diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2011-02-22 21:44:15 +0000 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2011-02-22 21:44:15 +0000 |
commit | 652463ecc0085c9e04da17631aa1fdb2703eee80 (patch) | |
tree | a05cac6777f599f0e8cabc2306e4f3af69428254 /apps/plugins/mpegplayer/libmpeg2 | |
parent | ec6e64ce9011281e6ecbbc0d93b91ce4db2f42dc (diff) | |
download | rockbox-652463ecc0085c9e04da17631aa1fdb2703eee80.tar.gz rockbox-652463ecc0085c9e04da17631aa1fdb2703eee80.zip |
mpegplayer: Move libmpeg2 files into their own subdirectory so things are less cluttered.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29381 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/mpegplayer/libmpeg2')
22 files changed, 8615 insertions, 0 deletions
diff --git a/apps/plugins/mpegplayer/libmpeg2/AUTHORS b/apps/plugins/mpegplayer/libmpeg2/AUTHORS new file mode 100644 index 0000000000..4722897c97 --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/AUTHORS | |||
@@ -0,0 +1,33 @@ | |||
1 | Aaron Holtzman <aholtzma@ess.engr.uvic.ca> started the project and | ||
2 | made the initial working implementation. | ||
3 | |||
4 | Michel Lespinasse <walken@zoy.org> did major changes for speed and | ||
5 | mpeg conformance and is the current maintainer. Most of the current | ||
6 | code was (re)written by him. | ||
7 | |||
8 | Other contributors include: | ||
9 | Bruno Barreyra <barreyra@ufl.edu> - build fixes | ||
10 | Gildas Bazin <gbazin@netcourrier.com> - mingw32 port | ||
11 | Alexander W. Chin <alexc@newt.phys.unsw.edu.au> - progressive_seq fix | ||
12 | Stephen Crowley <stephenc@dns2.digitalpassage.com> - build fixes | ||
13 | Didier Gautheron <dgautheron@magic.fr> - bug fixes | ||
14 | Ryan C. Gordon <icculus@lokigames.com> - SDL support | ||
15 | Peter Gubanov <peter@elecard.net.ru> - MMX IDCT scheduling | ||
16 | HÃ¥kan Hjort <d95hjort@dtek.chalmers.se> - Solaris fixes, mlib code | ||
17 | Nicolas Joly <njoly@pasteur.fr> - assorted bug fixes | ||
18 | Gerd Knorr <kraxel@goldbach.in-berlin.de> - Xv support | ||
19 | David I. Lehn <dlehn@vt.edu> - motion_comp mmx code | ||
20 | Olie Lho <ollie@sis.com.tw> - MMX yuv2rgb routine | ||
21 | David S. Miller <davem@redhat.com> - sparc VIS optimizations | ||
22 | Rick Niles <niles@scyld.com> - build fixes | ||
23 | Real Ouellet <realo@sympatico.ca> - g200 fixes | ||
24 | Bajusz Peter <hyp-x@inf.bme.hu> - motion comp fixes | ||
25 | Franck Sicard <Franck.Sicard@miniruth.solsoft.fr> - x11 fixes | ||
26 | Brion Vibber <brion@gizmo.usc.edu> - x11 fixes | ||
27 | Martin Vogt <mvogt@rhrk.uni-kl.de> - reentrancy fixes | ||
28 | Fredrik Vraalsen <vraalsen@cs.uiuc.edu> - general hackage and stuff | ||
29 | |||
30 | (let me know if I forgot anyone) | ||
31 | |||
32 | Thanks to David Schleef for creating me an account on his ppc g4 | ||
33 | machine and making it possible for me to work on the altivec code. | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/README b/apps/plugins/mpegplayer/libmpeg2/README new file mode 100644 index 0000000000..2a58846772 --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/README | |||
@@ -0,0 +1,204 @@ | |||
1 | |||
2 | |||
3 | ABOUT LIBMPEG2 | ||
4 | |||
5 | libmpeg2 is a free library for decoding mpeg-2 and mpeg-1 video | ||
6 | streams. It is released under the terms of the GPL license. | ||
7 | |||
8 | The main goals in libmpeg2 development are: | ||
9 | |||
10 | * Conformance - libmpeg2 is able to decode all mpeg streams that | ||
11 | conform to certain restrictions: "constrained parameters" for | ||
12 | mpeg-1, and "main profile" for mpeg-2. In practice, this is | ||
13 | what most people are using. For streams that follow these | ||
14 | restrictions, we believe libmpeg2 is 100% conformant to the | ||
15 | mpeg standards - and we have a pretty extensive test suite to | ||
16 | check this. | ||
17 | |||
18 | * Speed - there has been huge efforts there, and we believe | ||
19 | libmpeg2 is the fastest library around for what it | ||
20 | does. Please tell us if you find a faster one ! With typical | ||
21 | video streams as found on DVD's, and doing only decoding with | ||
22 | no display, you should be able to get about 110 fps on a | ||
23 | PIII/666, or 150 fps on an Athlon/950. This is less than 20 | ||
24 | cycles per output pixel. In a real player program, the display | ||
25 | routines will probably take as much time as the actual | ||
26 | decoding ! | ||
27 | |||
28 | * Portability - most of the code is written in C, and when we | ||
29 | use platform-specific optimizations (typically assembly | ||
30 | routines, currently used for the motion compensation and the | ||
31 | inverse cosine transform stages) we always have a generic C | ||
32 | routine to fall back on. This should be portable to all | ||
33 | architectures - at least we have heard reports from people | ||
34 | running this code on x86, ppc, sparc, arm and | ||
35 | sh4. Assembly-optimized implementations are available on x86 | ||
36 | (MMX) and ppc (altivec) architectures. Ultrasparc (VIS) is | ||
37 | probably the next on the list - we'll see. | ||
38 | |||
39 | * Reuseability - we do not want libmpeg2 to include any | ||
40 | project-specific code, but it should still include enough | ||
41 | features to be used by very diverse projects. We are only | ||
42 | starting to get there - the best way to help here is to give | ||
43 | us some feedback ! | ||
44 | |||
45 | The project homepage is at http://libmpeg2.sourceforge.net/ | ||
46 | |||
47 | |||
48 | MPEG2DEC | ||
49 | |||
50 | mpeg2dec is a test program for libmpeg2. It decodes mpeg-1 and mpeg-2 | ||
51 | video streams, and also includes a demultiplexer for mpeg-1 and mpeg-2 | ||
52 | program streams. It is purposely kept simple : it does not include | ||
53 | features like reading files from a DVD, CSS, fullscreen output, | ||
54 | navigation, etc... The main purpose of mpeg2dec is to have a simple | ||
55 | test bed for libmpeg2. | ||
56 | |||
57 | The libmpeg2 source code is always distributed in the mpeg2dec | ||
58 | package, to make it easier for people to test it. | ||
59 | |||
60 | The basic usage is to just type "mpeg2dec file" where file is a | ||
61 | demultiplexed mpeg video file. | ||
62 | |||
63 | The "-s" option must be used for multiplexed (audio and video) mpeg | ||
64 | files using the "program stream" format. These files are usualy found | ||
65 | on the internet or on unencrypted DVDs. | ||
66 | |||
67 | The "-t" option must be used for multiplexed (audio and video) mpeg | ||
68 | files using the "transport stream" format. These files are usualy | ||
69 | found in digital TV applications. | ||
70 | |||
71 | The "-o" option is used to select a given output module - for example | ||
72 | to redirect the output to a file. This is also used for performance | ||
73 | testing and conformance testing. | ||
74 | |||
75 | The "-c" option is used to disable all optimizations. | ||
76 | |||
77 | |||
78 | OTHER PROJECTS USING LIBMPEG2 | ||
79 | |||
80 | libmpeg2 is being used by various other projects, including: | ||
81 | |||
82 | * xine (http://xine.sourceforge.net/) - started as a simple | ||
83 | mpeg-2 audio and video decoder, but it since became a | ||
84 | full-featured DVD and video media player. | ||
85 | |||
86 | * VideoLAN (http://www.videolan.org/) - video streaming over an | ||
87 | ethernet network, can also be used as a standalone player. | ||
88 | |||
89 | * MPlayer (http://www.MPlayerHQ.hu) - another good player, it is | ||
90 | also very robust against damaged streams. | ||
91 | |||
92 | * movietime (http://movietime.sourceforge.net/) - still quite | ||
93 | young, but it looks very promising ! | ||
94 | |||
95 | * mpeg2decX (http://homepage1.nifty.com/~toku/software_en.html) - | ||
96 | a graphical interface for mpeg2dec for macintosh osX. | ||
97 | |||
98 | * TCVP (http://tcvp.sf.net) - video and music player for unix. | ||
99 | |||
100 | * drip (http://drip.sourceforge.net/) - a DVD to DIVX transcoder. | ||
101 | |||
102 | * PoMP | ||
103 | (http://www.dmclab.hanyang.ac.kr/research/project/PoDS/PoDS_sw.htm) - | ||
104 | a research player optimized to minimize disk power consumption. | ||
105 | |||
106 | * OMS (http://www.linuxvideo.org/oms/) | ||
107 | |||
108 | * XMPS (http://xmps.sourceforge.net/) | ||
109 | |||
110 | * GStreamer (http://www.gstreamer.net/) - a framework for | ||
111 | streaming media; it has an mpeg2 decoding plugin based on | ||
112 | libmpeg2. | ||
113 | |||
114 | * mpeglib (http://mpeglib.sourceforge.net/) - a video decoding | ||
115 | library that usess libmpeg2 when decoding mpeg streams. | ||
116 | |||
117 | * daphne (http://daphne.rulecity.com/) - a laserdisc arcade game | ||
118 | simulator. | ||
119 | |||
120 | * GOPchop (http://outflux.net/unix/software/GOPchop/) - a | ||
121 | GOP-accurate editor for MPEG2 streams. | ||
122 | |||
123 | If you use libmpeg2 in another project, let us know ! | ||
124 | |||
125 | |||
126 | TASKS | ||
127 | |||
128 | There are several places where we could easily use some help: | ||
129 | |||
130 | * Documentation: libmpeg2 still has no documentation. Every | ||
131 | project using it has had to figure things out by looking at | ||
132 | the header files, at the mpeg2dec sample application, and by | ||
133 | asking questions. Writing down a nice documentation would make | ||
134 | the code more easily reuseable. | ||
135 | |||
136 | * Testing: If you find any stream that does not decode right | ||
137 | with libmpeg2, let us know ! The best thing would be to mail | ||
138 | to the libmpeg2-devel mailing list. Also, it would be nice to | ||
139 | build a stress test so we can make sure libmpeg2 never crashes | ||
140 | on bad streams. | ||
141 | |||
142 | * Coding: There is a small TODO list in the mpeg2dec package, | ||
143 | you can have a look there ! Most items are pretty terse | ||
144 | though. | ||
145 | |||
146 | * Porting: If you're porting to a new architecture, you might | ||
147 | want to experiment with the compile flags defined in | ||
148 | configure.in . When you figure out whats fastest on your | ||
149 | platform, send us a patch ! | ||
150 | |||
151 | * Assembly optimizations: We only have x86 and altivec | ||
152 | optimizations yet, it would be worthwhile writing routines for | ||
153 | other architectures, especially those that have SIMD | ||
154 | instruction set extensions ! Also the yuv2rgb x86 routines | ||
155 | could probably be optimized a lot. | ||
156 | |||
157 | |||
158 | CVS SNAPSHOTS | ||
159 | |||
160 | A daily snapshot is created using "make distcheck" every night and | ||
161 | uploaded to http://libmpeg2.sourceforge.net/files/mpeg2dec-snapshot.tar.gz . | ||
162 | It is easier to use than the CVS repository, because you do not need | ||
163 | to have the right versions of automake, autoconf and libtool | ||
164 | installed. It might be convenient when working on a libmpeg2 port for | ||
165 | example. | ||
166 | |||
167 | |||
168 | CVS REPOSITORY | ||
169 | |||
170 | The latest libmpeg2 and mpeg2dec source code can always be found by | ||
171 | anonymous CVS: | ||
172 | |||
173 | # export CVSROOT=:pserver:anonymous@cvs.libmpeg2.sourceforge.net:/cvsroot/libmpeg2 | ||
174 | # cvs login (Just press Return when prompted for a password) | ||
175 | # cvs checkout mpeg2dec | ||
176 | |||
177 | You can also browse the latest changes online at | ||
178 | http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/libmpeg2/mpeg2dec/ | ||
179 | |||
180 | The other CVS modules are mpeg2dec-streams for the test suite, and | ||
181 | mpeg2dec-livid for the CVS history of the project while it was still | ||
182 | hosted on the linuxvideo.org servers. | ||
183 | |||
184 | |||
185 | MAILING LISTS | ||
186 | |||
187 | See the subscription information at http://libmpeg2.sourceforge.net/lists.html | ||
188 | |||
189 | libmpeg2-devel | ||
190 | |||
191 | This is the main mailing list for technical discussion about | ||
192 | libmpeg2. Anyone wanting to work on libmpeg2, or maybe just stay | ||
193 | informed about the development process, should probably subscribe to | ||
194 | this list. | ||
195 | |||
196 | libmpeg2-checkins | ||
197 | |||
198 | All libmpeg2 checkins are announced there. This is a good way to keep | ||
199 | track of what goes into CVS. | ||
200 | |||
201 | libmpeg2-announce | ||
202 | |||
203 | This is a very low traffic mailing list, only for announcements of new | ||
204 | versions of libmpeg2. Only project administrators can post there. | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/README.rockbox b/apps/plugins/mpegplayer/libmpeg2/README.rockbox new file mode 100644 index 0000000000..95f5a3d4b5 --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/README.rockbox | |||
@@ -0,0 +1,44 @@ | |||
1 | Library: libmpeg2 from mpeg2dec-0.4.0b (Released 2004-01-21) | ||
2 | Imported: 2006-08-06 by Dave Chapman | ||
3 | |||
4 | |||
5 | This directory contains a local version of libmpeg2 imported into | ||
6 | Rockbox for MPEG video decoding. | ||
7 | |||
8 | |||
9 | LICENSING INFORMATION | ||
10 | |||
11 | mpeg2dec and libmpeg2 are licensed under Version 2 of the GNU General | ||
12 | Public License. | ||
13 | |||
14 | |||
15 | IMPORT DETAILS | ||
16 | |||
17 | The following files were imported from the mpeg2dec-0.4.0b | ||
18 | distribution. Minor changes were made to enable compilation in | ||
19 | Rockbox and TABs were replaced by spaces to comply with the Rockbox | ||
20 | coding guidelines. | ||
21 | |||
22 | AUTHORS | ||
23 | README | ||
24 | SOURCES | ||
25 | attributes.h | ||
26 | cpu_accel.c | ||
27 | cpu_state.c | ||
28 | decode.c | ||
29 | header.c | ||
30 | idct.c | ||
31 | motion_comp.c | ||
32 | mpeg2.h | ||
33 | mpeg2_internal.h | ||
34 | slice.c | ||
35 | video_out.h | ||
36 | vlc.h | ||
37 | |||
38 | The following files are new, but based on code in mpeg2dec. | ||
39 | |||
40 | Makefile | ||
41 | mpegplayer.c | ||
42 | video_out_rockbox.c | ||
43 | mpeg2dec_config.h | ||
44 | alloc.c | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/attributes.h b/apps/plugins/mpegplayer/libmpeg2/attributes.h new file mode 100644 index 0000000000..24b069223b --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/attributes.h | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | * attributes.h | ||
3 | * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> | ||
4 | * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | ||
5 | * | ||
6 | * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. | ||
7 | * See http://libmpeg2.sourceforge.net/ for updates. | ||
8 | * | ||
9 | * mpeg2dec is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * mpeg2dec is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | ||
23 | * $Id$ | ||
24 | * libmpeg2 sync history: | ||
25 | * 2008-07-01 - CVS revision 1.5 | ||
26 | */ | ||
27 | |||
28 | /* use gcc attribs to align critical data structures */ | ||
29 | #ifdef ATTRIBUTE_ALIGNED_MAX | ||
30 | #define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align))) | ||
31 | #else | ||
32 | #define ATTR_ALIGN(align) | ||
33 | #endif | ||
34 | |||
35 | #if defined(LIKELY) && defined (UNLIKELY) | ||
36 | #define likely(x) LIKELY(x) | ||
37 | #define unlikely(x) UNLIKELY(x) | ||
38 | #else | ||
39 | #define likely(x) (x) | ||
40 | #define unlikely(x) (x) | ||
41 | #endif | ||
42 | |||
diff --git a/apps/plugins/mpegplayer/libmpeg2/decode.c b/apps/plugins/mpegplayer/libmpeg2/decode.c new file mode 100644 index 0000000000..9c8081efbe --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/decode.c | |||
@@ -0,0 +1,527 @@ | |||
1 | /* | ||
2 | * decode.c | ||
3 | * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> | ||
4 | * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | ||
5 | * | ||
6 | * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. | ||
7 | * See http://libmpeg2.sourceforge.net/ for updates. | ||
8 | * | ||
9 | * mpeg2dec is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * mpeg2dec is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | ||
23 | * $Id$ | ||
24 | * libmpeg2 sync history: | ||
25 | * 2008-07-01 - CVS revision 1.114 | ||
26 | */ | ||
27 | |||
28 | #include "plugin.h" | ||
29 | |||
30 | #include "mpeg2dec_config.h" | ||
31 | |||
32 | #include "mpeg2.h" | ||
33 | #include "attributes.h" | ||
34 | #include "mpeg2_internal.h" | ||
35 | |||
36 | #define BUFFER_SIZE (1194 * 1024) | ||
37 | |||
38 | #if defined(CPU_COLDFIRE) || (defined(CPU_ARM) && ARM_ARCH >= 6) | ||
39 | /* twice as large as on other targets because coldfire uses | ||
40 | * a secondary, transposed buffer for optimisation */ | ||
41 | static int16_t static_dct_block[128] IBSS_ATTR ATTR_ALIGN(16); | ||
42 | #define DCT_BLOCKSIZE (128 * sizeof (int16_t)) | ||
43 | #else | ||
44 | static int16_t static_dct_block[64] IBSS_ATTR ATTR_ALIGN(16); | ||
45 | #define DCT_BLOCKSIZE (64 * sizeof (int16_t)) | ||
46 | #endif | ||
47 | |||
48 | const mpeg2_info_t * mpeg2_info (mpeg2dec_t * mpeg2dec) | ||
49 | { | ||
50 | return &mpeg2dec->info; | ||
51 | } | ||
52 | |||
53 | static inline int skip_chunk (mpeg2dec_t * mpeg2dec, int bytes) | ||
54 | { | ||
55 | uint8_t * current; | ||
56 | uint32_t shift; | ||
57 | uint8_t * limit; | ||
58 | uint8_t byte; | ||
59 | |||
60 | if (!bytes) | ||
61 | return 0; | ||
62 | |||
63 | current = mpeg2dec->buf_start; | ||
64 | shift = mpeg2dec->shift; | ||
65 | limit = current + bytes; | ||
66 | |||
67 | do | ||
68 | { | ||
69 | byte = *current++; | ||
70 | |||
71 | if (shift == 0x00000100) | ||
72 | { | ||
73 | int skipped; | ||
74 | |||
75 | mpeg2dec->shift = 0xffffff00; | ||
76 | skipped = current - mpeg2dec->buf_start; | ||
77 | mpeg2dec->buf_start = current; | ||
78 | |||
79 | return skipped; | ||
80 | } | ||
81 | |||
82 | shift = (shift | byte) << 8; | ||
83 | } | ||
84 | while (current < limit); | ||
85 | |||
86 | mpeg2dec->shift = shift; | ||
87 | mpeg2dec->buf_start = current; | ||
88 | |||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | static inline int copy_chunk (mpeg2dec_t * mpeg2dec, int bytes) | ||
93 | { | ||
94 | uint8_t * current; | ||
95 | uint32_t shift; | ||
96 | uint8_t * chunk_ptr; | ||
97 | uint8_t * limit; | ||
98 | uint8_t byte; | ||
99 | |||
100 | if (!bytes) | ||
101 | return 0; | ||
102 | |||
103 | current = mpeg2dec->buf_start; | ||
104 | shift = mpeg2dec->shift; | ||
105 | chunk_ptr = mpeg2dec->chunk_ptr; | ||
106 | limit = current + bytes; | ||
107 | |||
108 | do | ||
109 | { | ||
110 | byte = *current++; | ||
111 | |||
112 | if (shift == 0x00000100) | ||
113 | { | ||
114 | int copied; | ||
115 | |||
116 | mpeg2dec->shift = 0xffffff00; | ||
117 | mpeg2dec->chunk_ptr = chunk_ptr + 1; | ||
118 | copied = current - mpeg2dec->buf_start; | ||
119 | mpeg2dec->buf_start = current; | ||
120 | return copied; | ||
121 | } | ||
122 | |||
123 | shift = (shift | byte) << 8; | ||
124 | *chunk_ptr++ = byte; | ||
125 | } | ||
126 | while (current < limit); | ||
127 | |||
128 | mpeg2dec->shift = shift; | ||
129 | mpeg2dec->buf_start = current; | ||
130 | return 0; | ||
131 | } | ||
132 | |||
133 | void mpeg2_buffer (mpeg2dec_t * mpeg2dec, uint8_t * start, uint8_t * end) | ||
134 | { | ||
135 | mpeg2dec->buf_start = start; | ||
136 | mpeg2dec->buf_end = end; | ||
137 | } | ||
138 | |||
139 | int mpeg2_getpos (mpeg2dec_t * mpeg2dec) | ||
140 | { | ||
141 | return mpeg2dec->buf_end - mpeg2dec->buf_start; | ||
142 | } | ||
143 | |||
144 | static inline mpeg2_state_t seek_chunk (mpeg2dec_t * mpeg2dec) | ||
145 | { | ||
146 | int size, skipped; | ||
147 | |||
148 | size = mpeg2dec->buf_end - mpeg2dec->buf_start; | ||
149 | skipped = skip_chunk (mpeg2dec, size); | ||
150 | |||
151 | if (!skipped) | ||
152 | { | ||
153 | mpeg2dec->bytes_since_tag += size; | ||
154 | return STATE_BUFFER; | ||
155 | } | ||
156 | |||
157 | mpeg2dec->bytes_since_tag += skipped; | ||
158 | mpeg2dec->code = mpeg2dec->buf_start[-1]; | ||
159 | |||
160 | return STATE_INTERNAL_NORETURN; | ||
161 | } | ||
162 | |||
163 | mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec) | ||
164 | { | ||
165 | while (!(mpeg2dec->code == 0xb3 || | ||
166 | ((mpeg2dec->code == 0xb7 || mpeg2dec->code == 0xb8 || | ||
167 | !mpeg2dec->code) && mpeg2dec->sequence.width != (unsigned)-1))) | ||
168 | { | ||
169 | if (seek_chunk (mpeg2dec) == STATE_BUFFER) | ||
170 | return STATE_BUFFER; | ||
171 | } | ||
172 | |||
173 | mpeg2dec->chunk_start = | ||
174 | mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer; | ||
175 | |||
176 | mpeg2dec->user_data_len = 0; | ||
177 | |||
178 | return ((mpeg2dec->code == 0xb7) ? | ||
179 | mpeg2_header_end(mpeg2dec) : mpeg2_parse_header(mpeg2dec)); | ||
180 | } | ||
181 | |||
182 | #define RECEIVED(code,state) (((state) << 8) + (code)) | ||
183 | |||
184 | mpeg2_state_t mpeg2_parse (mpeg2dec_t * mpeg2dec) | ||
185 | { | ||
186 | int size_buffer, size_chunk, copied; | ||
187 | |||
188 | if (mpeg2dec->action) | ||
189 | { | ||
190 | mpeg2_state_t state; | ||
191 | |||
192 | state = mpeg2dec->action (mpeg2dec); | ||
193 | |||
194 | if (state > STATE_INTERNAL_NORETURN) | ||
195 | return state; | ||
196 | } | ||
197 | |||
198 | while (1) | ||
199 | { | ||
200 | while ((unsigned) (mpeg2dec->code - mpeg2dec->first_decode_slice) < | ||
201 | mpeg2dec->nb_decode_slices) | ||
202 | { | ||
203 | size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start; | ||
204 | size_chunk = mpeg2dec->chunk_buffer + BUFFER_SIZE - | ||
205 | mpeg2dec->chunk_ptr; | ||
206 | |||
207 | if (size_buffer <= size_chunk) | ||
208 | { | ||
209 | copied = copy_chunk (mpeg2dec, size_buffer); | ||
210 | |||
211 | if (!copied) | ||
212 | { | ||
213 | mpeg2dec->bytes_since_tag += size_buffer; | ||
214 | mpeg2dec->chunk_ptr += size_buffer; | ||
215 | return STATE_BUFFER; | ||
216 | } | ||
217 | } | ||
218 | else | ||
219 | { | ||
220 | copied = copy_chunk (mpeg2dec, size_chunk); | ||
221 | |||
222 | if (!copied) | ||
223 | { | ||
224 | /* filled the chunk buffer without finding a start code */ | ||
225 | mpeg2dec->bytes_since_tag += size_chunk; | ||
226 | mpeg2dec->action = seek_chunk; | ||
227 | return STATE_INVALID; | ||
228 | } | ||
229 | } | ||
230 | |||
231 | mpeg2dec->bytes_since_tag += copied; | ||
232 | |||
233 | mpeg2_slice (&mpeg2dec->decoder, mpeg2dec->code, | ||
234 | mpeg2dec->chunk_start); | ||
235 | mpeg2dec->code = mpeg2dec->buf_start[-1]; | ||
236 | mpeg2dec->chunk_ptr = mpeg2dec->chunk_start; | ||
237 | } | ||
238 | |||
239 | if ((unsigned) (mpeg2dec->code - 1) >= 0xb0 - 1) | ||
240 | break; | ||
241 | |||
242 | if (seek_chunk (mpeg2dec) == STATE_BUFFER) | ||
243 | return STATE_BUFFER; | ||
244 | } | ||
245 | |||
246 | mpeg2dec->action = mpeg2_seek_header; | ||
247 | |||
248 | switch (mpeg2dec->code) | ||
249 | { | ||
250 | case 0x00: | ||
251 | return mpeg2dec->state; | ||
252 | case 0xb3: | ||
253 | case 0xb7: | ||
254 | case 0xb8: | ||
255 | return (mpeg2dec->state == STATE_SLICE) ? STATE_SLICE : STATE_INVALID; | ||
256 | default: | ||
257 | mpeg2dec->action = seek_chunk; | ||
258 | return STATE_INVALID; | ||
259 | } | ||
260 | } | ||
261 | |||
262 | mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec) | ||
263 | { | ||
264 | static int (* const process_header[9]) (mpeg2dec_t *) = | ||
265 | { | ||
266 | mpeg2_header_picture, | ||
267 | mpeg2_header_extension, | ||
268 | mpeg2_header_user_data, | ||
269 | mpeg2_header_sequence, | ||
270 | NULL, | ||
271 | NULL, | ||
272 | NULL, | ||
273 | NULL, | ||
274 | mpeg2_header_gop | ||
275 | }; | ||
276 | |||
277 | int size_buffer, size_chunk, copied; | ||
278 | |||
279 | mpeg2dec->action = mpeg2_parse_header; | ||
280 | mpeg2dec->info.user_data = NULL; | ||
281 | mpeg2dec->info.user_data_len = 0; | ||
282 | |||
283 | while (1) | ||
284 | { | ||
285 | size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start; | ||
286 | size_chunk = mpeg2dec->chunk_buffer + BUFFER_SIZE - | ||
287 | mpeg2dec->chunk_ptr; | ||
288 | |||
289 | if (size_buffer <= size_chunk) | ||
290 | { | ||
291 | copied = copy_chunk (mpeg2dec, size_buffer); | ||
292 | |||
293 | if (!copied) | ||
294 | { | ||
295 | mpeg2dec->bytes_since_tag += size_buffer; | ||
296 | mpeg2dec->chunk_ptr += size_buffer; | ||
297 | return STATE_BUFFER; | ||
298 | } | ||
299 | } | ||
300 | else | ||
301 | { | ||
302 | copied = copy_chunk (mpeg2dec, size_chunk); | ||
303 | |||
304 | if (!copied) | ||
305 | { | ||
306 | /* filled the chunk buffer without finding a start code */ | ||
307 | mpeg2dec->bytes_since_tag += size_chunk; | ||
308 | mpeg2dec->code = 0xb4; | ||
309 | mpeg2dec->action = mpeg2_seek_header; | ||
310 | return STATE_INVALID; | ||
311 | } | ||
312 | } | ||
313 | |||
314 | mpeg2dec->bytes_since_tag += copied; | ||
315 | |||
316 | if (process_header[mpeg2dec->code & 0x0b] (mpeg2dec)) | ||
317 | { | ||
318 | mpeg2dec->code = mpeg2dec->buf_start[-1]; | ||
319 | mpeg2dec->action = mpeg2_seek_header; | ||
320 | return STATE_INVALID; | ||
321 | } | ||
322 | |||
323 | mpeg2dec->code = mpeg2dec->buf_start[-1]; | ||
324 | |||
325 | switch (RECEIVED (mpeg2dec->code, mpeg2dec->state)) | ||
326 | { | ||
327 | /* state transition after a sequence header */ | ||
328 | case RECEIVED (0x00, STATE_SEQUENCE): | ||
329 | case RECEIVED (0xb8, STATE_SEQUENCE): | ||
330 | mpeg2_header_sequence_finalize (mpeg2dec); | ||
331 | break; | ||
332 | |||
333 | /* other legal state transitions */ | ||
334 | case RECEIVED (0x00, STATE_GOP): | ||
335 | mpeg2_header_gop_finalize (mpeg2dec); | ||
336 | break; | ||
337 | case RECEIVED (0x01, STATE_PICTURE): | ||
338 | case RECEIVED (0x01, STATE_PICTURE_2ND): | ||
339 | mpeg2_header_picture_finalize (mpeg2dec); | ||
340 | mpeg2dec->action = mpeg2_header_slice_start; | ||
341 | break; | ||
342 | |||
343 | /* legal headers within a given state */ | ||
344 | case RECEIVED (0xb2, STATE_SEQUENCE): | ||
345 | case RECEIVED (0xb2, STATE_GOP): | ||
346 | case RECEIVED (0xb2, STATE_PICTURE): | ||
347 | case RECEIVED (0xb2, STATE_PICTURE_2ND): | ||
348 | case RECEIVED (0xb5, STATE_SEQUENCE): | ||
349 | case RECEIVED (0xb5, STATE_PICTURE): | ||
350 | case RECEIVED (0xb5, STATE_PICTURE_2ND): | ||
351 | mpeg2dec->chunk_ptr = mpeg2dec->chunk_start; | ||
352 | continue; | ||
353 | |||
354 | default: | ||
355 | mpeg2dec->action = mpeg2_seek_header; | ||
356 | return STATE_INVALID; | ||
357 | } | ||
358 | |||
359 | mpeg2dec->chunk_start = mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer; | ||
360 | mpeg2dec->user_data_len = 0; | ||
361 | |||
362 | return mpeg2dec->state; | ||
363 | } | ||
364 | } | ||
365 | |||
366 | int mpeg2_convert (mpeg2dec_t * mpeg2dec, mpeg2_convert_t convert, void * arg) | ||
367 | { | ||
368 | mpeg2_convert_init_t convert_init; | ||
369 | int error; | ||
370 | |||
371 | error = convert (MPEG2_CONVERT_SET, NULL, &mpeg2dec->sequence, 0, | ||
372 | arg, &convert_init); | ||
373 | |||
374 | if (!error) | ||
375 | { | ||
376 | mpeg2dec->convert = convert; | ||
377 | mpeg2dec->convert_arg = arg; | ||
378 | mpeg2dec->convert_id_size = convert_init.id_size; | ||
379 | mpeg2dec->convert_stride = 0; | ||
380 | } | ||
381 | |||
382 | return error; | ||
383 | } | ||
384 | |||
385 | int mpeg2_stride (mpeg2dec_t * mpeg2dec, int stride) | ||
386 | { | ||
387 | if (!mpeg2dec->convert) | ||
388 | { | ||
389 | if (stride < (int) mpeg2dec->sequence.width) | ||
390 | stride = mpeg2dec->sequence.width; | ||
391 | |||
392 | mpeg2dec->decoder.stride_frame = stride; | ||
393 | } | ||
394 | else | ||
395 | { | ||
396 | mpeg2_convert_init_t convert_init; | ||
397 | |||
398 | stride = mpeg2dec->convert(MPEG2_CONVERT_STRIDE, NULL, | ||
399 | &mpeg2dec->sequence, stride, | ||
400 | mpeg2dec->convert_arg, | ||
401 | &convert_init); | ||
402 | |||
403 | mpeg2dec->convert_id_size = convert_init.id_size; | ||
404 | mpeg2dec->convert_stride = stride; | ||
405 | } | ||
406 | |||
407 | return stride; | ||
408 | } | ||
409 | |||
410 | void mpeg2_set_buf (mpeg2dec_t * mpeg2dec, uint8_t * buf[MPEG2_COMPONENTS], void * id) | ||
411 | { | ||
412 | mpeg2_fbuf_t * fbuf; | ||
413 | |||
414 | if (mpeg2dec->custom_fbuf) | ||
415 | { | ||
416 | if (mpeg2dec->state == STATE_SEQUENCE) | ||
417 | { | ||
418 | mpeg2dec->fbuf[2] = mpeg2dec->fbuf[1]; | ||
419 | mpeg2dec->fbuf[1] = mpeg2dec->fbuf[0]; | ||
420 | } | ||
421 | |||
422 | mpeg2_set_fbuf (mpeg2dec, (mpeg2dec->decoder.coding_type == | ||
423 | PIC_FLAG_CODING_TYPE_B)); | ||
424 | |||
425 | fbuf = mpeg2dec->fbuf[0]; | ||
426 | } | ||
427 | else | ||
428 | { | ||
429 | fbuf = &mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index].fbuf; | ||
430 | mpeg2dec->alloc_index_user = ++mpeg2dec->alloc_index; | ||
431 | } | ||
432 | |||
433 | fbuf->buf[0] = buf[0]; | ||
434 | #if MPEG2_COLOR | ||
435 | fbuf->buf[1] = buf[1]; | ||
436 | fbuf->buf[2] = buf[2]; | ||
437 | #endif | ||
438 | |||
439 | fbuf->id = id; | ||
440 | } | ||
441 | |||
442 | void mpeg2_custom_fbuf (mpeg2dec_t * mpeg2dec, int custom_fbuf) | ||
443 | { | ||
444 | mpeg2dec->custom_fbuf = custom_fbuf; | ||
445 | } | ||
446 | |||
447 | void mpeg2_skip (mpeg2dec_t * mpeg2dec, int skip) | ||
448 | { | ||
449 | mpeg2dec->first_decode_slice = 1; | ||
450 | mpeg2dec->nb_decode_slices = skip ? 0 : (0xb0 - 1); | ||
451 | } | ||
452 | |||
453 | void mpeg2_slice_region (mpeg2dec_t * mpeg2dec, int start, int end) | ||
454 | { | ||
455 | start = (start < 1) ? 1 : (start > 0xb0) ? 0xb0 : start; | ||
456 | end = (end < start) ? start : (end > 0xb0) ? 0xb0 : end; | ||
457 | mpeg2dec->first_decode_slice = start; | ||
458 | mpeg2dec->nb_decode_slices = end - start; | ||
459 | } | ||
460 | |||
461 | void mpeg2_tag_picture (mpeg2dec_t * mpeg2dec, uint32_t tag, uint32_t tag2) | ||
462 | { | ||
463 | mpeg2dec->tag_previous = mpeg2dec->tag_current; | ||
464 | mpeg2dec->tag2_previous = mpeg2dec->tag2_current; | ||
465 | mpeg2dec->tag_current = tag; | ||
466 | mpeg2dec->tag2_current = tag2; | ||
467 | mpeg2dec->num_tags++; | ||
468 | mpeg2dec->bytes_since_tag = 0; | ||
469 | } | ||
470 | |||
471 | void mpeg2_reset (mpeg2dec_t * mpeg2dec, int full_reset) | ||
472 | { | ||
473 | mpeg2dec->buf_start = mpeg2dec->buf_end = NULL; | ||
474 | mpeg2dec->num_tags = 0; | ||
475 | mpeg2dec->shift = 0xffffff00; | ||
476 | mpeg2dec->code = 0xb4; | ||
477 | mpeg2dec->action = mpeg2_seek_header; | ||
478 | mpeg2dec->state = STATE_INVALID; | ||
479 | mpeg2dec->first = 1; | ||
480 | |||
481 | mpeg2_reset_info(&mpeg2dec->info); | ||
482 | mpeg2dec->info.gop = NULL; | ||
483 | mpeg2dec->info.user_data = NULL; | ||
484 | mpeg2dec->info.user_data_len = 0; | ||
485 | |||
486 | if (full_reset) | ||
487 | { | ||
488 | mpeg2dec->info.sequence = NULL; | ||
489 | mpeg2_header_state_init (mpeg2dec); | ||
490 | } | ||
491 | } | ||
492 | |||
493 | mpeg2dec_t * mpeg2_init (void) | ||
494 | { | ||
495 | mpeg2dec_t * mpeg2dec; | ||
496 | |||
497 | mpeg2_idct_init (); | ||
498 | |||
499 | mpeg2dec = (mpeg2dec_t *)mpeg2_bufalloc(sizeof (mpeg2dec_t), | ||
500 | MPEG2_ALLOC_MPEG2DEC); | ||
501 | if (mpeg2dec == NULL) | ||
502 | return NULL; | ||
503 | |||
504 | mpeg2dec->decoder.DCTblock = static_dct_block; | ||
505 | |||
506 | rb->memset (mpeg2dec->decoder.DCTblock, 0, DCT_BLOCKSIZE); | ||
507 | |||
508 | DEBUGF("DCTblock: %p\n", mpeg2dec->decoder.DCTblock); | ||
509 | |||
510 | mpeg2dec->chunk_buffer = (uint8_t *)mpeg2_bufalloc(BUFFER_SIZE + 4, | ||
511 | MPEG2_ALLOC_CHUNK); | ||
512 | |||
513 | mpeg2dec->sequence.width = (unsigned)-1; | ||
514 | mpeg2_reset (mpeg2dec, 1); | ||
515 | |||
516 | return mpeg2dec; | ||
517 | } | ||
518 | |||
519 | void mpeg2_close (mpeg2dec_t * mpeg2dec) | ||
520 | { | ||
521 | mpeg2_header_state_init (mpeg2dec); | ||
522 | #if 0 | ||
523 | /* These are dedicated buffers in rockbox */ | ||
524 | mpeg2_free (mpeg2dec->chunk_buffer); | ||
525 | mpeg2_free (mpeg2dec); | ||
526 | #endif | ||
527 | } | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/header.c b/apps/plugins/mpegplayer/libmpeg2/header.c new file mode 100644 index 0000000000..001cafe7d5 --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/header.c | |||
@@ -0,0 +1,1286 @@ | |||
1 | /* | ||
2 | * header.c | ||
3 | * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> | ||
4 | * Copyright (C) 2003 Regis Duchesne <hpreg@zoy.org> | ||
5 | * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | ||
6 | * | ||
7 | * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. | ||
8 | * See http://libmpeg2.sourceforge.net/ for updates. | ||
9 | * | ||
10 | * mpeg2dec is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * mpeg2dec is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | * | ||
24 | * $Id$ | ||
25 | * libmpeg2 sync history: | ||
26 | * 2008-07-01 - CVS revision 1.101 | ||
27 | */ | ||
28 | |||
29 | #include "plugin.h" | ||
30 | |||
31 | #include "mpeg2dec_config.h" | ||
32 | |||
33 | #include "mpeg2.h" | ||
34 | #include "attributes.h" | ||
35 | #include "mpeg2_internal.h" | ||
36 | |||
37 | #define SEQ_EXT 2 | ||
38 | #define SEQ_DISPLAY_EXT 4 | ||
39 | #define QUANT_MATRIX_EXT 8 | ||
40 | #define COPYRIGHT_EXT 0x10 | ||
41 | #define PIC_DISPLAY_EXT 0x80 | ||
42 | #define PIC_CODING_EXT 0x100 | ||
43 | |||
44 | /* default intra quant matrix, in zig-zag order */ | ||
45 | static const uint8_t default_intra_quantizer_matrix[64] = | ||
46 | { | ||
47 | 8, | ||
48 | 16, 16, | ||
49 | 19, 16, 19, | ||
50 | 22, 22, 22, 22, | ||
51 | 22, 22, 26, 24, 26, | ||
52 | 27, 27, 27, 26, 26, 26, | ||
53 | 26, 27, 27, 27, 29, 29, 29, | ||
54 | 34, 34, 34, 29, 29, 29, 27, 27, | ||
55 | 29, 29, 32, 32, 34, 34, 37, | ||
56 | 38, 37, 35, 35, 34, 35, | ||
57 | 38, 38, 40, 40, 40, | ||
58 | 48, 48, 46, 46, | ||
59 | 56, 56, 58, | ||
60 | 69, 69, | ||
61 | 83 | ||
62 | }; | ||
63 | |||
64 | const uint8_t default_mpeg2_scan_norm[64] = | ||
65 | { | ||
66 | /* Zig-Zag scan pattern */ | ||
67 | 0, 1, 8, 16, 9, 2, 3, 10, | ||
68 | 17, 24, 32, 25, 18, 11, 4, 5, | ||
69 | 12, 19, 26, 33, 40, 48, 41, 34, | ||
70 | 27, 20, 13, 6, 7, 14, 21, 28, | ||
71 | 35, 42, 49, 56, 57, 50, 43, 36, | ||
72 | 29, 22, 15, 23, 30, 37, 44, 51, | ||
73 | 58, 59, 52, 45, 38, 31, 39, 46, | ||
74 | 53, 60, 61, 54, 47, 55, 62, 63 | ||
75 | }; | ||
76 | |||
77 | const uint8_t default_mpeg2_scan_alt[64] = | ||
78 | { | ||
79 | /* Alternate scan pattern */ | ||
80 | 0, 8, 16, 24, 1, 9, 2, 10, | ||
81 | 17, 25, 32, 40, 48, 56, 57, 49, | ||
82 | 41, 33, 26, 18, 3, 11, 4, 12, | ||
83 | 19, 27, 34, 42, 50, 58, 35, 43, | ||
84 | 51, 59, 20, 28, 5, 13, 6, 14, | ||
85 | 21, 29, 36, 44, 52, 60, 37, 45, | ||
86 | 53, 61, 22, 30, 7, 15, 23, 31, | ||
87 | 38, 46, 54, 62, 39, 47, 55, 63 | ||
88 | }; | ||
89 | |||
90 | uint8_t mpeg2_scan_norm[64] IDATA_ATTR; | ||
91 | uint8_t mpeg2_scan_alt[64] IDATA_ATTR; | ||
92 | |||
93 | void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec) | ||
94 | { | ||
95 | if (mpeg2dec->sequence.width != (unsigned)-1) | ||
96 | { | ||
97 | mpeg2dec->sequence.width = (unsigned)-1; | ||
98 | mpeg2_mem_reset(); /* Clean the memory slate */ | ||
99 | #if 0 | ||
100 | if (!mpeg2dec->custom_fbuf) | ||
101 | { | ||
102 | int i; | ||
103 | for (i = mpeg2dec->alloc_index_user; | ||
104 | i < mpeg2dec->alloc_index; i++) | ||
105 | { | ||
106 | mpeg2_free(mpeg2dec->fbuf_alloc[i].fbuf.buf[0]); | ||
107 | #if MPEG2_COLOR | ||
108 | mpeg2_free(mpeg2dec->fbuf_alloc[i].fbuf.buf[1]); | ||
109 | mpeg2_free(mpeg2dec->fbuf_alloc[i].fbuf.buf[2]); | ||
110 | #endif | ||
111 | } | ||
112 | } | ||
113 | |||
114 | if (mpeg2dec->convert_start) | ||
115 | { | ||
116 | int i; | ||
117 | for (i = 0; i < 3; i++) | ||
118 | { | ||
119 | mpeg2_free(mpeg2dec->yuv_buf[i][0]); | ||
120 | #if MPEG2_COLOR | ||
121 | mpeg2_free(mpeg2dec->yuv_buf[i][1]); | ||
122 | mpeg2_free(mpeg2dec->yuv_buf[i][2]); | ||
123 | #endif | ||
124 | } | ||
125 | } | ||
126 | |||
127 | if (mpeg2dec->decoder.convert_id) | ||
128 | { | ||
129 | mpeg2_free(mpeg2dec->decoder.convert_id); | ||
130 | } | ||
131 | #endif | ||
132 | } | ||
133 | |||
134 | mpeg2dec->decoder.coding_type = I_TYPE; | ||
135 | mpeg2dec->decoder.convert = NULL; | ||
136 | mpeg2dec->decoder.convert_id = NULL; | ||
137 | |||
138 | mpeg2dec->picture = mpeg2dec->pictures; | ||
139 | |||
140 | mpeg2dec->fbuf[0] = &mpeg2dec->fbuf_alloc[0].fbuf; | ||
141 | mpeg2dec->fbuf[1] = &mpeg2dec->fbuf_alloc[1].fbuf; | ||
142 | mpeg2dec->fbuf[2] = &mpeg2dec->fbuf_alloc[2].fbuf; | ||
143 | |||
144 | mpeg2dec->first = 1; | ||
145 | mpeg2dec->alloc_index = 0; | ||
146 | mpeg2dec->alloc_index_user = 0; | ||
147 | mpeg2dec->first_decode_slice = 1; | ||
148 | mpeg2dec->nb_decode_slices = 0xb0 - 1; | ||
149 | mpeg2dec->convert = NULL; | ||
150 | mpeg2dec->convert_start = NULL; | ||
151 | mpeg2dec->custom_fbuf = 0; | ||
152 | mpeg2dec->yuv_index = 0; | ||
153 | } | ||
154 | |||
155 | void mpeg2_reset_info (mpeg2_info_t * info) | ||
156 | { | ||
157 | info->current_picture = | ||
158 | info->current_picture_2nd = NULL; | ||
159 | |||
160 | info->display_picture = | ||
161 | info->display_picture_2nd = NULL; | ||
162 | |||
163 | info->current_fbuf = | ||
164 | info->display_fbuf = | ||
165 | info->discard_fbuf = NULL; | ||
166 | } | ||
167 | |||
168 | static void info_user_data (mpeg2dec_t * mpeg2dec) | ||
169 | { | ||
170 | if (mpeg2dec->user_data_len) | ||
171 | { | ||
172 | mpeg2dec->info.user_data = mpeg2dec->chunk_buffer; | ||
173 | mpeg2dec->info.user_data_len = mpeg2dec->user_data_len - 3; | ||
174 | } | ||
175 | } | ||
176 | |||
177 | int mpeg2_header_sequence (mpeg2dec_t * mpeg2dec) | ||
178 | { | ||
179 | static const unsigned int frame_period[16] = | ||
180 | { | ||
181 | 0, 1126125, 1125000, 1080000, 900900, 900000, 540000, 450450, 450000, | ||
182 | /* unofficial: xing 15 fps */ | ||
183 | 1800000, | ||
184 | /* unofficial: libmpeg3 "Unofficial economy rates" 5/10/12/15 fps */ | ||
185 | 5400000, 2700000, 2250000, 1800000, 0, 0 | ||
186 | }; | ||
187 | |||
188 | uint8_t * buffer = mpeg2dec->chunk_start; | ||
189 | mpeg2_sequence_t * sequence = &mpeg2dec->new_sequence; | ||
190 | int i; | ||
191 | |||
192 | if ((buffer[6] & 0x20) != 0x20) /* missing marker_bit */ | ||
193 | return 1; | ||
194 | |||
195 | i = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2]; | ||
196 | |||
197 | if (!(sequence->display_width = sequence->picture_width = i >> 12)) | ||
198 | return 1; | ||
199 | |||
200 | if (!(sequence->display_height = sequence->picture_height = i & 0xfff)) | ||
201 | return 1; | ||
202 | |||
203 | sequence->width = (sequence->picture_width + 15) & ~15; | ||
204 | sequence->height = (sequence->picture_height + 15) & ~15; | ||
205 | sequence->chroma_width = sequence->width >> 1; | ||
206 | sequence->chroma_height = sequence->height >> 1; | ||
207 | |||
208 | sequence->flags = SEQ_FLAG_PROGRESSIVE_SEQUENCE | | ||
209 | SEQ_VIDEO_FORMAT_UNSPECIFIED; | ||
210 | |||
211 | sequence->pixel_width = buffer[3] >> 4; /* aspect ratio */ | ||
212 | sequence->frame_period = frame_period[buffer[3] & 15]; | ||
213 | |||
214 | sequence->byte_rate = (buffer[4]<<10) | (buffer[5]<<2) | (buffer[6]>>6); | ||
215 | |||
216 | sequence->vbv_buffer_size = ((buffer[6]<<16) | (buffer[7]<<8)) & 0x1ff800; | ||
217 | |||
218 | if (buffer[7] & 4) | ||
219 | sequence->flags |= SEQ_FLAG_CONSTRAINED_PARAMETERS; | ||
220 | |||
221 | mpeg2dec->copy_matrix = 3; | ||
222 | |||
223 | if (buffer[7] & 2) | ||
224 | { | ||
225 | for (i = 0; i < 64; i++) | ||
226 | { | ||
227 | mpeg2dec->new_quantizer_matrix[0][mpeg2_scan_norm[i]] = | ||
228 | (buffer[i+7] << 7) | (buffer[i+8] >> 1); | ||
229 | } | ||
230 | |||
231 | buffer += 64; | ||
232 | } | ||
233 | else | ||
234 | { | ||
235 | for (i = 0; i < 64; i++) | ||
236 | { | ||
237 | mpeg2dec->new_quantizer_matrix[0][mpeg2_scan_norm[i]] = | ||
238 | default_intra_quantizer_matrix[i]; | ||
239 | } | ||
240 | } | ||
241 | |||
242 | if (buffer[7] & 1) | ||
243 | { | ||
244 | for (i = 0; i < 64; i++) | ||
245 | { | ||
246 | mpeg2dec->new_quantizer_matrix[1][mpeg2_scan_norm[i]] = | ||
247 | buffer[i+8]; | ||
248 | } | ||
249 | } | ||
250 | else | ||
251 | { | ||
252 | rb->memset (mpeg2dec->new_quantizer_matrix[1], 16, 64); | ||
253 | } | ||
254 | |||
255 | sequence->profile_level_id = 0x80; | ||
256 | sequence->colour_primaries = 0; | ||
257 | sequence->transfer_characteristics = 0; | ||
258 | sequence->matrix_coefficients = 0; | ||
259 | |||
260 | mpeg2dec->ext_state = SEQ_EXT; | ||
261 | mpeg2dec->state = STATE_SEQUENCE; | ||
262 | |||
263 | mpeg2dec->display_offset_x = | ||
264 | mpeg2dec->display_offset_y = 0; | ||
265 | |||
266 | return 0; | ||
267 | } | ||
268 | |||
269 | static int sequence_ext (mpeg2dec_t * mpeg2dec) | ||
270 | { | ||
271 | uint8_t * buffer = mpeg2dec->chunk_start; | ||
272 | mpeg2_sequence_t * sequence = &mpeg2dec->new_sequence; | ||
273 | uint32_t flags; | ||
274 | |||
275 | if (!(buffer[3] & 1)) | ||
276 | return 1; | ||
277 | |||
278 | sequence->profile_level_id = (buffer[0] << 4) | (buffer[1] >> 4); | ||
279 | |||
280 | sequence->picture_width += ((buffer[1] << 13) | (buffer[2] << 5)) & 0x3000; | ||
281 | sequence->display_width = sequence->picture_width; | ||
282 | |||
283 | sequence->picture_height += (buffer[2] << 7) & 0x3000; | ||
284 | sequence->display_height = sequence->picture_height; | ||
285 | |||
286 | sequence->width = (sequence->picture_width + 15) & ~15; | ||
287 | sequence->height = (sequence->picture_height + 15) & ~15; | ||
288 | |||
289 | flags = sequence->flags | SEQ_FLAG_MPEG2; | ||
290 | |||
291 | if (!(buffer[1] & 8)) | ||
292 | { | ||
293 | flags &= ~SEQ_FLAG_PROGRESSIVE_SEQUENCE; | ||
294 | sequence->height = (sequence->height + 31) & ~31; | ||
295 | } | ||
296 | |||
297 | if (buffer[5] & 0x80) | ||
298 | flags |= SEQ_FLAG_LOW_DELAY; | ||
299 | |||
300 | sequence->flags = flags; | ||
301 | sequence->chroma_width = sequence->width; | ||
302 | sequence->chroma_height = sequence->height; | ||
303 | |||
304 | switch (buffer[1] & 6) | ||
305 | { | ||
306 | case 0: /* invalid */ | ||
307 | return 1; | ||
308 | case 2: /* 4:2:0 */ | ||
309 | sequence->chroma_height >>= 1; | ||
310 | case 4: /* 4:2:2 */ | ||
311 | sequence->chroma_width >>= 1; | ||
312 | } | ||
313 | |||
314 | sequence->byte_rate += ((buffer[2]<<25) | (buffer[3]<<17)) & 0x3ffc0000; | ||
315 | |||
316 | sequence->vbv_buffer_size |= buffer[4] << 21; | ||
317 | |||
318 | sequence->frame_period = | ||
319 | sequence->frame_period * ((buffer[5]&31)+1) / (((buffer[5]>>2)&3)+1); | ||
320 | |||
321 | mpeg2dec->ext_state = SEQ_DISPLAY_EXT; | ||
322 | |||
323 | return 0; | ||
324 | } | ||
325 | |||
326 | static int sequence_display_ext (mpeg2dec_t * mpeg2dec) | ||
327 | { | ||
328 | uint8_t * buffer = mpeg2dec->chunk_start; | ||
329 | mpeg2_sequence_t * sequence = &mpeg2dec->new_sequence; | ||
330 | int x; | ||
331 | |||
332 | sequence->flags = (sequence->flags & ~SEQ_MASK_VIDEO_FORMAT) | | ||
333 | ((buffer[0] << 4) & SEQ_MASK_VIDEO_FORMAT); | ||
334 | |||
335 | if (buffer[0] & 1) | ||
336 | { | ||
337 | sequence->flags |= SEQ_FLAG_COLOUR_DESCRIPTION; | ||
338 | sequence->colour_primaries = buffer[1]; | ||
339 | sequence->transfer_characteristics = buffer[2]; | ||
340 | sequence->matrix_coefficients = buffer[3]; | ||
341 | buffer += 3; | ||
342 | } | ||
343 | |||
344 | if (!(buffer[2] & 2)) /* missing marker_bit */ | ||
345 | return 1; | ||
346 | |||
347 | x = (buffer[1] << 6) | (buffer[2] >> 2); | ||
348 | if (x) | ||
349 | sequence->display_width = x; | ||
350 | |||
351 | x = ((buffer[2] & 1) << 13) | (buffer[3] << 5) | (buffer[4] >> 3); | ||
352 | if (x) | ||
353 | sequence->display_height = x; | ||
354 | |||
355 | return 0; | ||
356 | } | ||
357 | |||
358 | static inline void simplify (unsigned int * u, unsigned int * v) | ||
359 | { | ||
360 | unsigned int a, b, tmp; | ||
361 | |||
362 | a = *u; | ||
363 | b = *v; | ||
364 | |||
365 | /* find greatest common divisor */ | ||
366 | while (a) | ||
367 | { | ||
368 | tmp = a; | ||
369 | a = b % tmp; | ||
370 | b = tmp; | ||
371 | } | ||
372 | |||
373 | *u /= b; | ||
374 | *v /= b; | ||
375 | } | ||
376 | |||
377 | static inline void finalize_sequence (mpeg2_sequence_t * sequence) | ||
378 | { | ||
379 | int width; | ||
380 | int height; | ||
381 | |||
382 | sequence->byte_rate *= 50; | ||
383 | |||
384 | if (sequence->flags & SEQ_FLAG_MPEG2) | ||
385 | { | ||
386 | switch (sequence->pixel_width) | ||
387 | { | ||
388 | case 1: /* square pixels */ | ||
389 | sequence->pixel_width = | ||
390 | sequence->pixel_height = 1; | ||
391 | return; | ||
392 | case 2: /* 4:3 aspect ratio */ | ||
393 | width = 4; | ||
394 | height = 3; | ||
395 | break; | ||
396 | case 3: /* 16:9 aspect ratio */ | ||
397 | width = 16; | ||
398 | height = 9; | ||
399 | break; | ||
400 | case 4: /* 2.21:1 aspect ratio */ | ||
401 | width = 221; | ||
402 | height = 100; | ||
403 | break; | ||
404 | default: /* illegal */ | ||
405 | sequence->pixel_width = | ||
406 | sequence->pixel_height = 0; | ||
407 | return; | ||
408 | } | ||
409 | |||
410 | width *= sequence->display_height; | ||
411 | height *= sequence->display_width; | ||
412 | } | ||
413 | else | ||
414 | { | ||
415 | if (sequence->byte_rate == 50 * 0x3ffff) | ||
416 | sequence->byte_rate = 0; /* mpeg-1 VBR */ | ||
417 | |||
418 | switch (sequence->pixel_width) | ||
419 | { | ||
420 | case 0: | ||
421 | case 15: /* illegal */ | ||
422 | sequence->pixel_width = | ||
423 | sequence->pixel_height = 0; | ||
424 | return; | ||
425 | case 1: /* square pixels */ | ||
426 | sequence->pixel_width = | ||
427 | sequence->pixel_height = 1; | ||
428 | return; | ||
429 | case 3: /* 720x576 16:9 */ | ||
430 | sequence->pixel_width = 64; | ||
431 | sequence->pixel_height = 45; | ||
432 | return; | ||
433 | case 6: /* 720x480 16:9 */ | ||
434 | sequence->pixel_width = 32; | ||
435 | sequence->pixel_height = 27; | ||
436 | return; | ||
437 | case 8: /* BT.601 625 lines 4:3 */ | ||
438 | sequence->pixel_width = 59; | ||
439 | sequence->pixel_height = 54; | ||
440 | return; | ||
441 | case 12: /* BT.601 525 lines 4:3 */ | ||
442 | sequence->pixel_width = 10; | ||
443 | sequence->pixel_height = 11; | ||
444 | return; | ||
445 | default: | ||
446 | height = 88 * sequence->pixel_width + 1171; | ||
447 | width = 2000; | ||
448 | } | ||
449 | } | ||
450 | |||
451 | sequence->pixel_width = width; | ||
452 | sequence->pixel_height = height; | ||
453 | |||
454 | simplify(&sequence->pixel_width, &sequence->pixel_height); | ||
455 | } | ||
456 | |||
457 | int mpeg2_guess_aspect (const mpeg2_sequence_t * sequence, | ||
458 | unsigned int * pixel_width, | ||
459 | unsigned int * pixel_height) | ||
460 | { | ||
461 | static const struct | ||
462 | { | ||
463 | unsigned int width, height; | ||
464 | } video_modes[] = | ||
465 | { | ||
466 | {720, 576}, /* 625 lines, 13.5 MHz (D1, DV, DVB, DVD) */ | ||
467 | {704, 576}, /* 625 lines, 13.5 MHz (1/1 D1, DVB, DVD, 4CIF) */ | ||
468 | {544, 576}, /* 625 lines, 10.125 MHz (DVB, laserdisc) */ | ||
469 | {528, 576}, /* 625 lines, 10.125 MHz (3/4 D1, DVB, laserdisc) */ | ||
470 | {480, 576}, /* 625 lines, 9 MHz (2/3 D1, DVB, SVCD) */ | ||
471 | {352, 576}, /* 625 lines, 6.75 MHz (D2, 1/2 D1, CVD, DVB, DVD) */ | ||
472 | {352, 288}, /* 625 lines, 6.75 MHz, 1 field (D4, VCD, DVB, DVD, CIF) */ | ||
473 | {176, 144}, /* 625 lines, 3.375 MHz, half field (QCIF) */ | ||
474 | {720, 486}, /* 525 lines, 13.5 MHz (D1) */ | ||
475 | {704, 486}, /* 525 lines, 13.5 MHz */ | ||
476 | {720, 480}, /* 525 lines, 13.5 MHz (DV, DSS, DVD) */ | ||
477 | {704, 480}, /* 525 lines, 13.5 MHz (1/1 D1, ATSC, DVD) */ | ||
478 | {544, 480}, /* 525 lines. 10.125 MHz (DSS, laserdisc) */ | ||
479 | {528, 480}, /* 525 lines. 10.125 MHz (3/4 D1, laserdisc) */ | ||
480 | {480, 480}, /* 525 lines, 9 MHz (2/3 D1, SVCD) */ | ||
481 | {352, 480}, /* 525 lines, 6.75 MHz (D2, 1/2 D1, CVD, DVD) */ | ||
482 | {352, 240} /* 525 lines. 6.75 MHz, 1 field (D4, VCD, DSS, DVD) */ | ||
483 | }; | ||
484 | unsigned int width, height, pix_width, pix_height, i, DAR_16_9; | ||
485 | |||
486 | *pixel_width = sequence->pixel_width; | ||
487 | *pixel_height = sequence->pixel_height; | ||
488 | width = sequence->picture_width; | ||
489 | height = sequence->picture_height; | ||
490 | |||
491 | for (i = 0; i < sizeof (video_modes) / sizeof (video_modes[0]); i++) | ||
492 | { | ||
493 | if (width == video_modes[i].width && height == video_modes[i].height) | ||
494 | break; | ||
495 | } | ||
496 | |||
497 | if (i == ARRAYLEN(video_modes) || | ||
498 | (sequence->pixel_width == 1 && sequence->pixel_height == 1) || | ||
499 | width != sequence->display_width || height != sequence->display_height) | ||
500 | { | ||
501 | return 0; | ||
502 | } | ||
503 | |||
504 | for (pix_height = 1; height * pix_height < 480; pix_height <<= 1); | ||
505 | height *= pix_height; | ||
506 | |||
507 | for (pix_width = 1; width * pix_width <= 352; pix_width <<= 1); | ||
508 | width *= pix_width; | ||
509 | |||
510 | if (!(sequence->flags & SEQ_FLAG_MPEG2)) | ||
511 | { | ||
512 | static unsigned int mpeg1_check[2][2] = {{11, 54}, {27, 45}}; | ||
513 | DAR_16_9 = (sequence->pixel_height == 27 || | ||
514 | sequence->pixel_height == 45); | ||
515 | if (width < 704 || | ||
516 | sequence->pixel_height != mpeg1_check[DAR_16_9][height == 576]) | ||
517 | return 0; | ||
518 | } | ||
519 | else | ||
520 | { | ||
521 | DAR_16_9 = (3 * sequence->picture_width * sequence->pixel_width > | ||
522 | 4 * sequence->picture_height * sequence->pixel_height); | ||
523 | switch (width) | ||
524 | { | ||
525 | case 528: | ||
526 | case 544: | ||
527 | pix_width *= 4; | ||
528 | pix_height *= 3; | ||
529 | break; | ||
530 | case 480: | ||
531 | pix_width *= 3; | ||
532 | pix_height *= 2; | ||
533 | break; | ||
534 | } | ||
535 | } | ||
536 | |||
537 | if (DAR_16_9) | ||
538 | { | ||
539 | pix_width *= 4; | ||
540 | pix_height *= 3; | ||
541 | } | ||
542 | |||
543 | if (height == 576) | ||
544 | { | ||
545 | pix_width *= 59; | ||
546 | pix_height *= 54; | ||
547 | } | ||
548 | else | ||
549 | { | ||
550 | pix_width *= 10; | ||
551 | pix_height *= 11; | ||
552 | } | ||
553 | |||
554 | *pixel_width = pix_width; | ||
555 | *pixel_height = pix_height; | ||
556 | |||
557 | simplify (pixel_width, pixel_height); | ||
558 | |||
559 | return (height == 576) ? 1 : 2; | ||
560 | } | ||
561 | |||
562 | static void copy_matrix (mpeg2dec_t * mpeg2dec, int index) | ||
563 | { | ||
564 | if (rb->memcmp (mpeg2dec->quantizer_matrix[index], | ||
565 | mpeg2dec->new_quantizer_matrix[index], 64)) | ||
566 | { | ||
567 | rb->memcpy (mpeg2dec->quantizer_matrix[index], | ||
568 | mpeg2dec->new_quantizer_matrix[index], 64); | ||
569 | |||
570 | mpeg2dec->scaled[index] = -1; | ||
571 | } | ||
572 | } | ||
573 | |||
574 | static void finalize_matrix (mpeg2dec_t * mpeg2dec) | ||
575 | { | ||
576 | mpeg2_decoder_t *decoder = &mpeg2dec->decoder; | ||
577 | int i; | ||
578 | |||
579 | for (i = 0; i < 2; i++) | ||
580 | { | ||
581 | if (mpeg2dec->copy_matrix & (1 << i)) | ||
582 | copy_matrix (mpeg2dec, i); | ||
583 | |||
584 | if ((mpeg2dec->copy_matrix & (4 << i)) && | ||
585 | rb->memcmp(mpeg2dec->quantizer_matrix[i], | ||
586 | mpeg2dec->new_quantizer_matrix[i+2], 64)) | ||
587 | { | ||
588 | copy_matrix (mpeg2dec, i + 2); | ||
589 | decoder->chroma_quantizer[i] = decoder->quantizer_prescale[i+2]; | ||
590 | } | ||
591 | else if (mpeg2dec->copy_matrix & (5 << i)) | ||
592 | { | ||
593 | decoder->chroma_quantizer[i] = decoder->quantizer_prescale[i]; | ||
594 | } | ||
595 | } | ||
596 | } | ||
597 | |||
598 | static mpeg2_state_t invalid_end_action (mpeg2dec_t * mpeg2dec) | ||
599 | { | ||
600 | mpeg2_reset_info (&mpeg2dec->info); | ||
601 | |||
602 | mpeg2dec->info.gop = NULL; | ||
603 | |||
604 | info_user_data (mpeg2dec); | ||
605 | |||
606 | mpeg2_header_state_init (mpeg2dec); | ||
607 | |||
608 | mpeg2dec->sequence = mpeg2dec->new_sequence; | ||
609 | mpeg2dec->action = mpeg2_seek_header; | ||
610 | mpeg2dec->state = STATE_SEQUENCE; | ||
611 | |||
612 | return STATE_SEQUENCE; | ||
613 | } | ||
614 | |||
615 | void mpeg2_header_sequence_finalize (mpeg2dec_t * mpeg2dec) | ||
616 | { | ||
617 | mpeg2_sequence_t * sequence = &mpeg2dec->new_sequence; | ||
618 | mpeg2_decoder_t * decoder = &mpeg2dec->decoder; | ||
619 | |||
620 | finalize_sequence(sequence); | ||
621 | finalize_matrix(mpeg2dec); | ||
622 | |||
623 | decoder->mpeg1 = !(sequence->flags & SEQ_FLAG_MPEG2); | ||
624 | decoder->width = sequence->width; | ||
625 | decoder->height = sequence->height; | ||
626 | decoder->vertical_position_extension = sequence->picture_height > 2800; | ||
627 | decoder->chroma_format = (sequence->chroma_width == sequence->width) + | ||
628 | (sequence->chroma_height == sequence->height); | ||
629 | |||
630 | if (mpeg2dec->sequence.width != (unsigned)-1) | ||
631 | { | ||
632 | /* | ||
633 | * According to 6.1.1.6, repeat sequence headers should be | ||
634 | * identical to the original. However some encoders don't | ||
635 | * respect that and change various fields (including bitrate | ||
636 | * and aspect ratio) in the repeat sequence headers. So we | ||
637 | * choose to be as conservative as possible and only restart | ||
638 | * the decoder if the width, height, chroma_width, | ||
639 | * chroma_height or low_delay flag are modified. | ||
640 | */ | ||
641 | if (sequence->width != mpeg2dec->sequence.width || | ||
642 | sequence->height != mpeg2dec->sequence.height || | ||
643 | sequence->chroma_width != mpeg2dec->sequence.chroma_width || | ||
644 | sequence->chroma_height != mpeg2dec->sequence.chroma_height || | ||
645 | ((sequence->flags ^ mpeg2dec->sequence.flags) & | ||
646 | SEQ_FLAG_LOW_DELAY)) | ||
647 | { | ||
648 | decoder->stride_frame = sequence->width; | ||
649 | mpeg2_header_end (mpeg2dec); | ||
650 | mpeg2dec->action = invalid_end_action; | ||
651 | mpeg2dec->state = STATE_INVALID_END; | ||
652 | return; | ||
653 | } | ||
654 | |||
655 | mpeg2dec->state = rb->memcmp(&mpeg2dec->sequence, sequence, | ||
656 | sizeof (mpeg2_sequence_t)) ? | ||
657 | STATE_SEQUENCE_MODIFIED : | ||
658 | STATE_SEQUENCE_REPEATED; | ||
659 | } | ||
660 | else | ||
661 | { | ||
662 | decoder->stride_frame = sequence->width; | ||
663 | } | ||
664 | |||
665 | mpeg2dec->sequence = *sequence; | ||
666 | mpeg2_reset_info(&mpeg2dec->info); | ||
667 | mpeg2dec->info.sequence = &mpeg2dec->sequence; | ||
668 | mpeg2dec->info.gop = NULL; | ||
669 | |||
670 | info_user_data (mpeg2dec); | ||
671 | } | ||
672 | |||
673 | int mpeg2_header_gop (mpeg2dec_t * mpeg2dec) | ||
674 | { | ||
675 | uint8_t * buffer = mpeg2dec->chunk_start; | ||
676 | mpeg2_gop_t * gop = &mpeg2dec->new_gop; | ||
677 | |||
678 | if (!(buffer[1] & 8)) | ||
679 | return 1; | ||
680 | |||
681 | gop->hours = (buffer[0] >> 2) & 31; | ||
682 | gop->minutes = ((buffer[0] << 4) | (buffer[1] >> 4)) & 63; | ||
683 | gop->seconds = ((buffer[1] << 3) | (buffer[2] >> 5)) & 63; | ||
684 | gop->pictures = ((buffer[2] << 1) | (buffer[3] >> 7)) & 63; | ||
685 | gop->flags = (buffer[0] >> 7) | ((buffer[3] >> 4) & 6); | ||
686 | |||
687 | mpeg2dec->state = STATE_GOP; | ||
688 | return 0; | ||
689 | } | ||
690 | |||
691 | void mpeg2_header_gop_finalize (mpeg2dec_t * mpeg2dec) | ||
692 | { | ||
693 | mpeg2dec->gop = mpeg2dec->new_gop; | ||
694 | mpeg2_reset_info (&mpeg2dec->info); | ||
695 | mpeg2dec->info.gop = &mpeg2dec->gop; | ||
696 | info_user_data (mpeg2dec); | ||
697 | } | ||
698 | |||
699 | void mpeg2_set_fbuf (mpeg2dec_t * mpeg2dec, int b_type) | ||
700 | { | ||
701 | int i; | ||
702 | |||
703 | for (i = 0; i < 3; i++) | ||
704 | { | ||
705 | if (mpeg2dec->fbuf[1] != &mpeg2dec->fbuf_alloc[i].fbuf && | ||
706 | mpeg2dec->fbuf[2] != &mpeg2dec->fbuf_alloc[i].fbuf) | ||
707 | { | ||
708 | mpeg2dec->fbuf[0] = &mpeg2dec->fbuf_alloc[i].fbuf; | ||
709 | mpeg2dec->info.current_fbuf = mpeg2dec->fbuf[0]; | ||
710 | |||
711 | if (b_type || (mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY)) | ||
712 | { | ||
713 | if (b_type || mpeg2dec->convert) | ||
714 | mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[0]; | ||
715 | |||
716 | mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[0]; | ||
717 | } | ||
718 | |||
719 | break; | ||
720 | } | ||
721 | } | ||
722 | } | ||
723 | |||
724 | int mpeg2_header_picture (mpeg2dec_t * mpeg2dec) | ||
725 | { | ||
726 | uint8_t * buffer = mpeg2dec->chunk_start; | ||
727 | mpeg2_picture_t * picture = &mpeg2dec->new_picture; | ||
728 | mpeg2_decoder_t * decoder = &mpeg2dec->decoder; | ||
729 | int type; | ||
730 | |||
731 | mpeg2dec->state = (mpeg2dec->state != STATE_SLICE_1ST) ? | ||
732 | STATE_PICTURE : STATE_PICTURE_2ND; | ||
733 | mpeg2dec->ext_state = PIC_CODING_EXT; | ||
734 | |||
735 | picture->temporal_reference = (buffer[0] << 2) | (buffer[1] >> 6); | ||
736 | |||
737 | type = (buffer [1] >> 3) & 7; | ||
738 | |||
739 | if (type == PIC_FLAG_CODING_TYPE_P || type == PIC_FLAG_CODING_TYPE_B) | ||
740 | { | ||
741 | /* forward_f_code and backward_f_code - used in mpeg1 only */ | ||
742 | decoder->f_motion.f_code[1] = (buffer[3] >> 2) & 1; | ||
743 | decoder->f_motion.f_code[0] = | ||
744 | (((buffer[3] << 1) | (buffer[4] >> 7)) & 7) - 1; | ||
745 | decoder->b_motion.f_code[1] = (buffer[4] >> 6) & 1; | ||
746 | decoder->b_motion.f_code[0] = ((buffer[4] >> 3) & 7) - 1; | ||
747 | } | ||
748 | |||
749 | picture->flags = PIC_FLAG_PROGRESSIVE_FRAME | type; | ||
750 | picture->tag = picture->tag2 = 0; | ||
751 | |||
752 | if (mpeg2dec->num_tags) | ||
753 | { | ||
754 | if (mpeg2dec->bytes_since_tag >= mpeg2dec->chunk_ptr - buffer + 4) | ||
755 | { | ||
756 | mpeg2dec->num_tags = 0; | ||
757 | picture->tag = mpeg2dec->tag_current; | ||
758 | picture->tag2 = mpeg2dec->tag2_current; | ||
759 | picture->flags |= PIC_FLAG_TAGS; | ||
760 | } | ||
761 | else if (mpeg2dec->num_tags > 1) | ||
762 | { | ||
763 | mpeg2dec->num_tags = 1; | ||
764 | picture->tag = mpeg2dec->tag_previous; | ||
765 | picture->tag2 = mpeg2dec->tag2_previous; | ||
766 | picture->flags |= PIC_FLAG_TAGS; | ||
767 | } | ||
768 | } | ||
769 | |||
770 | picture->nb_fields = 2; | ||
771 | picture->display_offset[0].x = picture->display_offset[1].x = | ||
772 | picture->display_offset[2].x = mpeg2dec->display_offset_x; | ||
773 | |||
774 | picture->display_offset[0].y = picture->display_offset[1].y = | ||
775 | picture->display_offset[2].y = mpeg2dec->display_offset_y; | ||
776 | |||
777 | /* XXXXXX decode extra_information_picture as well */ | ||
778 | |||
779 | mpeg2dec->q_scale_type = 0; | ||
780 | decoder->intra_dc_precision = 7; | ||
781 | decoder->frame_pred_frame_dct = 1; | ||
782 | decoder->concealment_motion_vectors = 0; | ||
783 | decoder->scan = mpeg2_scan_norm; | ||
784 | decoder->picture_structure = FRAME_PICTURE; | ||
785 | mpeg2dec->copy_matrix = 0; | ||
786 | |||
787 | return 0; | ||
788 | } | ||
789 | |||
790 | static int picture_coding_ext (mpeg2dec_t * mpeg2dec) | ||
791 | { | ||
792 | uint8_t * buffer = mpeg2dec->chunk_start; | ||
793 | mpeg2_picture_t * picture = &mpeg2dec->new_picture; | ||
794 | mpeg2_decoder_t * decoder = &mpeg2dec->decoder; | ||
795 | uint32_t flags; | ||
796 | |||
797 | /* pre subtract 1 for use later in compute_motion_vector */ | ||
798 | decoder->f_motion.f_code[0] = (buffer[0] & 15) - 1; | ||
799 | decoder->f_motion.f_code[1] = (buffer[1] >> 4) - 1; | ||
800 | decoder->b_motion.f_code[0] = (buffer[1] & 15) - 1; | ||
801 | decoder->b_motion.f_code[1] = (buffer[2] >> 4) - 1; | ||
802 | |||
803 | flags = picture->flags; | ||
804 | |||
805 | decoder->intra_dc_precision = 7 - ((buffer[2] >> 2) & 3); | ||
806 | decoder->picture_structure = buffer[2] & 3; | ||
807 | |||
808 | switch (decoder->picture_structure) | ||
809 | { | ||
810 | case TOP_FIELD: | ||
811 | flags |= PIC_FLAG_TOP_FIELD_FIRST; | ||
812 | case BOTTOM_FIELD: | ||
813 | picture->nb_fields = 1; | ||
814 | break; | ||
815 | case FRAME_PICTURE: | ||
816 | if (!(mpeg2dec->sequence.flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE)) | ||
817 | { | ||
818 | picture->nb_fields = (buffer[3] & 2) ? 3 : 2; | ||
819 | flags |= (buffer[3] & 128) ? PIC_FLAG_TOP_FIELD_FIRST : 0; | ||
820 | } | ||
821 | else | ||
822 | { | ||
823 | picture->nb_fields = (buffer[3]&2) ? ((buffer[3]&128) ? 6 : 4) : 2; | ||
824 | } | ||
825 | break; | ||
826 | default: | ||
827 | return 1; | ||
828 | } | ||
829 | |||
830 | decoder->top_field_first = buffer[3] >> 7; | ||
831 | decoder->frame_pred_frame_dct = (buffer[3] >> 6) & 1; | ||
832 | decoder->concealment_motion_vectors = (buffer[3] >> 5) & 1; | ||
833 | mpeg2dec->q_scale_type = buffer[3] & 16; | ||
834 | decoder->intra_vlc_format = (buffer[3] >> 3) & 1; | ||
835 | decoder->scan = (buffer[3] & 4) ? mpeg2_scan_alt : mpeg2_scan_norm; | ||
836 | |||
837 | if (!(buffer[4] & 0x80)) | ||
838 | flags &= ~PIC_FLAG_PROGRESSIVE_FRAME; | ||
839 | |||
840 | if (buffer[4] & 0x40) | ||
841 | { | ||
842 | flags |= (((buffer[4]<<26) | (buffer[5]<<18) | (buffer[6]<<10)) & | ||
843 | PIC_MASK_COMPOSITE_DISPLAY) | PIC_FLAG_COMPOSITE_DISPLAY; | ||
844 | } | ||
845 | |||
846 | picture->flags = flags; | ||
847 | |||
848 | mpeg2dec->ext_state = PIC_DISPLAY_EXT | COPYRIGHT_EXT | QUANT_MATRIX_EXT; | ||
849 | |||
850 | return 0; | ||
851 | } | ||
852 | |||
853 | static int picture_display_ext (mpeg2dec_t * mpeg2dec) | ||
854 | { | ||
855 | uint8_t * buffer = mpeg2dec->chunk_start; | ||
856 | mpeg2_picture_t * picture = &mpeg2dec->new_picture; | ||
857 | int i, nb_pos; | ||
858 | |||
859 | nb_pos = picture->nb_fields; | ||
860 | |||
861 | if (mpeg2dec->sequence.flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE) | ||
862 | nb_pos >>= 1; | ||
863 | |||
864 | for (i = 0; i < nb_pos; i++) | ||
865 | { | ||
866 | int x, y; | ||
867 | |||
868 | x = ((buffer[4*i] << 24) | (buffer[4*i+1] << 16) | | ||
869 | (buffer[4*i+2] << 8) | buffer[4*i+3]) >> (11-2*i); | ||
870 | |||
871 | y = ((buffer[4*i+2] << 24) | (buffer[4*i+3] << 16) | | ||
872 | (buffer[4*i+4] << 8) | buffer[4*i+5]) >> (10-2*i); | ||
873 | |||
874 | if (! (x & y & 1)) | ||
875 | return 1; | ||
876 | |||
877 | picture->display_offset[i].x = mpeg2dec->display_offset_x = x >> 1; | ||
878 | picture->display_offset[i].y = mpeg2dec->display_offset_y = y >> 1; | ||
879 | } | ||
880 | |||
881 | for (; i < 3; i++) | ||
882 | { | ||
883 | picture->display_offset[i].x = mpeg2dec->display_offset_x; | ||
884 | picture->display_offset[i].y = mpeg2dec->display_offset_y; | ||
885 | } | ||
886 | |||
887 | return 0; | ||
888 | } | ||
889 | |||
890 | void mpeg2_header_picture_finalize (mpeg2dec_t * mpeg2dec) | ||
891 | { | ||
892 | mpeg2_decoder_t * decoder = &mpeg2dec->decoder; | ||
893 | int old_type_b = decoder->coding_type == B_TYPE; | ||
894 | int low_delay = mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY; | ||
895 | |||
896 | finalize_matrix (mpeg2dec); | ||
897 | decoder->coding_type = mpeg2dec->new_picture.flags & PIC_MASK_CODING_TYPE; | ||
898 | |||
899 | if (mpeg2dec->state == STATE_PICTURE) | ||
900 | { | ||
901 | mpeg2_picture_t * picture; | ||
902 | mpeg2_picture_t * other; | ||
903 | |||
904 | decoder->second_field = 0; | ||
905 | |||
906 | picture = other = mpeg2dec->pictures; | ||
907 | |||
908 | if (old_type_b ^ (mpeg2dec->picture < mpeg2dec->pictures + 2)) | ||
909 | picture += 2; | ||
910 | else | ||
911 | other += 2; | ||
912 | |||
913 | mpeg2dec->picture = picture; | ||
914 | *picture = mpeg2dec->new_picture; | ||
915 | |||
916 | if (!old_type_b) | ||
917 | { | ||
918 | mpeg2dec->fbuf[2] = mpeg2dec->fbuf[1]; | ||
919 | mpeg2dec->fbuf[1] = mpeg2dec->fbuf[0]; | ||
920 | } | ||
921 | |||
922 | mpeg2dec->fbuf[0] = NULL; | ||
923 | mpeg2_reset_info (&mpeg2dec->info); | ||
924 | mpeg2dec->info.current_picture = picture; | ||
925 | mpeg2dec->info.display_picture = picture; | ||
926 | |||
927 | if (decoder->coding_type != B_TYPE) | ||
928 | { | ||
929 | if (!low_delay) | ||
930 | { | ||
931 | if (mpeg2dec->first) | ||
932 | { | ||
933 | mpeg2dec->info.display_picture = NULL; | ||
934 | mpeg2dec->first = 0; | ||
935 | } | ||
936 | else | ||
937 | { | ||
938 | mpeg2dec->info.display_picture = other; | ||
939 | |||
940 | if (other->nb_fields == 1) | ||
941 | mpeg2dec->info.display_picture_2nd = other + 1; | ||
942 | |||
943 | mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[1]; | ||
944 | } | ||
945 | } | ||
946 | |||
947 | if (!low_delay + !mpeg2dec->convert) | ||
948 | { | ||
949 | mpeg2dec->info.discard_fbuf = | ||
950 | mpeg2dec->fbuf[!low_delay + !mpeg2dec->convert]; | ||
951 | } | ||
952 | } | ||
953 | |||
954 | if (mpeg2dec->convert) | ||
955 | { | ||
956 | mpeg2_convert_init_t convert_init; | ||
957 | |||
958 | if (!mpeg2dec->convert_start) | ||
959 | { | ||
960 | mpeg2dec->decoder.convert_id = | ||
961 | mpeg2_malloc (mpeg2dec->convert_id_size, | ||
962 | MPEG2_ALLOC_CONVERT_ID); | ||
963 | |||
964 | mpeg2dec->convert (MPEG2_CONVERT_START, | ||
965 | mpeg2dec->decoder.convert_id, | ||
966 | &mpeg2dec->sequence, | ||
967 | mpeg2dec->convert_stride, | ||
968 | mpeg2dec->convert_arg, &convert_init); | ||
969 | |||
970 | mpeg2dec->convert_start = convert_init.start; | ||
971 | mpeg2dec->decoder.convert = convert_init.copy; | ||
972 | |||
973 | int y_size = decoder->stride_frame * mpeg2dec->sequence.height; | ||
974 | |||
975 | mpeg2dec->yuv_buf[0][0] = | ||
976 | (uint8_t *) mpeg2_malloc(y_size, MPEG2_ALLOC_YUV); | ||
977 | #if MPEG2_COLOR | ||
978 | int uv_size = y_size >> (2 - mpeg2dec->decoder.chroma_format); | ||
979 | |||
980 | mpeg2dec->yuv_buf[0][1] = | ||
981 | (uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV); | ||
982 | mpeg2dec->yuv_buf[0][2] = | ||
983 | (uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV); | ||
984 | #endif | ||
985 | |||
986 | mpeg2dec->yuv_buf[1][0] = | ||
987 | (uint8_t *) mpeg2_malloc(y_size, MPEG2_ALLOC_YUV); | ||
988 | #if MPEG2_COLOR | ||
989 | mpeg2dec->yuv_buf[1][1] = | ||
990 | (uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV); | ||
991 | mpeg2dec->yuv_buf[1][2] = | ||
992 | (uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV); | ||
993 | #endif | ||
994 | y_size = decoder->stride_frame * 32; | ||
995 | |||
996 | mpeg2dec->yuv_buf[2][0] = | ||
997 | (uint8_t *) mpeg2_malloc(y_size, MPEG2_ALLOC_YUV); | ||
998 | #if MPEG2_COLOR | ||
999 | uv_size = y_size >> (2 - mpeg2dec->decoder.chroma_format); | ||
1000 | |||
1001 | mpeg2dec->yuv_buf[2][1] = | ||
1002 | (uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV); | ||
1003 | mpeg2dec->yuv_buf[2][2] = | ||
1004 | (uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV); | ||
1005 | #endif | ||
1006 | } | ||
1007 | |||
1008 | if (!mpeg2dec->custom_fbuf) | ||
1009 | { | ||
1010 | while (mpeg2dec->alloc_index < 3) | ||
1011 | { | ||
1012 | mpeg2_fbuf_t * fbuf; | ||
1013 | |||
1014 | fbuf = &mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index++].fbuf; | ||
1015 | fbuf->id = NULL; | ||
1016 | |||
1017 | fbuf->buf[0] = | ||
1018 | (uint8_t *) mpeg2_malloc (convert_init.buf_size[0], | ||
1019 | MPEG2_ALLOC_CONVERTED); | ||
1020 | #if MPEG2_COLOR | ||
1021 | fbuf->buf[1] = | ||
1022 | (uint8_t *) mpeg2_malloc (convert_init.buf_size[1], | ||
1023 | MPEG2_ALLOC_CONVERTED); | ||
1024 | fbuf->buf[2] = | ||
1025 | (uint8_t *) mpeg2_malloc (convert_init.buf_size[2], | ||
1026 | MPEG2_ALLOC_CONVERTED); | ||
1027 | #endif | ||
1028 | } | ||
1029 | |||
1030 | mpeg2_set_fbuf (mpeg2dec, (decoder->coding_type == B_TYPE)); | ||
1031 | } | ||
1032 | } | ||
1033 | else if (!mpeg2dec->custom_fbuf) | ||
1034 | { | ||
1035 | while (mpeg2dec->alloc_index < 3) | ||
1036 | { | ||
1037 | mpeg2_fbuf_t * fbuf; | ||
1038 | |||
1039 | fbuf = &mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index++].fbuf; | ||
1040 | |||
1041 | fbuf->id = NULL; | ||
1042 | |||
1043 | int y_size = decoder->stride_frame * mpeg2dec->sequence.height; | ||
1044 | |||
1045 | fbuf->buf[0] = (uint8_t *) mpeg2_malloc (y_size, | ||
1046 | MPEG2_ALLOC_YUV); | ||
1047 | #if MPEG2_COLOR | ||
1048 | int uv_size = y_size >> (2 - decoder->chroma_format); | ||
1049 | |||
1050 | fbuf->buf[1] = (uint8_t *) mpeg2_malloc (uv_size, | ||
1051 | MPEG2_ALLOC_YUV); | ||
1052 | fbuf->buf[2] = (uint8_t *) mpeg2_malloc (uv_size, | ||
1053 | MPEG2_ALLOC_YUV); | ||
1054 | #endif | ||
1055 | } | ||
1056 | |||
1057 | mpeg2_set_fbuf (mpeg2dec, (decoder->coding_type == B_TYPE)); | ||
1058 | } | ||
1059 | } | ||
1060 | else | ||
1061 | { | ||
1062 | decoder->second_field = 1; | ||
1063 | mpeg2dec->picture++; /* second field picture */ | ||
1064 | |||
1065 | *(mpeg2dec->picture) = mpeg2dec->new_picture; | ||
1066 | |||
1067 | mpeg2dec->info.current_picture_2nd = mpeg2dec->picture; | ||
1068 | |||
1069 | if (low_delay || decoder->coding_type == B_TYPE) | ||
1070 | mpeg2dec->info.display_picture_2nd = mpeg2dec->picture; | ||
1071 | } | ||
1072 | |||
1073 | info_user_data (mpeg2dec); | ||
1074 | } | ||
1075 | |||
1076 | static int copyright_ext (mpeg2dec_t * mpeg2dec) | ||
1077 | { | ||
1078 | (void)mpeg2dec; | ||
1079 | return 0; | ||
1080 | } | ||
1081 | |||
1082 | static int quant_matrix_ext (mpeg2dec_t * mpeg2dec) | ||
1083 | { | ||
1084 | uint8_t * buffer = mpeg2dec->chunk_start; | ||
1085 | int i, j; | ||
1086 | |||
1087 | for (i = 0; i < 4; i++) | ||
1088 | { | ||
1089 | if (buffer[0] & (8 >> i)) | ||
1090 | { | ||
1091 | for (j = 0; j < 64; j++) | ||
1092 | { | ||
1093 | mpeg2dec->new_quantizer_matrix[i][mpeg2_scan_norm[j]] = | ||
1094 | (buffer[j] << (i+5)) | (buffer[j+1] >> (3-i)); | ||
1095 | } | ||
1096 | |||
1097 | mpeg2dec->copy_matrix |= 1 << i; | ||
1098 | buffer += 64; | ||
1099 | } | ||
1100 | } | ||
1101 | |||
1102 | return 0; | ||
1103 | } | ||
1104 | |||
1105 | int mpeg2_header_extension (mpeg2dec_t * mpeg2dec) | ||
1106 | { | ||
1107 | static int (* const parser[9]) (mpeg2dec_t *) = | ||
1108 | { | ||
1109 | NULL, | ||
1110 | sequence_ext, | ||
1111 | sequence_display_ext, | ||
1112 | quant_matrix_ext, | ||
1113 | copyright_ext, | ||
1114 | NULL, | ||
1115 | NULL, | ||
1116 | picture_display_ext, | ||
1117 | picture_coding_ext | ||
1118 | }; | ||
1119 | |||
1120 | int ext, ext_bit; | ||
1121 | |||
1122 | ext = mpeg2dec->chunk_start[0] >> 4; | ||
1123 | ext_bit = 1 << ext; | ||
1124 | |||
1125 | if (!(mpeg2dec->ext_state & ext_bit)) | ||
1126 | return 0; /* ignore illegal extensions */ | ||
1127 | |||
1128 | mpeg2dec->ext_state &= ~ext_bit; | ||
1129 | |||
1130 | return parser[ext] (mpeg2dec); | ||
1131 | } | ||
1132 | |||
1133 | int mpeg2_header_user_data (mpeg2dec_t * mpeg2dec) | ||
1134 | { | ||
1135 | mpeg2dec->user_data_len += mpeg2dec->chunk_ptr - 1 - mpeg2dec->chunk_start; | ||
1136 | mpeg2dec->chunk_start = mpeg2dec->chunk_ptr - 1; | ||
1137 | |||
1138 | return 0; | ||
1139 | } | ||
1140 | |||
1141 | static void prescale (mpeg2dec_t * mpeg2dec, int index) | ||
1142 | { | ||
1143 | static const int non_linear_scale[32] = | ||
1144 | { | ||
1145 | 0, 1, 2, 3, 4, 5, 6, 7, | ||
1146 | 8, 10, 12, 14, 16, 18, 20, 22, | ||
1147 | 24, 28, 32, 36, 40, 44, 48, 52, | ||
1148 | 56, 64, 72, 80, 88, 96, 104, 112 | ||
1149 | }; | ||
1150 | |||
1151 | int i, j, k; | ||
1152 | mpeg2_decoder_t * decoder = &mpeg2dec->decoder; | ||
1153 | |||
1154 | if (mpeg2dec->scaled[index] != mpeg2dec->q_scale_type) | ||
1155 | { | ||
1156 | mpeg2dec->scaled[index] = mpeg2dec->q_scale_type; | ||
1157 | |||
1158 | for (i = 0; i < 32; i++) | ||
1159 | { | ||
1160 | k = mpeg2dec->q_scale_type ? non_linear_scale[i] : (i << 1); | ||
1161 | |||
1162 | for (j = 0; j < 64; j++) | ||
1163 | { | ||
1164 | decoder->quantizer_prescale[index][i][j] = | ||
1165 | k * mpeg2dec->quantizer_matrix[index][j]; | ||
1166 | } | ||
1167 | } | ||
1168 | } | ||
1169 | } | ||
1170 | |||
1171 | mpeg2_state_t mpeg2_header_slice_start (mpeg2dec_t * mpeg2dec) | ||
1172 | { | ||
1173 | mpeg2_decoder_t * decoder = &mpeg2dec->decoder; | ||
1174 | |||
1175 | mpeg2dec->info.user_data = NULL; | ||
1176 | mpeg2dec->info.user_data_len = 0; | ||
1177 | mpeg2dec->state = (mpeg2dec->picture->nb_fields > 1 || | ||
1178 | mpeg2dec->state == STATE_PICTURE_2ND) ? | ||
1179 | STATE_SLICE : STATE_SLICE_1ST; | ||
1180 | |||
1181 | if (mpeg2dec->decoder.coding_type != D_TYPE) | ||
1182 | { | ||
1183 | prescale (mpeg2dec, 0); | ||
1184 | |||
1185 | if (decoder->chroma_quantizer[0] == decoder->quantizer_prescale[2]) | ||
1186 | prescale (mpeg2dec, 2); | ||
1187 | |||
1188 | if (mpeg2dec->decoder.coding_type != I_TYPE) | ||
1189 | { | ||
1190 | prescale (mpeg2dec, 1); | ||
1191 | |||
1192 | if (decoder->chroma_quantizer[1] == decoder->quantizer_prescale[3]) | ||
1193 | prescale (mpeg2dec, 3); | ||
1194 | } | ||
1195 | } | ||
1196 | |||
1197 | if (!(mpeg2dec->nb_decode_slices)) | ||
1198 | { | ||
1199 | mpeg2dec->picture->flags |= PIC_FLAG_SKIP; | ||
1200 | } | ||
1201 | else if (mpeg2dec->convert_start) | ||
1202 | { | ||
1203 | mpeg2dec->convert_start (decoder->convert_id, mpeg2dec->fbuf[0], | ||
1204 | mpeg2dec->picture, mpeg2dec->info.gop); | ||
1205 | |||
1206 | if (mpeg2dec->decoder.coding_type == B_TYPE) | ||
1207 | { | ||
1208 | mpeg2_init_fbuf (&mpeg2dec->decoder, mpeg2dec->yuv_buf[2], | ||
1209 | mpeg2dec->yuv_buf[mpeg2dec->yuv_index ^ 1], | ||
1210 | mpeg2dec->yuv_buf[mpeg2dec->yuv_index]); | ||
1211 | } | ||
1212 | else | ||
1213 | { | ||
1214 | mpeg2_init_fbuf (&mpeg2dec->decoder, | ||
1215 | mpeg2dec->yuv_buf[mpeg2dec->yuv_index ^ 1], | ||
1216 | mpeg2dec->yuv_buf[mpeg2dec->yuv_index], | ||
1217 | mpeg2dec->yuv_buf[mpeg2dec->yuv_index]); | ||
1218 | |||
1219 | if (mpeg2dec->state == STATE_SLICE) | ||
1220 | mpeg2dec->yuv_index ^= 1; | ||
1221 | } | ||
1222 | } | ||
1223 | else | ||
1224 | { | ||
1225 | int b_type; | ||
1226 | |||
1227 | b_type = (mpeg2dec->decoder.coding_type == B_TYPE); | ||
1228 | |||
1229 | mpeg2_init_fbuf (&mpeg2dec->decoder, mpeg2dec->fbuf[0]->buf, | ||
1230 | mpeg2dec->fbuf[b_type + 1]->buf, | ||
1231 | mpeg2dec->fbuf[b_type]->buf); | ||
1232 | } | ||
1233 | |||
1234 | mpeg2dec->action = NULL; | ||
1235 | |||
1236 | return STATE_INTERNAL_NORETURN; | ||
1237 | } | ||
1238 | |||
1239 | static mpeg2_state_t seek_sequence (mpeg2dec_t * mpeg2dec) | ||
1240 | { | ||
1241 | mpeg2_reset_info (&mpeg2dec->info); | ||
1242 | |||
1243 | mpeg2dec->info.sequence = NULL; | ||
1244 | mpeg2dec->info.gop = NULL; | ||
1245 | |||
1246 | mpeg2_header_state_init (mpeg2dec); | ||
1247 | |||
1248 | mpeg2dec->action = mpeg2_seek_header; | ||
1249 | |||
1250 | return mpeg2_seek_header (mpeg2dec); | ||
1251 | } | ||
1252 | |||
1253 | mpeg2_state_t mpeg2_header_end (mpeg2dec_t * mpeg2dec) | ||
1254 | { | ||
1255 | mpeg2_picture_t * picture; | ||
1256 | int b_type; | ||
1257 | |||
1258 | b_type = (mpeg2dec->decoder.coding_type == B_TYPE); | ||
1259 | picture = mpeg2dec->pictures; | ||
1260 | |||
1261 | if ((mpeg2dec->picture >= picture + 2) ^ b_type) | ||
1262 | picture = mpeg2dec->pictures + 2; | ||
1263 | |||
1264 | mpeg2_reset_info (&mpeg2dec->info); | ||
1265 | |||
1266 | if (!(mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY)) | ||
1267 | { | ||
1268 | mpeg2dec->info.display_picture = picture; | ||
1269 | |||
1270 | if (picture->nb_fields == 1) | ||
1271 | mpeg2dec->info.display_picture_2nd = picture + 1; | ||
1272 | |||
1273 | mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[b_type]; | ||
1274 | |||
1275 | if (!mpeg2dec->convert) | ||
1276 | mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[b_type + 1]; | ||
1277 | } | ||
1278 | else if (!mpeg2dec->convert) | ||
1279 | { | ||
1280 | mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[b_type]; | ||
1281 | } | ||
1282 | |||
1283 | mpeg2dec->action = seek_sequence; | ||
1284 | |||
1285 | return STATE_END; | ||
1286 | } | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/idct.c b/apps/plugins/mpegplayer/libmpeg2/idct.c new file mode 100644 index 0000000000..7f0b9a3c12 --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/idct.c | |||
@@ -0,0 +1,274 @@ | |||
1 | /* | ||
2 | * idct.c | ||
3 | * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> | ||
4 | * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | ||
5 | * | ||
6 | * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. | ||
7 | * See http://libmpeg2.sourceforge.net/ for updates. | ||
8 | * | ||
9 | * mpeg2dec is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * mpeg2dec is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | ||
23 | * $Id$ | ||
24 | * libmpeg2 sync history: | ||
25 | * 2008-07-01 - CVS revision 1.36 | ||
26 | */ | ||
27 | |||
28 | #include "plugin.h" | ||
29 | |||
30 | #include "mpeg2dec_config.h" | ||
31 | |||
32 | #include "mpeg2.h" | ||
33 | #include "attributes.h" | ||
34 | #include "mpeg2_internal.h" | ||
35 | |||
36 | #if defined(CPU_COLDFIRE) || defined (CPU_ARM) | ||
37 | #define IDCT_ASM | ||
38 | #endif | ||
39 | |||
40 | #ifndef IDCT_ASM | ||
41 | |||
42 | #define W1 2841 /* 2048 * sqrt (2) * cos (1 * pi / 16) */ | ||
43 | #define W2 2676 /* 2048 * sqrt (2) * cos (2 * pi / 16) */ | ||
44 | #define W3 2408 /* 2048 * sqrt (2) * cos (3 * pi / 16) */ | ||
45 | #define W5 1609 /* 2048 * sqrt (2) * cos (5 * pi / 16) */ | ||
46 | #define W6 1108 /* 2048 * sqrt (2) * cos (6 * pi / 16) */ | ||
47 | #define W7 565 /* 2048 * sqrt (2) * cos (7 * pi / 16) */ | ||
48 | |||
49 | /* | ||
50 | * In legal streams, the IDCT output should be between -384 and +384. | ||
51 | * In corrupted streams, it is possible to force the IDCT output to go | ||
52 | * to +-3826 - this is the worst case for a column IDCT where the | ||
53 | * column inputs are 16-bit values. | ||
54 | */ | ||
55 | #define CLIP(i) \ | ||
56 | ({ typeof (i) _i = (i); \ | ||
57 | if ((_i & 0xff) != _i) \ | ||
58 | _i = ~(_i >> (8*sizeof(_i) - 1)); \ | ||
59 | _i; }) | ||
60 | |||
61 | #if 0 | ||
62 | #define BUTTERFLY(t0,t1,W0,W1,d0,d1) \ | ||
63 | do { \ | ||
64 | t0 = W0 * d0 + W1 * d1; \ | ||
65 | t1 = W0 * d1 - W1 * d0; \ | ||
66 | } while (0) | ||
67 | #else | ||
68 | #define BUTTERFLY(t0,t1,W0,W1,d0,d1) \ | ||
69 | do { \ | ||
70 | int tmp = W0 * (d0 + d1); \ | ||
71 | t0 = tmp + (W1 - W0) * d1; \ | ||
72 | t1 = tmp - (W1 + W0) * d0; \ | ||
73 | } while (0) | ||
74 | #endif | ||
75 | |||
76 | static inline void idct_row (int16_t * const block) | ||
77 | { | ||
78 | int d0, d1, d2, d3; | ||
79 | int a0, a1, a2, a3, b0, b1, b2, b3; | ||
80 | int t0, t1, t2, t3; | ||
81 | |||
82 | /* shortcut */ | ||
83 | if (likely (!(block[1] | ((int32_t *)block)[1] | ((int32_t *)block)[2] | | ||
84 | ((int32_t *)block)[3]))) | ||
85 | { | ||
86 | uint32_t tmp = (uint16_t) (block[0] >> 1); | ||
87 | tmp |= tmp << 16; | ||
88 | ((int32_t *)block)[0] = tmp; | ||
89 | ((int32_t *)block)[1] = tmp; | ||
90 | ((int32_t *)block)[2] = tmp; | ||
91 | ((int32_t *)block)[3] = tmp; | ||
92 | return; | ||
93 | } | ||
94 | |||
95 | d0 = (block[0] << 11) + 2048; | ||
96 | d1 = block[1]; | ||
97 | d2 = block[2] << 11; | ||
98 | d3 = block[3]; | ||
99 | t0 = d0 + d2; | ||
100 | t1 = d0 - d2; | ||
101 | BUTTERFLY (t2, t3, W6, W2, d3, d1); | ||
102 | a0 = t0 + t2; | ||
103 | a1 = t1 + t3; | ||
104 | a2 = t1 - t3; | ||
105 | a3 = t0 - t2; | ||
106 | |||
107 | d0 = block[4]; | ||
108 | d1 = block[5]; | ||
109 | d2 = block[6]; | ||
110 | d3 = block[7]; | ||
111 | BUTTERFLY (t0, t1, W7, W1, d3, d0); | ||
112 | BUTTERFLY (t2, t3, W3, W5, d1, d2); | ||
113 | b0 = t0 + t2; | ||
114 | b3 = t1 + t3; | ||
115 | t0 -= t2; | ||
116 | t1 -= t3; | ||
117 | b1 = ((t0 + t1) >> 8) * 181; | ||
118 | b2 = ((t0 - t1) >> 8) * 181; | ||
119 | |||
120 | block[0] = (a0 + b0) >> 12; | ||
121 | block[1] = (a1 + b1) >> 12; | ||
122 | block[2] = (a2 + b2) >> 12; | ||
123 | block[3] = (a3 + b3) >> 12; | ||
124 | block[4] = (a3 - b3) >> 12; | ||
125 | block[5] = (a2 - b2) >> 12; | ||
126 | block[6] = (a1 - b1) >> 12; | ||
127 | block[7] = (a0 - b0) >> 12; | ||
128 | } | ||
129 | |||
130 | static inline void idct_col (int16_t * const block) | ||
131 | { | ||
132 | int d0, d1, d2, d3; | ||
133 | int a0, a1, a2, a3, b0, b1, b2, b3; | ||
134 | int t0, t1, t2, t3; | ||
135 | |||
136 | d0 = (block[8*0] << 11) + 65536; | ||
137 | d1 = block[8*1]; | ||
138 | d2 = block[8*2] << 11; | ||
139 | d3 = block[8*3]; | ||
140 | t0 = d0 + d2; | ||
141 | t1 = d0 - d2; | ||
142 | BUTTERFLY (t2, t3, W6, W2, d3, d1); | ||
143 | a0 = t0 + t2; | ||
144 | a1 = t1 + t3; | ||
145 | a2 = t1 - t3; | ||
146 | a3 = t0 - t2; | ||
147 | |||
148 | d0 = block[8*4]; | ||
149 | d1 = block[8*5]; | ||
150 | d2 = block[8*6]; | ||
151 | d3 = block[8*7]; | ||
152 | BUTTERFLY (t0, t1, W7, W1, d3, d0); | ||
153 | BUTTERFLY (t2, t3, W3, W5, d1, d2); | ||
154 | b0 = t0 + t2; | ||
155 | b3 = t1 + t3; | ||
156 | t0 -= t2; | ||
157 | t1 -= t3; | ||
158 | b1 = ((t0 + t1) >> 8) * 181; | ||
159 | b2 = ((t0 - t1) >> 8) * 181; | ||
160 | |||
161 | block[8*0] = (a0 + b0) >> 17; | ||
162 | block[8*1] = (a1 + b1) >> 17; | ||
163 | block[8*2] = (a2 + b2) >> 17; | ||
164 | block[8*3] = (a3 + b3) >> 17; | ||
165 | block[8*4] = (a3 - b3) >> 17; | ||
166 | block[8*5] = (a2 - b2) >> 17; | ||
167 | block[8*6] = (a1 - b1) >> 17; | ||
168 | block[8*7] = (a0 - b0) >> 17; | ||
169 | } | ||
170 | |||
171 | void mpeg2_idct_copy (int16_t * block, uint8_t * dest, | ||
172 | const int stride) | ||
173 | { | ||
174 | int i; | ||
175 | |||
176 | for (i = 0; i < 8; i++) | ||
177 | idct_row (block + 8 * i); | ||
178 | |||
179 | for (i = 0; i < 8; i++) | ||
180 | idct_col (block + i); | ||
181 | |||
182 | do | ||
183 | { | ||
184 | dest[0] = CLIP (block[0]); | ||
185 | dest[1] = CLIP (block[1]); | ||
186 | dest[2] = CLIP (block[2]); | ||
187 | dest[3] = CLIP (block[3]); | ||
188 | dest[4] = CLIP (block[4]); | ||
189 | dest[5] = CLIP (block[5]); | ||
190 | dest[6] = CLIP (block[6]); | ||
191 | dest[7] = CLIP (block[7]); | ||
192 | |||
193 | ((int32_t *)block)[0] = 0; | ||
194 | ((int32_t *)block)[1] = 0; | ||
195 | ((int32_t *)block)[2] = 0; | ||
196 | ((int32_t *)block)[3] = 0; | ||
197 | |||
198 | dest += stride; | ||
199 | block += 8; | ||
200 | } | ||
201 | while (--i); | ||
202 | } | ||
203 | |||
204 | void mpeg2_idct_add (const int last, int16_t * block, | ||
205 | uint8_t * dest, const int stride) | ||
206 | { | ||
207 | int i; | ||
208 | |||
209 | if (last != 129 || (block[0] & (7 << 4)) == (4 << 4)) | ||
210 | { | ||
211 | for (i = 0; i < 8; i++) | ||
212 | idct_row (block + 8 * i); | ||
213 | |||
214 | for (i = 0; i < 8; i++) | ||
215 | idct_col (block + i); | ||
216 | |||
217 | do | ||
218 | { | ||
219 | dest[0] = CLIP (block[0] + dest[0]); | ||
220 | dest[1] = CLIP (block[1] + dest[1]); | ||
221 | dest[2] = CLIP (block[2] + dest[2]); | ||
222 | dest[3] = CLIP (block[3] + dest[3]); | ||
223 | dest[4] = CLIP (block[4] + dest[4]); | ||
224 | dest[5] = CLIP (block[5] + dest[5]); | ||
225 | dest[6] = CLIP (block[6] + dest[6]); | ||
226 | dest[7] = CLIP (block[7] + dest[7]); | ||
227 | |||
228 | ((int32_t *)block)[0] = 0; | ||
229 | ((int32_t *)block)[1] = 0; | ||
230 | ((int32_t *)block)[2] = 0; | ||
231 | ((int32_t *)block)[3] = 0; | ||
232 | |||
233 | dest += stride; | ||
234 | block += 8; | ||
235 | } | ||
236 | while (--i); | ||
237 | } | ||
238 | else | ||
239 | { | ||
240 | int DC = (block[0] + 64) >> 7; | ||
241 | block[0] = block[63] = 0; | ||
242 | i = 8; | ||
243 | |||
244 | do | ||
245 | { | ||
246 | dest[0] = CLIP (DC + dest[0]); | ||
247 | dest[1] = CLIP (DC + dest[1]); | ||
248 | dest[2] = CLIP (DC + dest[2]); | ||
249 | dest[3] = CLIP (DC + dest[3]); | ||
250 | dest[4] = CLIP (DC + dest[4]); | ||
251 | dest[5] = CLIP (DC + dest[5]); | ||
252 | dest[6] = CLIP (DC + dest[6]); | ||
253 | dest[7] = CLIP (DC + dest[7]); | ||
254 | dest += stride; | ||
255 | } | ||
256 | while (--i); | ||
257 | } | ||
258 | } | ||
259 | |||
260 | #endif /* IDCT_ASM */ | ||
261 | |||
262 | void mpeg2_idct_init (void) | ||
263 | { | ||
264 | int i, j; | ||
265 | |||
266 | for (i = 0; i < 64; i++) | ||
267 | { | ||
268 | j = default_mpeg2_scan_norm[i]; | ||
269 | mpeg2_scan_norm[i] = ((j & 0x36) >> 1) | ((j & 0x09) << 2); | ||
270 | |||
271 | j = default_mpeg2_scan_alt[i]; | ||
272 | mpeg2_scan_alt[i] = ((j & 0x36) >> 1) | ((j & 0x09) << 2); | ||
273 | } | ||
274 | } | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/idct_arm.S b/apps/plugins/mpegplayer/libmpeg2/idct_arm.S new file mode 100644 index 0000000000..97a87a8b59 --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/idct_arm.S | |||
@@ -0,0 +1,443 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2007 by Michael Sevakis | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | |||
24 | .global mpeg2_idct_copy | ||
25 | .type mpeg2_idct_copy, %function | ||
26 | .global mpeg2_idct_add | ||
27 | .type mpeg2_idct_add, %function | ||
28 | |||
29 | |||
30 | /* Custom calling convention: | ||
31 | * r0 contains block pointer and is non-volatile | ||
32 | * all non-volatile c context saved and restored on its behalf | ||
33 | */ | ||
34 | .idct: | ||
35 | add r12, r0, #128 | ||
36 | 1: | ||
37 | ldrsh r1, [r0, #0] /* d0 */ | ||
38 | ldrsh r2, [r0, #2] /* d1 */ | ||
39 | ldrsh r3, [r0, #4] /* d2 */ | ||
40 | ldrsh r4, [r0, #6] /* d3 */ | ||
41 | ldrsh r5, [r0, #8] /* d0 */ | ||
42 | ldrsh r6, [r0, #10] /* d1 */ | ||
43 | ldrsh r7, [r0, #12] /* d2 */ | ||
44 | ldrsh r8, [r0, #14] /* d3 */ | ||
45 | orrs r9, r2, r3 | ||
46 | orreqs r9, r4, r5 | ||
47 | orreqs r9, r6, r7 | ||
48 | cmpeq r8, #0 | ||
49 | bne 2f | ||
50 | mov r1, r1, asl #15 | ||
51 | bic r1, r1, #0x8000 | ||
52 | orr r1, r1, r1, lsr #16 | ||
53 | str r1, [r0], #4 | ||
54 | str r1, [r0], #4 | ||
55 | str r1, [r0], #4 | ||
56 | str r1, [r0], #4 | ||
57 | cmp r0, r12 | ||
58 | blo 1b | ||
59 | b 3f | ||
60 | 2: | ||
61 | mov r1, r1, asl #11 /* r1 = d0 = (block[0] << 11) + 2048 */ | ||
62 | add r1, r1, #2048 | ||
63 | add r1, r1, r3, asl #11 /* r1 = t0 = d0 + (block[2] << 11) */ | ||
64 | sub r3, r1, r3, asl #12 /* r3 = t1 = d0 - (block[2] << 11) */ | ||
65 | |||
66 | add r9, r2, r4 /* r9 = tmp = (d1+d3)*(1108/4) */ | ||
67 | add r10, r9, r9, asl #2 | ||
68 | add r10, r10, r9, asl #4 | ||
69 | add r9, r10, r9, asl #8 | ||
70 | |||
71 | add r10, r2, r2, asl #4 /* r2 = t2 = tmp + (d1*(1568/32)*8) */ | ||
72 | add r2, r10, r2, asl #5 | ||
73 | add r2, r9, r2, asl #3 | ||
74 | |||
75 | add r10, r4, r4, asl #2 /* r4 = t3 = tmp - (d3*(3784/8)*2) */ | ||
76 | rsb r10, r10, r4, asl #6 | ||
77 | add r4, r4, r10, asl #3 | ||
78 | sub r4, r9, r4, asl #1 | ||
79 | /* t2 & t3 are 1/4 final value here */ | ||
80 | add r1, r1, r2, asl #2 /* r1 = a0 = t0 + t2 */ | ||
81 | sub r2, r1, r2, asl #3 /* r2 = a3 = t0 - t2 */ | ||
82 | add r3, r3, r4, asl #2 /* r3 = a1 = t1 + t3 */ | ||
83 | sub r4, r3, r4, asl #3 /* r4 = a2 = t1 - t3 */ | ||
84 | |||
85 | add r9, r8, r5 /* r9 = tmp = 565*(d3 + d0) */ | ||
86 | add r10, r9, r9, asl #4 | ||
87 | add r10, r10, r10, asl #5 | ||
88 | add r9, r10, r9, asl #2 | ||
89 | |||
90 | add r10, r5, r5, asl #4 /* r5 = t0 = tmp + (((2276/4)*d0)*4) */ | ||
91 | add r10, r10, r10, asl #5 | ||
92 | add r5, r10, r5, asl #3 | ||
93 | add r5, r9, r5, asl #2 | ||
94 | |||
95 | add r10, r8, r8, asl #2 /* r8 = t1 = tmp - (((3406/2)*d3)*2) */ | ||
96 | add r10, r10, r10, asl #4 | ||
97 | add r10, r10, r8, asl #7 | ||
98 | rsb r8, r8, r10, asl #3 | ||
99 | sub r8, r9, r8, asl #1 | ||
100 | |||
101 | add r9, r6, r7 /* r9 = tmp = (2408/8)*(d1 + d2) */ | ||
102 | add r10, r9, r9, asl #3 | ||
103 | add r10, r10, r10, asl #5 | ||
104 | add r9, r10, r9, asl #2 | ||
105 | |||
106 | add r10, r7, r7, asl #3 /* r7 = t2 = (tmp*8) - 799*d2 */ | ||
107 | add r10, r10, r7, asl #4 | ||
108 | rsb r7, r7, r10, asl #5 | ||
109 | rsb r7, r7, r9, asl #3 | ||
110 | |||
111 | sub r10, r6, r6, asl #4 /* r6 = t3 = (tmp*8) - 4017*d1 */ | ||
112 | sub r10, r10, r6, asl #6 | ||
113 | add r10, r10, r6, asl #12 | ||
114 | add r6, r10, r6 | ||
115 | rsb r6, r6, r9, asl #3 | ||
116 | /* t0 = r5, t1 = r8, t2 = r7, t3 = r6*/ | ||
117 | add r9, r5, r7 /* r9 = b0 = t0 + t2 */ | ||
118 | add r10, r8, r6 /* r10 = b3 = t1 + t3 */ | ||
119 | sub r5, r5, r7 /* t0 -= t2 */ | ||
120 | sub r8, r8, r6 /* t1 -= t3 */ | ||
121 | add r6, r5, r8 /* r6 = t0 + t1 */ | ||
122 | sub r7, r5, r8 /* r7 = t0 - t1 */ | ||
123 | |||
124 | add r11, r6, r6, asr #2 /* r6 = b1 = r6*(181/128) */ | ||
125 | add r11, r11, r11, asr #5 | ||
126 | add r6, r11, r6, asr #3 | ||
127 | add r11, r7, r7, asr #2 /* r7 = b2 = r7*(181/128) */ | ||
128 | add r11, r11, r11, asr #5 | ||
129 | add r7, r11, r7, asr #3 | ||
130 | /* r1 = a0, r3 = a1, r4 = a2, r2 = a3 */ | ||
131 | /* r9 = b0, r6 = b1*2, r7 = b2*2, r10 = b3 */ | ||
132 | add r5, r1, r9 /* block[0] = (a0 + b0) >> 12 */ | ||
133 | mov r5, r5, asr #12 | ||
134 | strh r5, [r0], #2 | ||
135 | add r8, r3, r6, asr #1 /* block[1] = (a1 + b1) >> 12 */ | ||
136 | mov r8, r8, asr #12 | ||
137 | strh r8, [r0], #2 | ||
138 | add r5, r4, r7, asr #1 /* block[2] = (a2 + b2) >> 12 */ | ||
139 | mov r5, r5, asr #12 | ||
140 | strh r5, [r0], #2 | ||
141 | add r8, r2, r10 /* block[3] = (a3 + b3) >> 12 */ | ||
142 | mov r8, r8, asr #12 | ||
143 | strh r8, [r0], #2 | ||
144 | sub r5, r2, r10 /* block[4] = (a3 - b3) >> 12 */ | ||
145 | mov r5, r5, asr #12 | ||
146 | strh r5, [r0], #2 | ||
147 | sub r8, r4, r7, asr #1 /* block[5] = (a2 - b2) >> 12 */ | ||
148 | mov r8, r8, asr #12 | ||
149 | strh r8, [r0], #2 | ||
150 | sub r5, r3, r6, asr #1 /* block[6] = (a1 - b1) >> 12 */ | ||
151 | mov r5, r5, asr #12 | ||
152 | strh r5, [r0], #2 | ||
153 | sub r8, r1, r9 /* block[7] = (a0 - b0) >> 12 */ | ||
154 | mov r8, r8, asr #12 | ||
155 | strh r8, [r0], #2 | ||
156 | cmp r0, r12 | ||
157 | blo 1b | ||
158 | 3: | ||
159 | sub r0, r0, #128 | ||
160 | add r12, r0, #16 | ||
161 | 4: | ||
162 | ldrsh r1, [r0, #0*8] /* d0 */ | ||
163 | ldrsh r2, [r0, #2*8] /* d1 */ | ||
164 | ldrsh r3, [r0, #4*8] /* d2 */ | ||
165 | ldrsh r4, [r0, #6*8] /* d3 */ | ||
166 | ldrsh r5, [r0, #8*8] /* d0 */ | ||
167 | ldrsh r6, [r0, #10*8] /* d1 */ | ||
168 | ldrsh r7, [r0, #12*8] /* d2 */ | ||
169 | ldrsh r8, [r0, #14*8] /* d3 */ | ||
170 | |||
171 | mov r1, r1, asl #11 /* r1 = d0 = (block[0] << 11) + 2048 */ | ||
172 | add r1, r1, #65536 | ||
173 | add r1, r1, r3, asl #11 /* r1 = t0 = d0 + d2:(block[2] << 11) */ | ||
174 | sub r3, r1, r3, asl #12 /* r3 = t1 = d0 - d2:(block[2] << 11) */ | ||
175 | |||
176 | add r9, r2, r4 /* r9 = tmp = (d1+d3)*(1108/4) */ | ||
177 | add r10, r9, r9, asl #2 | ||
178 | add r10, r10, r9, asl #4 | ||
179 | add r9, r10, r9, asl #8 | ||
180 | |||
181 | add r11, r2, r2, asl #4 /* r2 = t2 = tmp + (d1*(1568/32)*8) */ | ||
182 | add r2, r11, r2, asl #5 | ||
183 | add r2, r9, r2, asl #3 | ||
184 | |||
185 | add r10, r4, r4, asl #2 /* r4 = t3 = tmp - (d3*(3784/8)*2) */ | ||
186 | rsb r10, r10, r4, asl #6 | ||
187 | add r4, r4, r10, asl #3 | ||
188 | sub r4, r9, r4, asl #1 | ||
189 | /* t2 & t3 are 1/4 final value here */ | ||
190 | add r1, r1, r2, asl #2 /* r1 = a0 = t0 + t2 */ | ||
191 | sub r2, r1, r2, asl #3 /* r2 = a3 = t0 - t2 */ | ||
192 | add r3, r3, r4, asl #2 /* r3 = a1 = t1 + t3 */ | ||
193 | sub r4, r3, r4, asl #3 /* r4 = a2 = t1 - t3 */ | ||
194 | |||
195 | add r9, r8, r5 /* r9 = tmp = 565*(d3 + d0) */ | ||
196 | add r10, r9, r9, asl #4 | ||
197 | add r10, r10, r10, asl #5 | ||
198 | add r9, r10, r9, asl #2 | ||
199 | |||
200 | add r10, r5, r5, asl #4 /* r5 = t0 = tmp + (((2276/4)*d0)*4) */ | ||
201 | add r10, r10, r10, asl #5 | ||
202 | add r5, r10, r5, asl #3 | ||
203 | add r5, r9, r5, asl #2 | ||
204 | |||
205 | add r10, r8, r8, asl #2 /* r8 = t1 = tmp - (((3406/2)*d3)*2) */ | ||
206 | add r10, r10, r10, asl #4 | ||
207 | add r10, r10, r8, asl #7 | ||
208 | rsb r8, r8, r10, asl #3 | ||
209 | sub r8, r9, r8, asl #1 | ||
210 | |||
211 | add r9, r6, r7 /* r9 = tmp = (2408/8)*(d1 + d2) */ | ||
212 | add r10, r9, r9, asl #3 | ||
213 | add r10, r10, r10, asl #5 | ||
214 | add r9, r10, r9, asl #2 | ||
215 | |||
216 | add r10, r7, r7, asl #3 /* r7 = t2 = (tmp*8) - 799*d2 */ | ||
217 | add r10, r10, r7, asl #4 | ||
218 | rsb r7, r7, r10, asl #5 | ||
219 | rsb r7, r7, r9, asl #3 | ||
220 | |||
221 | sub r10, r6, r6, asl #4 /* r6 = t3 = (tmp*8) - 4017*d1 */ | ||
222 | sub r10, r10, r6, asl #6 | ||
223 | add r10, r10, r6, asl #12 | ||
224 | add r6, r10, r6 | ||
225 | rsb r6, r6, r9, asl #3 | ||
226 | /* t0=r5, t1=r8, t2=r7, t3=r6*/ | ||
227 | add r9, r5, r7 /* r9 = b0 = t0 + t2 */ | ||
228 | add r10, r8, r6 /* r10 = b3 = t1 + t3 */ | ||
229 | sub r5, r5, r7 /* t0 -= t2 */ | ||
230 | sub r8, r8, r6 /* t1 -= t3 */ | ||
231 | add r6, r5, r8 /* r6 = t0 + t1 */ | ||
232 | sub r7, r5, r8 /* r7 = t0 - t1 */ | ||
233 | |||
234 | add r11, r6, r6, asr #2 /* r6 = b1 = r5*(181/128) */ | ||
235 | add r11, r11, r11, asr #5 | ||
236 | add r6, r11, r6, asr #3 | ||
237 | add r11, r7, r7, asr #2 /* r7 = b2 = r6*(181/128) */ | ||
238 | add r11, r11, r11, asr #5 | ||
239 | add r7, r11, r7, asr #3 | ||
240 | /* r1 = a0, r3 = a1, r4 = a2, r2 = a3 */ | ||
241 | /* r9 = b0, r6 = b1*2, r7 = b2*2, r10 = b3 */ | ||
242 | add r5, r1, r9 /* block[0] = (a0 + b0) >> 17 */ | ||
243 | mov r5, r5, asr #17 | ||
244 | strh r5, [r0, #0*8] | ||
245 | add r8, r3, r6, asr #1 /* block[1] = (a1 + b1) >> 17 */ | ||
246 | mov r8, r8, asr #17 | ||
247 | strh r8, [r0, #2*8] | ||
248 | add r5, r4, r7, asr #1 /* block[2] = (a2 + b2) >> 17 */ | ||
249 | mov r5, r5, asr #17 | ||
250 | strh r5, [r0, #4*8] | ||
251 | add r8, r2, r10 /* block[3] = (a3 + b3) >> 17 */ | ||
252 | mov r8, r8, asr #17 | ||
253 | strh r8, [r0, #6*8] | ||
254 | sub r5, r2, r10 /* block[4] = (a3 - b3) >> 17 */ | ||
255 | mov r5, r5, asr #17 | ||
256 | strh r5, [r0, #8*8] | ||
257 | sub r8, r4, r7, asr #1 /* block[5] = (a2 - b2) >> 17 */ | ||
258 | mov r8, r8, asr #17 | ||
259 | strh r8, [r0, #10*8] | ||
260 | sub r5, r3, r6, asr #1 /* block[6] = (a1 - b1) >> 17 */ | ||
261 | mov r5, r5, asr #17 | ||
262 | strh r5, [r0, #12*8] | ||
263 | sub r8, r1, r9 /* block[7] = (a0 - b0) >> 17 */ | ||
264 | mov r8, r8, asr #17 | ||
265 | strh r8, [r0, #14*8] | ||
266 | add r0, r0, #2 | ||
267 | cmp r0, r12 | ||
268 | blo 4b | ||
269 | sub r0, r0, #16 | ||
270 | bx lr | ||
271 | |||
272 | mpeg2_idct_copy: | ||
273 | stmfd sp!, { r1-r2, r4-r11, lr } | ||
274 | bl .idct | ||
275 | ldmfd sp!, { r1-r2 } | ||
276 | mov r11, #0 | ||
277 | add r12, r0, #128 | ||
278 | 1: | ||
279 | ldrsh r3, [r0, #0] | ||
280 | ldrsh r4, [r0, #2] | ||
281 | ldrsh r5, [r0, #4] | ||
282 | ldrsh r6, [r0, #6] | ||
283 | ldrsh r7, [r0, #8] | ||
284 | ldrsh r8, [r0, #10] | ||
285 | ldrsh r9, [r0, #12] | ||
286 | ldrsh r10, [r0, #14] | ||
287 | cmp r3, #255 | ||
288 | mvnhi r3, r3, asr #31 | ||
289 | strb r3, [r1, #0] | ||
290 | str r11, [r0], #4 | ||
291 | cmp r4, #255 | ||
292 | mvnhi r4, r4, asr #31 | ||
293 | strb r4, [r1, #1] | ||
294 | cmp r5, #255 | ||
295 | mvnhi r5, r5, asr #31 | ||
296 | strb r5, [r1, #2] | ||
297 | str r11, [r0], #4 | ||
298 | cmp r6, #255 | ||
299 | mvnhi r6, r6, asr #31 | ||
300 | strb r6, [r1, #3] | ||
301 | cmp r7, #255 | ||
302 | mvnhi r7, r7, asr #31 | ||
303 | strb r7, [r1, #4] | ||
304 | str r11, [r0], #4 | ||
305 | cmp r8, #255 | ||
306 | mvnhi r8, r8, asr #31 | ||
307 | strb r8, [r1, #5] | ||
308 | cmp r9, #255 | ||
309 | mvnhi r9, r9, asr #31 | ||
310 | strb r9, [r1, #6] | ||
311 | str r11, [r0], #4 | ||
312 | cmp r10, #255 | ||
313 | mvnhi r10, r10, asr #31 | ||
314 | strb r10, [r1, #7] | ||
315 | add r1, r1, r2 | ||
316 | cmp r0, r12 | ||
317 | blo 1b | ||
318 | ldmpc regs=r4-r11 | ||
319 | |||
320 | mpeg2_idct_add: | ||
321 | cmp r0, #129 | ||
322 | mov r0, r1 | ||
323 | ldreqsh r1, [r0, #0] | ||
324 | bne 1f | ||
325 | and r1, r1, #0x70 | ||
326 | cmp r1, #0x40 | ||
327 | bne 3f | ||
328 | 1: | ||
329 | stmfd sp!, { r2-r11, lr } | ||
330 | bl .idct | ||
331 | ldmfd sp!, { r1-r2 } | ||
332 | mov r11, #0 | ||
333 | add r12, r0, #128 | ||
334 | 2: | ||
335 | ldrb r3, [r1, #0] | ||
336 | ldrb r4, [r1, #1] | ||
337 | ldrb r5, [r1, #2] | ||
338 | ldrb r6, [r1, #3] | ||
339 | ldrsh r7, [r0, #0] | ||
340 | ldrsh r8, [r0, #2] | ||
341 | ldrsh r9, [r0, #4] | ||
342 | ldrsh r10, [r0, #6] | ||
343 | add r7, r7, r3 | ||
344 | ldrb r3, [r1, #4] | ||
345 | cmp r7, #255 | ||
346 | mvnhi r7, r7, asr #31 | ||
347 | strb r7, [r1, #0] | ||
348 | ldrsh r7, [r0, #8] | ||
349 | add r8, r8, r4 | ||
350 | ldrb r4, [r1, #5] | ||
351 | cmp r8, #255 | ||
352 | mvnhi r8, r8, asr #31 | ||
353 | strb r8, [r1, #1] | ||
354 | ldrsh r8, [r0, #10] | ||
355 | add r9, r9, r5 | ||
356 | ldrb r5, [r1, #6] | ||
357 | cmp r9, #255 | ||
358 | mvnhi r9, r9, asr #31 | ||
359 | strb r9, [r1, #2] | ||
360 | ldrsh r9, [r0, #12] | ||
361 | add r10, r10, r6 | ||
362 | ldrb r6, [r1, #7] | ||
363 | cmp r10, #255 | ||
364 | mvnhi r10, r10, asr #31 | ||
365 | strb r10, [r1, #3] | ||
366 | ldrsh r10, [r0, #14] | ||
367 | str r11, [r0], #4 | ||
368 | add r7, r7, r3 | ||
369 | cmp r7, #255 | ||
370 | mvnhi r7, r7, asr #31 | ||
371 | strb r7, [r1, #4] | ||
372 | str r11, [r0], #4 | ||
373 | add r8, r8, r4 | ||
374 | cmp r8, #255 | ||
375 | mvnhi r8, r8, asr #31 | ||
376 | strb r8, [r1, #5] | ||
377 | str r11, [r0], #4 | ||
378 | add r9, r9, r5 | ||
379 | cmp r9, #255 | ||
380 | mvnhi r9, r9, asr #31 | ||
381 | strb r9, [r1, #6] | ||
382 | add r10, r10, r6 | ||
383 | cmp r10, #255 | ||
384 | mvnhi r10, r10, asr #31 | ||
385 | strb r10, [r1, #7] | ||
386 | str r11, [r0], #4 | ||
387 | add r1, r1, r2 | ||
388 | cmp r0, r12 | ||
389 | blo 2b | ||
390 | ldmpc regs=r4-r11 | ||
391 | 3: | ||
392 | stmfd sp!, { r4-r5, lr } | ||
393 | ldrsh r1, [r0, #0] /* r1 = block[0] */ | ||
394 | mov r4, #0 | ||
395 | strh r4, [r0, #0] /* block[0] = 0 */ | ||
396 | strh r4, [r0, #126] /* block[63] = 0 */ | ||
397 | add r1, r1, #64 /* r1 = DC << 7 */ | ||
398 | add r0, r2, r3, asl #3 | ||
399 | 4: | ||
400 | ldrb r4, [r2, #0] | ||
401 | ldrb r5, [r2, #1] | ||
402 | ldrb r12, [r2, #2] | ||
403 | ldrb lr, [r2, #3] | ||
404 | add r4, r4, r1, asr #7 | ||
405 | cmp r4, #255 | ||
406 | mvnhi r4, r4, asr #31 | ||
407 | strb r4, [r2, #0] | ||
408 | add r5, r5, r1, asr #7 | ||
409 | cmp r5, #255 | ||
410 | mvnhi r5, r5, asr #31 | ||
411 | strb r5, [r2, #1] | ||
412 | add r12, r12, r1, asr #7 | ||
413 | cmp r12, #255 | ||
414 | mvnhi r12, r12, asr #31 | ||
415 | strb r12, [r2, #2] | ||
416 | add lr, lr, r1, asr #7 | ||
417 | cmp lr, #255 | ||
418 | mvnhi lr, lr, asr #31 | ||
419 | strb lr, [r2, #3] | ||
420 | ldrb r4, [r2, #4] | ||
421 | ldrb r5, [r2, #5] | ||
422 | ldrb r12, [r2, #6] | ||
423 | ldrb lr, [r2, #7] | ||
424 | add r4, r4, r1, asr #7 | ||
425 | cmp r4, #255 | ||
426 | mvnhi r4, r4, asr #31 | ||
427 | strb r4, [r2, #4] | ||
428 | add r5, r5, r1, asr #7 | ||
429 | cmp r5, #255 | ||
430 | mvnhi r5, r5, asr #31 | ||
431 | strb r5, [r2, #5] | ||
432 | add r12, r12, r1, asr #7 | ||
433 | cmp r12, #255 | ||
434 | mvnhi r12, r12, asr #31 | ||
435 | strb r12, [r2, #6] | ||
436 | add lr, lr, r1, asr #7 | ||
437 | cmp lr, #255 | ||
438 | mvnhi lr, lr, asr #31 | ||
439 | strb lr, [r2, #7] | ||
440 | add r2, r2, r3 | ||
441 | cmp r2, r0 | ||
442 | blo 4b | ||
443 | ldmpc regs=r4-r5 | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/idct_armv6.S b/apps/plugins/mpegplayer/libmpeg2/idct_armv6.S new file mode 100644 index 0000000000..dc53cbd7bd --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/idct_armv6.S | |||
@@ -0,0 +1,297 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2009 by Jens Arnold | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | |||
23 | .global mpeg2_idct_copy | ||
24 | .type mpeg2_idct_copy, %function | ||
25 | .global mpeg2_idct_add | ||
26 | .type mpeg2_idct_add, %function | ||
27 | |||
28 | /* Custom calling convention: | ||
29 | * r0 contains block pointer and is non-volatile | ||
30 | * all non-volatile c context saved and restored on its behalf | ||
31 | */ | ||
32 | .idct: | ||
33 | str lr, [sp, #-4]! @ lr is used | ||
34 | add r1, r0, #128 @ secondary, transposed temp buffer | ||
35 | mov r14, #8 @ loop counter | ||
36 | |||
37 | .row_loop: | ||
38 | ldmia r0!, {r2, r3, r10, r11} @ fetch f0, f2, f4, f6, f1, f3, f5, f7 | ||
39 | ldrd r4, L_W1357 @ load W1, W3, W5, W7 | ||
40 | |||
41 | smuad r6, r4, r10 @ b0 = W1 * f1 + W3 * f3 | ||
42 | smultt r7, r5, r10 @ -b1 = W7 * f3 | ||
43 | smulbt r8, r4, r10 @ -b2 = W1 * f3 | ||
44 | |||
45 | smusdx r9, r10, r5 @ b3 = f1 * W7 - f3 * W5 | ||
46 | smlabb r7, r4, r11, r7 @ -b1 += W1 * f5 | ||
47 | rsb r8, r8, #0 @ b2 = -b2 | ||
48 | smlabb r8, r5, r10, r8 @ b2 += W5 * f1 | ||
49 | |||
50 | smlad r6, r5, r11, r6 @ b0 += W5 * f5 + W7 * f7 | ||
51 | smlabt r7, r5, r11, r7 @ -b1 += W5 * f7 | ||
52 | smlatb r8, r5, r11, r8 @ b2 += W7 * f5 | ||
53 | |||
54 | smlsdx r9, r11, r4, r9 @ b3 += f5 * W3 - f7 * W1 | ||
55 | rsb r7, r7, #0 @ b1 = -b1 | ||
56 | smlatb r7, r4, r10, r7 @ b1 += W3 * f1 | ||
57 | smlatt r8, r4, r11, r8 @ b2 += W3 * f7 | ||
58 | |||
59 | ldrd r4, L_W0246 @ load W0, W2, W4, W6 | ||
60 | add r2, r2, #1 @ f0 += 1 | ||
61 | |||
62 | smulbb r10, r5, r3 @ a0' = W4 * f4 | ||
63 | smultt r12, r5, r3 @ a3' = W6 * f6 | ||
64 | smultt r3, r4, r3 @ -a2' = W2 * f6 | ||
65 | |||
66 | rsb r11, r10, #0 @ a1' = -W4 * f4 | ||
67 | smlabb r10, r4, r2, r10 @ a0' += W0 * f0 | ||
68 | smlabb r11, r4, r2, r11 @ a1' += W0 * f0 | ||
69 | smlatt r12, r4, r2, r12 @ a3' += W2 * f2 | ||
70 | rsb r3, r3, #0 @ a2' = -a2' | ||
71 | smlatt r3, r5, r2, r3 @ a2' += W6 * f2 | ||
72 | |||
73 | add r10, r10, r12 @ a0 = a0' + a3' | ||
74 | sub r12, r10, r12, lsl #1 @ a3 = a0 - 2 * a3' | ||
75 | add r11, r11, r3 @ a1 = a1' + a2' | ||
76 | sub r3, r11, r3, lsl #1 @ a2 = a1 - 2 * a2' | ||
77 | |||
78 | subs r14, r14, #1 @ decrease loop count | ||
79 | |||
80 | @ Special store order for making the column pass calculate columns in | ||
81 | @ the order 0-2-1-3-4-6-5-7, allowing for uxtab16 use in later stages. | ||
82 | sub r2, r10, r6 @ block[7] = (a0 - b0) | ||
83 | mov r2, r2, asr #12 @ >> 12 | ||
84 | strh r2, [r1, #7*16] | ||
85 | sub r2, r11, r7 @ block[6] = (a1 - b1) | ||
86 | mov r2, r2, asr #12 @ >> 12 | ||
87 | strh r2, [r1, #5*16] | ||
88 | sub r2, r3, r8 @ block[5] = (a2 - b2) | ||
89 | mov r2, r2, asr #12 @ >> 12 | ||
90 | strh r2, [r1, #6*16] | ||
91 | sub r2, r12, r9 @ block[4] = (a3 - b3) | ||
92 | mov r2, r2, asr #12 @ >> 12 | ||
93 | strh r2, [r1, #4*16] | ||
94 | add r2, r12, r9 @ block[3] = (a3 + b3) | ||
95 | mov r2, r2, asr #12 @ >> 12 | ||
96 | strh r2, [r1, #3*16] | ||
97 | add r2, r3, r8 @ block[2] = (a2 + b2) | ||
98 | mov r2, r2, asr #12 @ >> 12 | ||
99 | strh r2, [r1, #1*16] | ||
100 | add r2, r11, r7 @ block[1] = (a1 + b1) | ||
101 | mov r2, r2, asr #12 @ >> 12 | ||
102 | strh r2, [r1, #2*16] | ||
103 | add r2, r10, r6 @ block[0] = (a0 + b0) | ||
104 | mov r2, r2, asr #12 @ >> 12 | ||
105 | strh r2, [r1], #2 @ advance to next temp column | ||
106 | |||
107 | bne .row_loop | ||
108 | b .col_start | ||
109 | |||
110 | @placed here because of ldrd's offset limit | ||
111 | L_W1357: | ||
112 | .short 2841 | ||
113 | .short 2408 | ||
114 | .short 1609 | ||
115 | .short 565 | ||
116 | |||
117 | L_W0246: | ||
118 | .short 2048 | ||
119 | .short 2676 | ||
120 | .short 2048 | ||
121 | .short 1108 | ||
122 | |||
123 | .col_start: | ||
124 | @ r0 now points to the temp buffer, where we need it. | ||
125 | sub r1, r1, #128+16 @ point r1 back to the input block | ||
126 | mov r14, #8 @ loop counter | ||
127 | |||
128 | .col_loop: | ||
129 | ldmia r0!, {r2, r3, r10, r11} @ fetch f0, f2, f4, f6, f1, f3, f5, f7 | ||
130 | ldrd r4, L_W1357 @ load W1, W3, W5, W7 | ||
131 | |||
132 | smuad r6, r4, r10 @ b0 = W1 * f1 + W3 * f3 | ||
133 | smultt r7, r5, r10 @ -b1 = W7 * f3 | ||
134 | smulbt r8, r4, r10 @ -b2 = W1 * f3 | ||
135 | |||
136 | smusdx r9, r10, r5 @ b3 = f1 * W7 - f3 * W5 | ||
137 | smlabb r7, r4, r11, r7 @ -b1 += W1 * f5 | ||
138 | rsb r8, r8, #0 @ b2 = -b2 | ||
139 | smlabb r8, r5, r10, r8 @ b2 += W5 * f1 | ||
140 | |||
141 | smlad r6, r5, r11, r6 @ b0 += W5 * f5 + W7 * f7 | ||
142 | smlabt r7, r5, r11, r7 @ -b1 += W5 * f7 | ||
143 | smlatb r8, r5, r11, r8 @ b2 += W7 * f5 | ||
144 | |||
145 | smlsdx r9, r11, r4, r9 @ b3 += f5 * W3 - f7 * W1 | ||
146 | rsb r7, r7, #0 @ b1 = -b1 | ||
147 | smlatb r7, r4, r10, r7 @ b1 += W3 * f1 | ||
148 | smlatt r8, r4, r11, r8 @ b2 += W3 * f7 | ||
149 | |||
150 | ldrd r4, L_W0246 @ load W0, W2, W4, W6 | ||
151 | add r2, r2, #32 @ DC offset: 0.5 | ||
152 | |||
153 | smulbb r10, r5, r3 @ a0' = W4 * f4 | ||
154 | smultt r12, r5, r3 @ a3' = W6 * f6 | ||
155 | smultt r3, r4, r3 @ -a2' = W2 * f6 | ||
156 | |||
157 | rsb r11, r10, #0 @ a1' = -W4 * f4 | ||
158 | smlabb r10, r4, r2, r10 @ a0' += W0 * f0 | ||
159 | smlabb r11, r4, r2, r11 @ a1' += W0 * f0 | ||
160 | smlatt r12, r4, r2, r12 @ a3' += W2 * f2 | ||
161 | rsb r3, r3, #0 @ a2' = -a2' | ||
162 | smlatt r3, r5, r2, r3 @ a2' += W6 * f2 | ||
163 | |||
164 | add r10, r10, r12 @ a0 = a0' + a3' | ||
165 | sub r12, r10, r12, lsl #1 @ a3 = a0 - 2 * a3' | ||
166 | add r11, r11, r3 @ a1 = a1' + a2' | ||
167 | sub r3, r11, r3, lsl #1 @ a2 = a1 - 2 * a2' | ||
168 | |||
169 | subs r14, r14, #1 @ decrease loop count | ||
170 | |||
171 | sub r2, r10, r6 @ block[7] = (a0 - b0) | ||
172 | mov r2, r2, asr #17 @ >> 17 | ||
173 | strh r2, [r1, #7*16] | ||
174 | sub r2, r11, r7 @ block[6] = (a1 - b1) | ||
175 | mov r2, r2, asr #17 @ >> 17 | ||
176 | strh r2, [r1, #6*16] | ||
177 | sub r2, r3, r8 @ block[5] = (a2 - b2) | ||
178 | mov r2, r2, asr #17 @ >> 17 | ||
179 | strh r2, [r1, #5*16] | ||
180 | sub r2, r12, r9 @ block[4] = (a3 - b3) | ||
181 | mov r2, r2, asr #17 @ >> 17 | ||
182 | strh r2, [r1, #4*16] | ||
183 | add r2, r12, r9 @ block[3] = (a3 + b3) | ||
184 | mov r2, r2, asr #17 @ >> 17 | ||
185 | strh r2, [r1, #3*16] | ||
186 | add r2, r3, r8 @ block[2] = (a2 + b2) | ||
187 | mov r2, r2, asr #17 @ >> 17 | ||
188 | strh r2, [r1, #2*16] | ||
189 | add r2, r11, r7 @ block[1] = (a1 + b1) | ||
190 | mov r2, r2, asr #17 @ >> 17 | ||
191 | strh r2, [r1, #1*16] | ||
192 | add r2, r10, r6 @ block[0] = (a0 + b0) | ||
193 | mov r2, r2, asr #17 @ >> 17 | ||
194 | strh r2, [r1], #2 @ advance to next column | ||
195 | |||
196 | bne .col_loop | ||
197 | |||
198 | sub r0, r0, #256 @ point r0 back to the input block | ||
199 | ldr pc, [sp], #4 | ||
200 | |||
201 | |||
202 | mpeg2_idct_copy: | ||
203 | stmfd sp!, {r1-r2, r4-r11, lr} | ||
204 | bl .idct | ||
205 | ldmfd sp!, {r1-r2} | ||
206 | |||
207 | add r3, r0, #128 | ||
208 | mov r8, #0 | ||
209 | mov r9, #0 | ||
210 | mov r10, #0 | ||
211 | mov r11, #0 | ||
212 | 1: @ idct data is in order 0-2-1-3-4-6-5-7, | ||
213 | ldmia r0, {r4-r7} @ see above | ||
214 | stmia r0!, {r8-r11} | ||
215 | usat16 r4, #8, r4 | ||
216 | usat16 r5, #8, r5 | ||
217 | orr r4, r4, r5, lsl #8 | ||
218 | usat16 r6, #8, r6 | ||
219 | usat16 r7, #8, r7 | ||
220 | orr r5, r6, r7, lsl #8 | ||
221 | strd r4, [r1] @ r4, r5 | ||
222 | add r1, r1, r2 | ||
223 | cmp r0, r3 | ||
224 | blo 1b | ||
225 | |||
226 | ldmfd sp!, {r4-r11, pc} | ||
227 | |||
228 | mpeg2_idct_add: | ||
229 | cmp r0, #129 | ||
230 | mov r0, r1 | ||
231 | ldreqsh r1, [r0, #0] | ||
232 | bne 1f | ||
233 | and r1, r1, #0x70 | ||
234 | cmp r1, #0x40 | ||
235 | bne 3f | ||
236 | 1: | ||
237 | stmfd sp!, {r2-r11, lr} | ||
238 | bl .idct | ||
239 | ldmfd sp!, {r1-r2} | ||
240 | |||
241 | add r3, r0, #128 | ||
242 | mov r10, #0 | ||
243 | mov r11, #0 | ||
244 | mov r12, #0 | ||
245 | mov lr, #0 | ||
246 | ldrd r8, [r1] @ r8, r9 | ||
247 | 2: @ idct data is in order 0-2-1-3-4-6-5-7, | ||
248 | ldmia r0, {r4-r7} @ see above | ||
249 | stmia r0!, {r10-r12, lr} | ||
250 | uxtab16 r4, r4, r8 | ||
251 | uxtab16 r5, r5, r8, ror #8 | ||
252 | usat16 r4, #8, r4 | ||
253 | usat16 r5, #8, r5 | ||
254 | orr r4, r4, r5, lsl #8 | ||
255 | uxtab16 r6, r6, r9 | ||
256 | uxtab16 r7, r7, r9, ror #8 | ||
257 | usat16 r6, #8, r6 | ||
258 | usat16 r7, #8, r7 | ||
259 | orr r5, r6, r7, lsl #8 | ||
260 | strd r4, [r1] @ r4, r5 | ||
261 | add r1, r1, r2 | ||
262 | cmp r0, r3 | ||
263 | ldrlod r8, [r1] @ r8, r9 | ||
264 | blo 2b | ||
265 | |||
266 | ldmfd sp!, {r4-r11, pc} | ||
267 | |||
268 | 3: | ||
269 | stmfd sp!, {r4, lr} | ||
270 | ldrsh r4, [r0, #0] @ r4 = block[0] | ||
271 | mov r12, #0 | ||
272 | strh r12, [r0, #0] @ block[0] = 0 | ||
273 | strh r12, [r0, #126] @ block[63] = 0 | ||
274 | add r4, r4, #64 | ||
275 | mov r4, r4, asr #7 @ r4 = DC | ||
276 | mov r4, r4, lsl #16 @ spread to 2 halfwords | ||
277 | orr r4, r4, r4, lsr #16 | ||
278 | ldrd r0, [r2] @ r0, r1 | ||
279 | add r12, r2, r3, asl #3 | ||
280 | 4: | ||
281 | uxtab16 lr, r4, r0, ror #8 | ||
282 | uxtab16 r0, r4, r0 | ||
283 | usat16 lr, #8, lr | ||
284 | usat16 r0, #8, r0 | ||
285 | orr r0, r0, lr, lsl #8 | ||
286 | uxtab16 lr, r4, r1, ror #8 | ||
287 | uxtab16 r1, r4, r1 | ||
288 | usat16 lr, #8, lr | ||
289 | usat16 r1, #8, r1 | ||
290 | orr r1, r1, lr, lsl #8 | ||
291 | strd r0, [r2] @ r0, r1 | ||
292 | add r2, r2, r3 | ||
293 | cmp r2, r12 | ||
294 | ldrlod r0, [r2] @ r0, r1 | ||
295 | blo 4b | ||
296 | |||
297 | ldmfd sp!, {r4, pc} | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/idct_coldfire.S b/apps/plugins/mpegplayer/libmpeg2/idct_coldfire.S new file mode 100644 index 0000000000..abc54b16cb --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/idct_coldfire.S | |||
@@ -0,0 +1,575 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2007 Jens Arnold | ||
11 | * Based on the work of Karim Boucher and Rani Hod | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | |||
23 | .global mpeg2_idct_copy | ||
24 | .type mpeg2_idct_copy, @function | ||
25 | .global mpeg2_idct_add | ||
26 | .type mpeg2_idct_add, @function | ||
27 | |||
28 | /* The IDCT itself. | ||
29 | * Input: %a0: block pointer | ||
30 | * Caller must save all registers. */ | ||
31 | .align 2 | ||
32 | .idct: | ||
33 | move.l %a0, %a6 | ||
34 | |||
35 | move.l #0, %macsr | signed integer mode | ||
36 | |||
37 | move.l #((2048<<16)+2841), %a0 | W0, W1 | ||
38 | move.l #((2676<<16)+2408), %a1 | W2, W3 | ||
39 | move.l #((2048<<16)+1609), %a2 | W4, W5 | ||
40 | move.l #((1108<<16)+ 565), %a3 | W6, W7 | ||
41 | |||
42 | lea.l (128,%a6), %a4 | secondary, transposed temp buffer | ||
43 | moveq.l #8, %d3 | loop counter | ||
44 | |||
45 | .row_loop: | ||
46 | movem.l (%a6), %d0-%d2/%a5 | fetch (f0, f2, f4, f6, f1, f3, f5, f7) | ||
47 | |||
48 | mac.w %a0l, %d2u, %acc0 | %acc0 = W1 * f1 | ||
49 | mac.w %a1l, %d2l, %acc0 | + W3 * f3 | ||
50 | mac.w %a2l, %a5u, %acc0 | + W5 * f5 | ||
51 | mac.w %a3l, %a5l, %acc0 | + W7 * f7 | ||
52 | |||
53 | mac.w %a1l, %d2u, %acc1 | %acc1 = W3 * f1 | ||
54 | msac.w %a3l, %d2l, %acc1 | - W7 * f3 | ||
55 | msac.w %a0l, %a5u, %acc1 | - W1 * f5 | ||
56 | msac.w %a2l, %a5l, %acc1 | - W5 * f7 | ||
57 | |||
58 | mac.w %a2l, %d2u, %acc2 | %acc2 = W5 * f1 | ||
59 | msac.w %a0l, %d2l, %acc2 | - W1 * f3 | ||
60 | mac.w %a3l, %a5u, %acc2 | + W7 * f5 | ||
61 | mac.w %a1l, %a5l, %acc2 | + W3 * f7 | ||
62 | |||
63 | mac.w %a3l, %d2u, %acc3 | %acc3 = W7 * f1 | ||
64 | msac.w %a2l, %d2l, %acc3 | - W5 * f3 | ||
65 | mac.w %a1l, %a5u, %acc3 | + W3 * f5 | ||
66 | msac.w %a0l, %a5l, %acc3 | - W1 * f7 | ||
67 | |||
68 | lea.l (16,%a6), %a6 | Advance to next row; put here to fill EMAC latency | ||
69 | add.l #(1<<16), %d0 | f0 += 1; | ||
70 | |||
71 | movclr.l %acc0, %d4 | b0 | ||
72 | movclr.l %acc1, %d5 | b1 | ||
73 | movclr.l %acc2, %d6 | b2 | ||
74 | movclr.l %acc3, %d7 | b3 | ||
75 | |||
76 | mac.w %a0u, %d0u, %acc0 | %acc0 = W0 * f0 | ||
77 | mac.w %a2u, %d1u, %acc0 | + W4 * f4 | ||
78 | move.l %acc0, %acc3 | ||
79 | mac.w %a1u, %d0l, %acc0 | + W2 * f2 | ||
80 | mac.w %a3u, %d1l, %acc0 | + W6 * f6 | ||
81 | |||
82 | mac.w %a0u, %d0u, %acc1 | %acc1 = W0 * f0 | ||
83 | msac.w %a2u, %d1u, %acc1 | - W4 * f4 | ||
84 | move.l %acc1, %acc2 | ||
85 | mac.w %a3u, %d0l, %acc1 | + W6 * f2 | ||
86 | msac.w %a1u, %d1l, %acc1 | - W2 * f6 | ||
87 | |||
88 | | ^ move.l %acc1, %acc2 %acc2 = W0 * f0 - W4 * f4 | ||
89 | msac.w %a3u, %d0l, %acc2 | - W6 * f2 | ||
90 | mac.w %a1u, %d1l, %acc2 | + W2 * f6 | ||
91 | |||
92 | | ^ move.l %acc0, %acc3 %acc3 = W0 * f0 + W4 * f4 | ||
93 | msac.w %a1u, %d0l, %acc3 | - W2 * f2 | ||
94 | msac.w %a3u, %d1l, %acc3 | - W6 * f6 | ||
95 | |||
96 | moveq.l #12, %d1 | shift amount | ||
97 | |||
98 | move.l %acc0, %d0 | block[7] = (a0 | ||
99 | sub.l %d4,%d0 | - b0) | ||
100 | asr.l %d1, %d0 | >> 12 | ||
101 | move.w %d0, (7*16,%a4) | ||
102 | |||
103 | move.l %acc1, %d0 | block[6] = (a1 | ||
104 | sub.l %d5,%d0 | - b1) | ||
105 | asr.l %d1, %d0 | >> 12 | ||
106 | move.w %d0, (6*16,%a4) | ||
107 | |||
108 | move.l %acc2, %d0 | block[5] = (a2 | ||
109 | sub.l %d6,%d0 | - b2) | ||
110 | asr.l %d1, %d0 | >> 12 | ||
111 | move.w %d0, (5*16,%a4) | ||
112 | |||
113 | move.l %acc3, %d0 | block[4] = (a3 | ||
114 | sub.l %d7,%d0 | - b3) | ||
115 | asr.l %d1, %d0 | >> 12 | ||
116 | move.w %d0, (4*16,%a4) | ||
117 | |||
118 | movclr.l %acc3, %d0 | block[3] = (a3 | ||
119 | add.l %d7, %d0 | + b3) | ||
120 | asr.l %d1, %d0 | >> 12 | ||
121 | move.w %d0, (3*16,%a4) | ||
122 | |||
123 | movclr.l %acc2, %d0 | block[2] = (a2 | ||
124 | add.l %d6, %d0 | + b2) | ||
125 | asr.l %d1, %d0 | >> 12 | ||
126 | move.w %d0, (2*16,%a4) | ||
127 | |||
128 | movclr.l %acc1, %d0 | block[1] = (a1 | ||
129 | add.l %d5, %d0 | + b1) | ||
130 | asr.l %d1, %d0 | >> 12 | ||
131 | move.w %d0, (1*16,%a4) | ||
132 | |||
133 | movclr.l %acc0, %d0 | block[0] = (a0 | ||
134 | add.l %d4, %d0 | + b0) | ||
135 | asr.l %d1, %d0 | >> 12 | ||
136 | move.w %d0, (%a4)+ | advance to next temp column | ||
137 | |||
138 | subq.l #1, %d3 | loop 8 times | ||
139 | bne.w .row_loop | ||
140 | |||
141 | | %a6 now points to the temp buffer, where we need it. | ||
142 | lea.l (-16-128,%a4), %a4 | point %a4 back to the input block | ||
143 | moveq.l #8, %d3 | loop counter | ||
144 | |||
145 | .col_loop: | ||
146 | movem.l (%a6), %d0-%d2/%a5 | fetch (f0, f2, f4, f6, f1, f3, f5, f7) | ||
147 | |||
148 | mac.w %a0l, %d2u, %acc0 | %acc0 = W1 * f1 | ||
149 | mac.w %a1l, %d2l, %acc0 | + W3 * f3 | ||
150 | mac.w %a2l, %a5u, %acc0 | + W5 * f5 | ||
151 | mac.w %a3l, %a5l, %acc0 | + W7 * f7 | ||
152 | |||
153 | mac.w %a1l, %d2u, %acc1 | %acc1 = W3 * f1 | ||
154 | msac.w %a3l, %d2l, %acc1 | - W7 * f3 | ||
155 | msac.w %a0l, %a5u, %acc1 | - W1 * f5 | ||
156 | msac.w %a2l, %a5l, %acc1 | - W5 * f7 | ||
157 | |||
158 | mac.w %a2l, %d2u, %acc2 | %acc2 = W5 * f1 | ||
159 | msac.w %a0l, %d2l, %acc2 | - W1 * f3 | ||
160 | mac.w %a3l, %a5u, %acc2 | + W7 * f5 | ||
161 | mac.w %a1l, %a5l, %acc2 | + W3 * f7 | ||
162 | |||
163 | mac.w %a3l, %d2u, %acc3 | %acc3 = W7 * f1 | ||
164 | msac.w %a2l, %d2l, %acc3 | - W5 * f3 | ||
165 | mac.w %a1l, %a5u, %acc3 | + W3 * f5 | ||
166 | msac.w %a0l, %a5l, %acc3 | - W1 * f7 | ||
167 | |||
168 | lea.l (16,%a6), %a6 | Advance to next row; put here to fill EMAC latency | ||
169 | add.l #(32<<16), %d0 | DC offset: 0.5 | ||
170 | |||
171 | movclr.l %acc0, %d4 | b0 | ||
172 | movclr.l %acc1, %d5 | b1 | ||
173 | movclr.l %acc2, %d6 | b2 | ||
174 | movclr.l %acc3, %d7 | b3 | ||
175 | |||
176 | mac.w %a0u, %d0u, %acc0 | %acc0 = W0 * f0 | ||
177 | mac.w %a2u, %d1u, %acc0 | + W4 * f4 | ||
178 | move.l %acc0, %acc3 | ||
179 | mac.w %a1u, %d0l, %acc0 | + W2 * f2 | ||
180 | mac.w %a3u, %d1l, %acc0 | + W6 * f6 | ||
181 | |||
182 | mac.w %a0u, %d0u, %acc1 | %acc1 = W0 * f0 | ||
183 | msac.w %a2u, %d1u, %acc1 | - W4 * f4 | ||
184 | move.l %acc1, %acc2 | ||
185 | mac.w %a3u, %d0l, %acc1 | + W6 * f2 | ||
186 | msac.w %a1u, %d1l, %acc1 | - W2 * f6 | ||
187 | |||
188 | | ^ move.l %acc1, %acc2 %acc2 = W0 * f0 - W4 * f4 | ||
189 | msac.w %a3u, %d0l, %acc2 | - W6 * f2 | ||
190 | mac.w %a1u, %d1l, %acc2 | + W2 * f6 | ||
191 | |||
192 | | ^ move.l %acc0, %acc3 %acc3 = W0 * f0 + W4 * f4 | ||
193 | msac.w %a1u, %d0l, %acc3 | - W2 * f2 | ||
194 | msac.w %a3u, %d1l, %acc3 | - W6 * f6 | ||
195 | |||
196 | moveq.l #17, %d1 | shift amount | ||
197 | |||
198 | move.l %acc0, %d0 | block[7] = (a0 | ||
199 | sub.l %d4,%d0 | - b0) | ||
200 | asr.l %d1, %d0 | >> 17 | ||
201 | move.w %d0, (7*16,%a4) | ||
202 | |||
203 | move.l %acc1, %d0 | block[6] = (a1 | ||
204 | sub.l %d5,%d0 | - b1) | ||
205 | asr.l %d1, %d0 | >> 17 | ||
206 | move.w %d0, (6*16,%a4) | ||
207 | |||
208 | move.l %acc2, %d0 | block[5] = (a2 | ||
209 | sub.l %d6,%d0 | - b2) | ||
210 | asr.l %d1, %d0 | >> 17 | ||
211 | move.w %d0, (5*16,%a4) | ||
212 | |||
213 | move.l %acc3, %d0 | block[4] = (a3 | ||
214 | sub.l %d7,%d0 | - b3) | ||
215 | asr.l %d1, %d0 | >> 17 | ||
216 | move.w %d0, (4*16,%a4) | ||
217 | |||
218 | movclr.l %acc3, %d0 | block[3] = (a3 | ||
219 | add.l %d7, %d0 | + b3) | ||
220 | asr.l %d1, %d0 | >> 17 | ||
221 | move.w %d0, (3*16,%a4) | ||
222 | |||
223 | movclr.l %acc2, %d0 | block[2] = (a2 | ||
224 | add.l %d6, %d0 | + b2) | ||
225 | asr.l %d1, %d0 | >> 17 | ||
226 | move.w %d0, (2*16,%a4) | ||
227 | |||
228 | movclr.l %acc1, %d0 | block[1] = (a1 | ||
229 | add.l %d5, %d0 | + b1) | ||
230 | asr.l %d1, %d0 | >> 17 | ||
231 | move.w %d0, (1*16,%a4) | ||
232 | |||
233 | movclr.l %acc0, %d0 | block[0] = (a0 | ||
234 | add.l %d4, %d0 | + b0) | ||
235 | asr.l %d1, %d0 | >> 17 | ||
236 | move.w %d0, (%a4)+ | advance to next column | ||
237 | |||
238 | subq.l #1, %d3 | loop 8 times | ||
239 | bne.w .col_loop | ||
240 | |||
241 | rts | ||
242 | |||
243 | .align 2 | ||
244 | |||
245 | mpeg2_idct_copy: | ||
246 | lea.l (-11*4,%sp), %sp | ||
247 | movem.l %d2-%d7/%a2-%a6, (%sp) | save some registers | ||
248 | move.l (11*4+4,%sp), %a0 | %a0 - block pointer for idct | ||
249 | |||
250 | bsr.w .idct | apply idct to block | ||
251 | movem.l (11*4+4,%sp), %a0-%a2 | %a0 - block pointer | ||
252 | | %a1 - destination pointer | ||
253 | | %a2 - stride | ||
254 | |||
255 | move.l #255, %d1 | preload constant for clipping | ||
256 | moveq.l #8, %d4 | loop counter | ||
257 | |||
258 | .copy_clip_loop: | ||
259 | move.w (%a0), %d0 | load block[0] | ||
260 | ext.l %d0 | sign extend | ||
261 | cmp.l %d1, %d0 | overflow? | ||
262 | bls.b 1f | ||
263 | spl.b %d0 | yes: set appropriate limit value in low byte | ||
264 | 1: | ||
265 | move.b %d0, %d2 | collect output bytes 0..3 in %d2 | ||
266 | lsl.l #8, %d2 | ||
267 | |||
268 | move.w (2,%a0), %d0 | load block[1] | ||
269 | ext.l %d0 | sign extend | ||
270 | cmp.l %d1, %d0 | overflow? | ||
271 | bls.b 1f | ||
272 | spl.b %d0 | yes: set appropriate limit value in low byte | ||
273 | 1: | ||
274 | move.b %d0, %d2 | collect output bytes 0..3 in %d2 | ||
275 | lsl.l #8, %d2 | ||
276 | clr.l (%a0)+ | clear block[0] and block[1], | ||
277 | | %a0 now pointing to block[2] | ||
278 | move.w (%a0), %d0 | do b2 and b3 | ||
279 | ext.l %d0 | ||
280 | cmp.l %d1, %d0 | ||
281 | bls.b 1f | ||
282 | spl.b %d0 | ||
283 | 1: | ||
284 | move.b %d0, %d2 | ||
285 | lsl.l #8, %d2 | ||
286 | |||
287 | move.w (2,%a0), %d0 | ||
288 | ext.l %d0 | ||
289 | cmp.l %d1, %d0 | ||
290 | bls.b 1f | ||
291 | spl.b %d0 | ||
292 | 1: | ||
293 | move.b %d0, %d2 | ||
294 | clr.l (%a0)+ | ||
295 | |||
296 | move.w (%a0), %d0 | do b4 and b5 | ||
297 | ext.l %d0 | ||
298 | cmp.l %d1, %d0 | ||
299 | bls.b 1f | ||
300 | spl.b %d0 | ||
301 | 1: | ||
302 | move.b %d0, %d3 | ||
303 | lsl.l #8, %d3 | ||
304 | |||
305 | move.w (2,%a0), %d0 | ||
306 | ext.l %d0 | ||
307 | cmp.l %d1, %d0 | ||
308 | bls.b 1f | ||
309 | spl.b %d0 | ||
310 | 1: | ||
311 | move.b %d0, %d3 | ||
312 | lsl.l #8, %d3 | ||
313 | clr.l (%a0)+ | ||
314 | |||
315 | move.w (%a0), %d0 | do b6 and b7 | ||
316 | ext.l %d0 | ||
317 | cmp.l %d1, %d0 | ||
318 | bls.b 1f | ||
319 | spl.b %d0 | ||
320 | 1: | ||
321 | move.b %d0, %d3 | ||
322 | lsl.l #8, %d3 | ||
323 | |||
324 | move.w (2,%a0), %d0 | ||
325 | ext.l %d0 | ||
326 | cmp.l %d1, %d0 | ||
327 | bls.b 1f | ||
328 | spl.b %d0 | ||
329 | 1: | ||
330 | move.b %d0, %d3 | ||
331 | clr.l (%a0)+ | ||
332 | |||
333 | movem.l %d2-%d3, (%a1) | write all 8 output bytes at once | ||
334 | add.l %a2, %a1 | advance output pointer | ||
335 | subq.l #1, %d4 | loop 8 times | ||
336 | bne.w .copy_clip_loop | ||
337 | |||
338 | movem.l (%sp), %d2-%d7/%a2-%a6 | ||
339 | lea.l (11*4,%sp), %sp | ||
340 | rts | ||
341 | |||
342 | .align 2 | ||
343 | |||
344 | mpeg2_idct_add: | ||
345 | lea.l (-11*4,%sp), %sp | ||
346 | movem.l %d2-%d7/%a2-%a6, (%sp) | ||
347 | movem.l (11*4+4,%sp), %d0/%a0-%a2 | %d0 - last value | ||
348 | | %a0 - block pointer | ||
349 | | %a1 - destination pointer | ||
350 | | %a2 - stride | ||
351 | |||
352 | cmp.l #129, %d0 | last == 129 ? | ||
353 | bne.b .idct_add | no: perform idct + addition | ||
354 | move.w (%a0), %d0 | ||
355 | ext.l %d0 | ((block[0] | ||
356 | asr.l #4, %d0 | >> 4) | ||
357 | and.l #7, %d0 | & 7) | ||
358 | subq.l #4, %d0 | - 4 == 0 ? | ||
359 | bne.w .dc_add | no: just perform addition | ||
360 | |||
361 | .idct_add: | ||
362 | bsr.w .idct | apply idct | ||
363 | movem.l (11*4+8,%sp), %a0-%a2 | reload arguments %a0..%a2 | ||
364 | |||
365 | move.l #255, %d2 | preload constant for clipping | ||
366 | clr.l %d3 | used for splitting input words into bytes | ||
367 | moveq.l #8, %d4 | loop counter | ||
368 | |||
369 | .add_clip_loop: | ||
370 | movem.l (%a1), %d6-%d7 | fetch (b0 b1 b2 b3) (b4 b5 b6 b7) | ||
371 | swap %d6 | (b2 b3 b0 b1) | ||
372 | swap %d7 | (b6 b7 b4 b5) | ||
373 | |||
374 | move.w (2,%a0), %d0 | load block[1] | ||
375 | ext.l %d0 | sign extend | ||
376 | move.b %d6, %d3 | copy b1 | ||
377 | lsr.l #8, %d6 | prepare 1st buffer for next byte | ||
378 | add.l %d3, %d0 | add b1 | ||
379 | cmp.l %d2, %d0 | overflow ? | ||
380 | bls.b 1f | ||
381 | spl.b %d0 | yes: set appropriate limit value in low byte | ||
382 | 1: | ||
383 | move.w (%a0), %d1 | load block[0] | ||
384 | ext.l %d1 | sign extend | ||
385 | move.b %d6, %d3 | copy b0 | ||
386 | lsr.l #8, %d6 | prepare 1st buffer for next byte | ||
387 | add.l %d3, %d1 | add b0 | ||
388 | cmp.l %d2, %d1 | overflow ? | ||
389 | bls.b 1f | ||
390 | spl.b %d1 | yes: set appropriate limit value in low byte | ||
391 | 1: | ||
392 | move.b %d1, %d5 | collect output bytes 0..3 in %d5 | ||
393 | lsl.l #8, %d5 | ||
394 | move.b %d0, %d5 | ||
395 | lsl.l #8, %d5 | ||
396 | clr.l (%a0)+ | clear block[0] and block[1] | ||
397 | | %a0 now pointing to block[2] | ||
398 | move.w (2,%a0), %d0 | do b3 and b2 | ||
399 | ext.l %d0 | ||
400 | move.b %d6, %d3 | ||
401 | lsr.l #8, %d6 | ||
402 | add.l %d3, %d0 | ||
403 | cmp.l %d2, %d0 | ||
404 | bls.b 1f | ||
405 | spl.b %d0 | ||
406 | 1: | ||
407 | move.w (%a0), %d1 | ||
408 | ext.l %d1 | ||
409 | add.l %d6, %d1 | ||
410 | cmp.l %d2, %d1 | ||
411 | bls.b 1f | ||
412 | spl.b %d1 | ||
413 | 1: | ||
414 | move.b %d1, %d5 | ||
415 | lsl.l #8, %d5 | ||
416 | move.b %d0, %d5 | ||
417 | clr.l (%a0)+ | ||
418 | |||
419 | move.w (2,%a0), %d0 | do b5 and b4 | ||
420 | ext.l %d0 | ||
421 | move.b %d7, %d3 | ||
422 | lsr.l #8, %d7 | ||
423 | add.l %d3, %d0 | ||
424 | cmp.l %d2, %d0 | ||
425 | bls.b 1f | ||
426 | spl.b %d0 | ||
427 | 1: | ||
428 | move.w (%a0), %d1 | ||
429 | ext.l %d1 | ||
430 | move.b %d7, %d3 | ||
431 | lsr.l #8, %d7 | ||
432 | add.l %d3, %d1 | ||
433 | cmp.l %d2, %d1 | ||
434 | bls.b 1f | ||
435 | spl.b %d1 | ||
436 | 1: | ||
437 | move.b %d1, %d6 | ||
438 | lsl.l #8, %d6 | ||
439 | move.b %d0, %d6 | ||
440 | lsl.l #8, %d6 | ||
441 | clr.l (%a0)+ | ||
442 | |||
443 | move.w (2,%a0), %d0 | do b7 and b6 | ||
444 | ext.l %d0 | ||
445 | move.b %d7, %d3 | ||
446 | lsr.l #8, %d7 | ||
447 | add.l %d3, %d0 | ||
448 | cmp.l %d2, %d0 | ||
449 | bls.b 1f | ||
450 | spl.b %d0 | ||
451 | 1: | ||
452 | move.w (%a0), %d1 | ||
453 | ext.l %d1 | ||
454 | add.l %d7, %d1 | ||
455 | cmp.l %d2, %d1 | ||
456 | bls.b 1f | ||
457 | spl.b %d1 | ||
458 | 1: | ||
459 | move.b %d1, %d6 | ||
460 | lsl.l #8, %d6 | ||
461 | move.b %d0, %d6 | ||
462 | clr.l (%a0)+ | ||
463 | |||
464 | movem.l %d5-%d6, (%a1) | write all 8 output bytes at once | ||
465 | add.l %a2, %a1 | advance output pointer | ||
466 | subq.l #1, %d4 | loop 8 times | ||
467 | bne.w .add_clip_loop | ||
468 | |||
469 | bra.w .idct_add_end | ||
470 | |||
471 | .dc_add: | ||
472 | move.w (%a0), %d0 | ||
473 | ext.l %d0 | %d0 = (block[0] | ||
474 | add.l #64, %d0 | + 64) | ||
475 | asr.l #7, %d0 | >> 7 | ||
476 | clr.w (%a0) | clear block[0] | ||
477 | clr.w (63*2,%a0) | and block[63] | ||
478 | move.l %d0, %a0 | DC value in %a0 | ||
479 | |||
480 | move.l #255, %d2 | preload constant for clipping | ||
481 | clr.l %d3 | for splitting input words into bytes | ||
482 | moveq.l #8, %d4 | loop counter | ||
483 | |||
484 | .dc_clip_loop: | ||
485 | movem.l (%a1), %d6-%d7 | (b0 b1 b2 b3) (b4 b5 b6 b7) | ||
486 | swap %d6 | (b2 b3 b0 b1) | ||
487 | swap %d7 | (b6 b7 b4 b5) | ||
488 | |||
489 | move.l %a0, %d0 | copy DC | ||
490 | move.b %d6, %d3 | copy b1 | ||
491 | lsr.l #8, %d6 | prepare 1st buffer for next byte | ||
492 | add.l %d3, %d0 | add b1 | ||
493 | cmp.l %d2, %d0 | overflow ? | ||
494 | bls.b 1f | ||
495 | spl.b %d0 | yes: set appropriate limit value in low byte | ||
496 | 1: | ||
497 | move.l %a0, %d1 | copy DC | ||
498 | move.b %d6, %d3 | copy b0 | ||
499 | lsr.l #8, %d6 | prepare 1st buffer for next byte | ||
500 | add.l %d3, %d1 | add b0 | ||
501 | cmp.l %d2, %d1 | overflow ? | ||
502 | bls.b 1f | ||
503 | spl.b %d1 | yes: set appropriate limit value in low byte | ||
504 | 1: | ||
505 | move.b %d1, %d5 | collect output bytes 0..3 in %d5 | ||
506 | lsl.l #8, %d5 | ||
507 | move.b %d0, %d5 | ||
508 | lsl.l #8, %d5 | ||
509 | |||
510 | move.l %a0, %d0 | do b3 and b2 | ||
511 | move.b %d6, %d3 | ||
512 | lsr.l #8, %d6 | ||
513 | add.l %d3, %d0 | ||
514 | cmp.l %d2, %d0 | ||
515 | bls.b 1f | ||
516 | spl.b %d0 | ||
517 | 1: | ||
518 | move.l %a0, %d1 | ||
519 | add.l %d6, %d1 | ||
520 | cmp.l %d2, %d1 | ||
521 | bls.b 1f | ||
522 | spl.b %d1 | ||
523 | 1: | ||
524 | move.b %d1, %d5 | ||
525 | lsl.l #8, %d5 | ||
526 | move.b %d0, %d5 | ||
527 | |||
528 | move.l %a0, %d0 | do b5 and b4 | ||
529 | move.b %d7, %d3 | ||
530 | lsr.l #8, %d7 | ||
531 | add.l %d3, %d0 | ||
532 | cmp.l %d2, %d0 | ||
533 | bls.b 1f | ||
534 | spl.b %d0 | ||
535 | 1: | ||
536 | move.l %a0, %d1 | ||
537 | move.b %d7, %d3 | ||
538 | lsr.l #8, %d7 | ||
539 | add.l %d3, %d1 | ||
540 | cmp.l %d2, %d1 | ||
541 | bls.b 1f | ||
542 | spl.b %d1 | ||
543 | 1: | ||
544 | move.b %d1, %d6 | do b7 and b6 | ||
545 | lsl.l #8, %d6 | ||
546 | move.b %d0, %d6 | ||
547 | lsl.l #8, %d6 | ||
548 | |||
549 | move.l %a0, %d0 | ||
550 | move.b %d7, %d3 | ||
551 | lsr.l #8, %d7 | ||
552 | add.l %d3, %d0 | ||
553 | cmp.l %d2, %d0 | ||
554 | bls.b 1f | ||
555 | spl.b %d0 | ||
556 | 1: | ||
557 | move.l %a0, %d1 | ||
558 | add.l %d7, %d1 | ||
559 | cmp.l %d2, %d1 | ||
560 | bls.b 1f | ||
561 | spl.b %d1 | ||
562 | 1: | ||
563 | move.b %d1, %d6 | ||
564 | lsl.l #8, %d6 | ||
565 | move.b %d0, %d6 | ||
566 | |||
567 | movem.l %d5-%d6, (%a1) | write all 8 output bytes at once | ||
568 | add.l %a2, %a1 | advance output pointer | ||
569 | subq.l #1, %d4 | loop 8 times | ||
570 | bne.w .dc_clip_loop | ||
571 | |||
572 | .idct_add_end: | ||
573 | movem.l (%sp), %d2-%d7/%a2-%a6 | ||
574 | lea.l (11*4,%sp), %sp | ||
575 | rts | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/motion_comp.c b/apps/plugins/mpegplayer/libmpeg2/motion_comp.c new file mode 100644 index 0000000000..d6968f68ce --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/motion_comp.c | |||
@@ -0,0 +1,66 @@ | |||
1 | /* | ||
2 | * motion_comp.c | ||
3 | * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> | ||
4 | * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | ||
5 | * | ||
6 | * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. | ||
7 | * See http://libmpeg2.sourceforge.net/ for updates. | ||
8 | * | ||
9 | * mpeg2dec is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * mpeg2dec is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | ||
23 | * $Id$ | ||
24 | * libmpeg2 sync history: | ||
25 | * 2008-07-01 - CVS revision 1.17 - lost compatibility previously to | ||
26 | * provide simplified and CPU-optimized motion compensation. | ||
27 | */ | ||
28 | |||
29 | #include "plugin.h" | ||
30 | |||
31 | #include "mpeg2dec_config.h" | ||
32 | |||
33 | #include "mpeg2.h" | ||
34 | #include "attributes.h" | ||
35 | #include "mpeg2_internal.h" | ||
36 | |||
37 | /* These are defined in their respective target files - motion_comp_X.c */ | ||
38 | extern mpeg2_mc_fct MC_put_o_16; | ||
39 | extern mpeg2_mc_fct MC_put_o_8; | ||
40 | extern mpeg2_mc_fct MC_put_x_16; | ||
41 | extern mpeg2_mc_fct MC_put_x_8; | ||
42 | extern mpeg2_mc_fct MC_put_y_16; | ||
43 | extern mpeg2_mc_fct MC_put_y_8; | ||
44 | extern mpeg2_mc_fct MC_put_xy_16; | ||
45 | extern mpeg2_mc_fct MC_put_xy_8; | ||
46 | |||
47 | extern mpeg2_mc_fct MC_avg_o_16; | ||
48 | extern mpeg2_mc_fct MC_avg_o_8; | ||
49 | extern mpeg2_mc_fct MC_avg_x_16; | ||
50 | extern mpeg2_mc_fct MC_avg_x_8; | ||
51 | extern mpeg2_mc_fct MC_avg_y_16; | ||
52 | extern mpeg2_mc_fct MC_avg_y_8; | ||
53 | extern mpeg2_mc_fct MC_avg_xy_16; | ||
54 | extern mpeg2_mc_fct MC_avg_xy_8; | ||
55 | |||
56 | const mpeg2_mc_t mpeg2_mc = | ||
57 | { | ||
58 | { | ||
59 | MC_put_o_16, MC_put_x_16, MC_put_y_16, MC_put_xy_16, | ||
60 | MC_put_o_8, MC_put_x_8, MC_put_y_8, MC_put_xy_8 | ||
61 | }, | ||
62 | { | ||
63 | MC_avg_o_16, MC_avg_x_16, MC_avg_y_16, MC_avg_xy_16, | ||
64 | MC_avg_o_8, MC_avg_x_8, MC_avg_y_8, MC_avg_xy_8 | ||
65 | } | ||
66 | }; | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/motion_comp.h b/apps/plugins/mpegplayer/libmpeg2/motion_comp.h new file mode 100644 index 0000000000..4737e72cab --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/motion_comp.h | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | * motion_comp.h | ||
3 | * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> | ||
4 | * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | ||
5 | * | ||
6 | * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. | ||
7 | * See http://libmpeg2.sourceforge.net/ for updates. | ||
8 | * | ||
9 | * mpeg2dec is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * mpeg2dec is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | ||
23 | * $Id$ | ||
24 | */ | ||
25 | |||
26 | |||
27 | #define avg2(a,b) ((a+b+1)>>1) | ||
28 | #define avg4(a,b,c,d) ((a+b+c+d+2)>>2) | ||
29 | |||
30 | #define predict_o(i) (ref[i]) | ||
31 | #define predict_x(i) (avg2 (ref[i], ref[i+1])) | ||
32 | #define predict_y(i) (avg2 (ref[i], (ref+stride)[i])) | ||
33 | #define predict_xy(i) (avg4 (ref[i], ref[i+1], \ | ||
34 | (ref+stride)[i], (ref+stride)[i+1])) | ||
35 | |||
36 | #define put(predictor,i) dest[i] = predictor (i) | ||
37 | #define avg(predictor,i) dest[i] = avg2 (predictor (i), dest[i]) | ||
38 | |||
39 | /* mc function template */ | ||
40 | #define MC_FUNC(op, xy) \ | ||
41 | MC_FUNC_16(op, xy) \ | ||
42 | MC_FUNC_8(op, xy) | ||
43 | |||
44 | #define MC_FUNC_16(op, xy) \ | ||
45 | void MC_##op##_##xy##_16 (uint8_t * dest, const uint8_t * ref, \ | ||
46 | const int stride, int height) \ | ||
47 | { \ | ||
48 | do { \ | ||
49 | op (predict_##xy, 0); \ | ||
50 | op (predict_##xy, 1); \ | ||
51 | op (predict_##xy, 2); \ | ||
52 | op (predict_##xy, 3); \ | ||
53 | op (predict_##xy, 4); \ | ||
54 | op (predict_##xy, 5); \ | ||
55 | op (predict_##xy, 6); \ | ||
56 | op (predict_##xy, 7); \ | ||
57 | op (predict_##xy, 8); \ | ||
58 | op (predict_##xy, 9); \ | ||
59 | op (predict_##xy, 10); \ | ||
60 | op (predict_##xy, 11); \ | ||
61 | op (predict_##xy, 12); \ | ||
62 | op (predict_##xy, 13); \ | ||
63 | op (predict_##xy, 14); \ | ||
64 | op (predict_##xy, 15); \ | ||
65 | ref += stride; \ | ||
66 | dest += stride; \ | ||
67 | } while (--height); \ | ||
68 | } | ||
69 | |||
70 | #define MC_FUNC_8(op, xy) \ | ||
71 | void MC_##op##_##xy##_8 (uint8_t * dest, const uint8_t * ref, \ | ||
72 | const int stride, int height) \ | ||
73 | { \ | ||
74 | do { \ | ||
75 | op (predict_##xy, 0); \ | ||
76 | op (predict_##xy, 1); \ | ||
77 | op (predict_##xy, 2); \ | ||
78 | op (predict_##xy, 3); \ | ||
79 | op (predict_##xy, 4); \ | ||
80 | op (predict_##xy, 5); \ | ||
81 | op (predict_##xy, 6); \ | ||
82 | op (predict_##xy, 7); \ | ||
83 | ref += stride; \ | ||
84 | dest += stride; \ | ||
85 | } while (--height); \ | ||
86 | } | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/motion_comp_arm_c.c b/apps/plugins/mpegplayer/libmpeg2/motion_comp_arm_c.c new file mode 100644 index 0000000000..dcf1df53e9 --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/motion_comp_arm_c.c | |||
@@ -0,0 +1,39 @@ | |||
1 | /* | ||
2 | * motion_comp_arm.c | ||
3 | * Copyright (C) 2004 AGAWA Koji <i (AT) atty (DOT) jp> | ||
4 | * | ||
5 | * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. | ||
6 | * See http://libmpeg2.sourceforge.net/ for updates. | ||
7 | * | ||
8 | * mpeg2dec is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * mpeg2dec is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | * | ||
22 | * $Id$ | ||
23 | */ | ||
24 | #include <inttypes.h> | ||
25 | #include "mpeg2.h" | ||
26 | #include "attributes.h" | ||
27 | #include "mpeg2_internal.h" | ||
28 | #include "motion_comp.h" | ||
29 | |||
30 | /* definitions of the actual mc functions */ | ||
31 | |||
32 | /* MC_FUNC (put, o) <= ASM */ | ||
33 | MC_FUNC (avg, o) | ||
34 | /* MC_FUNC (put, x) <= ASM */ | ||
35 | MC_FUNC (avg, x) | ||
36 | MC_FUNC (put, y) | ||
37 | MC_FUNC (avg, y) | ||
38 | MC_FUNC (put, xy) | ||
39 | MC_FUNC (avg, xy) | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/motion_comp_arm_s.S b/apps/plugins/mpegplayer/libmpeg2/motion_comp_arm_s.S new file mode 100644 index 0000000000..1ec1b0686e --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/motion_comp_arm_s.S | |||
@@ -0,0 +1,342 @@ | |||
1 | @ motion_comp_arm_s.S | ||
2 | @ Copyright (C) 2004 AGAWA Koji <i (AT) atty (DOT) jp> | ||
3 | @ | ||
4 | @ This file is part of mpeg2dec, a free MPEG-2 video stream decoder. | ||
5 | @ See http://libmpeg2.sourceforge.net/ for updates. | ||
6 | @ | ||
7 | @ mpeg2dec is free software; you can redistribute it and/or modify | ||
8 | @ it under the terms of the GNU General Public License as published by | ||
9 | @ the Free Software Foundation; either version 2 of the License, or | ||
10 | @ (at your option) any later version. | ||
11 | @ | ||
12 | @ mpeg2dec is distributed in the hope that it will be useful, | ||
13 | @ but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | @ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | @ GNU General Public License for more details. | ||
16 | @ | ||
17 | @ You should have received a copy of the GNU General Public License | ||
18 | @ along with this program; if not, write to the Free Software | ||
19 | @ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | @ | ||
21 | @ $Id$ | ||
22 | |||
23 | #include "config.h" /* Rockbox: ARM architecture version */ | ||
24 | |||
25 | .text | ||
26 | |||
27 | @ ---------------------------------------------------------------- | ||
28 | .align | ||
29 | .global MC_put_o_16 | ||
30 | MC_put_o_16: | ||
31 | @@ void func(uint8_t * dest, const uint8_t * ref, int stride, int height) | ||
32 | @@ pld [r1] | ||
33 | stmfd sp!, {r4-r7, lr} @ R14 is also called LR | ||
34 | and r4, r1, #3 | ||
35 | ldr pc, [pc, r4, lsl #2] | ||
36 | .word 0 | ||
37 | .word MC_put_o_16_align0 | ||
38 | .word MC_put_o_16_align1 | ||
39 | .word MC_put_o_16_align2 | ||
40 | .word MC_put_o_16_align3 | ||
41 | |||
42 | MC_put_o_16_align0: | ||
43 | ldmia r1, {r4-r7} | ||
44 | add r1, r1, r2 | ||
45 | @@ pld [r1] | ||
46 | stmia r0, {r4-r7} | ||
47 | subs r3, r3, #1 | ||
48 | add r0, r0, r2 | ||
49 | bne MC_put_o_16_align0 | ||
50 | ldmpc regs=r4-r7 @@ update PC with LR content. | ||
51 | |||
52 | .macro ADJ_ALIGN_QW shift, R0, R1, R2, R3, R4 | ||
53 | mov \R0, \R0, lsr #(\shift) | ||
54 | orr \R0, \R0, \R1, lsl #(32 - \shift) | ||
55 | mov \R1, \R1, lsr #(\shift) | ||
56 | orr \R1, \R1, \R2, lsl #(32 - \shift) | ||
57 | mov \R2, \R2, lsr #(\shift) | ||
58 | orr \R2, \R2, \R3, lsl #(32 - \shift) | ||
59 | mov \R3, \R3, lsr #(\shift) | ||
60 | orr \R3, \R3, \R4, lsl #(32 - \shift) | ||
61 | mov \R4, \R4, lsr #(\shift) | ||
62 | .endm | ||
63 | |||
64 | MC_put_o_16_align1: | ||
65 | and r1, r1, #0xFFFFFFFC | ||
66 | 1: ldmia r1, {r4-r7, r12} | ||
67 | add r1, r1, r2 | ||
68 | @@ pld [r1] | ||
69 | ADJ_ALIGN_QW 8, r4, r5, r6, r7, r12 | ||
70 | stmia r0, {r4-r7} | ||
71 | subs r3, r3, #1 | ||
72 | add r0, r0, r2 | ||
73 | bne 1b | ||
74 | ldmpc regs=r4-r7 @@ update PC with LR content. | ||
75 | |||
76 | MC_put_o_16_align2: | ||
77 | and r1, r1, #0xFFFFFFFC | ||
78 | 1: ldmia r1, {r4-r7, r12} | ||
79 | add r1, r1, r2 | ||
80 | @@ pld [r1] | ||
81 | ADJ_ALIGN_QW 16, r4, r5, r6, r7, r12 | ||
82 | stmia r0, {r4-r7} | ||
83 | subs r3, r3, #1 | ||
84 | add r0, r0, r2 | ||
85 | bne 1b | ||
86 | ldmpc regs=r4-r7 @@ update PC with LR content. | ||
87 | |||
88 | MC_put_o_16_align3: | ||
89 | and r1, r1, #0xFFFFFFFC | ||
90 | 1: ldmia r1, {r4-r7, r12} | ||
91 | add r1, r1, r2 | ||
92 | @@ pld [r1] | ||
93 | ADJ_ALIGN_QW 24, r4, r5, r6, r7, r12 | ||
94 | stmia r0, {r4-r7} | ||
95 | subs r3, r3, #1 | ||
96 | add r0, r0, r2 | ||
97 | bne 1b | ||
98 | ldmpc regs=r4-r7 @@ update PC with LR content. | ||
99 | |||
100 | @ ---------------------------------------------------------------- | ||
101 | .align | ||
102 | .global MC_put_o_8 | ||
103 | MC_put_o_8: | ||
104 | @@ void func(uint8_t * dest, const uint8_t * ref, int stride, int height) | ||
105 | @@ pld [r1] | ||
106 | stmfd sp!, {r4, r5, lr} @ R14 is also called LR | ||
107 | and r4, r1, #3 | ||
108 | ldr pc, [pc, r4, lsl #2] | ||
109 | .word 0 | ||
110 | .word MC_put_o_8_align0 | ||
111 | .word MC_put_o_8_align1 | ||
112 | .word MC_put_o_8_align2 | ||
113 | .word MC_put_o_8_align3 | ||
114 | |||
115 | MC_put_o_8_align0: | ||
116 | ldmia r1, {r4, r5} | ||
117 | add r1, r1, r2 | ||
118 | @@ pld [r1] | ||
119 | stmia r0, {r4, r5} | ||
120 | add r0, r0, r2 | ||
121 | subs r3, r3, #1 | ||
122 | bne MC_put_o_8_align0 | ||
123 | ldmpc regs=r4-r5 @@ update PC with LR content. | ||
124 | |||
125 | .macro ADJ_ALIGN_DW shift, R0, R1, R2 | ||
126 | mov \R0, \R0, lsr #(\shift) | ||
127 | orr \R0, \R0, \R1, lsl #(32 - \shift) | ||
128 | mov \R1, \R1, lsr #(\shift) | ||
129 | orr \R1, \R1, \R2, lsl #(32 - \shift) | ||
130 | mov \R2, \R2, lsr #(\shift) | ||
131 | .endm | ||
132 | |||
133 | MC_put_o_8_align1: | ||
134 | and r1, r1, #0xFFFFFFFC | ||
135 | 1: ldmia r1, {r4, r5, r12} | ||
136 | add r1, r1, r2 | ||
137 | @@ pld [r1] | ||
138 | ADJ_ALIGN_DW 8, r4, r5, r12 | ||
139 | stmia r0, {r4, r5} | ||
140 | subs r3, r3, #1 | ||
141 | add r0, r0, r2 | ||
142 | bne 1b | ||
143 | ldmpc regs=r4-r5 @@ update PC with LR content. | ||
144 | |||
145 | MC_put_o_8_align2: | ||
146 | and r1, r1, #0xFFFFFFFC | ||
147 | 1: ldmia r1, {r4, r5, r12} | ||
148 | add r1, r1, r2 | ||
149 | @@ pld [r1] | ||
150 | ADJ_ALIGN_DW 16, r4, r5, r12 | ||
151 | stmia r0, {r4, r5} | ||
152 | subs r3, r3, #1 | ||
153 | add r0, r0, r2 | ||
154 | bne 1b | ||
155 | ldmpc regs=r4-r5 @@ update PC with LR content. | ||
156 | |||
157 | MC_put_o_8_align3: | ||
158 | and r1, r1, #0xFFFFFFFC | ||
159 | 1: ldmia r1, {r4, r5, r12} | ||
160 | add r1, r1, r2 | ||
161 | @@ pld [r1] | ||
162 | ADJ_ALIGN_DW 24, r4, r5, r12 | ||
163 | stmia r0, {r4, r5} | ||
164 | subs r3, r3, #1 | ||
165 | add r0, r0, r2 | ||
166 | bne 1b | ||
167 | ldmpc regs=r4-r5 @@ update PC with LR content. | ||
168 | |||
169 | @ ---------------------------------------------------------------- | ||
170 | .macro AVG_PW rW1, rW2 | ||
171 | mov \rW2, \rW2, lsl #24 | ||
172 | orr \rW2, \rW2, \rW1, lsr #8 | ||
173 | eor r9, \rW1, \rW2 | ||
174 | #if ARM_ARCH >= 6 | ||
175 | uhadd8 \rW2, \rW1, \rW2 | ||
176 | #else | ||
177 | and \rW2, \rW1, \rW2 | ||
178 | and r10, r9, r11 | ||
179 | add \rW2, \rW2, r10, lsr #1 | ||
180 | #endif | ||
181 | and r9, r9, r12 | ||
182 | add \rW2, \rW2, r9 | ||
183 | .endm | ||
184 | |||
185 | #if ARM_ARCH >= 6 | ||
186 | #define HIGHEST_REG r9 | ||
187 | #else | ||
188 | #define HIGHEST_REG r11 | ||
189 | #endif | ||
190 | |||
191 | .align | ||
192 | .global MC_put_x_16 | ||
193 | MC_put_x_16: | ||
194 | @@ void func(uint8_t * dest, const uint8_t * ref, int stride, int height) | ||
195 | @@ pld [r1] | ||
196 | stmfd sp!, {r4-HIGHEST_REG, lr} @ R14 is also called LR | ||
197 | and r4, r1, #3 | ||
198 | ldr r12, 2f | ||
199 | #if ARM_ARCH < 6 | ||
200 | mvn r11, r12 | ||
201 | #endif | ||
202 | ldr pc, [pc, r4, lsl #2] | ||
203 | 2: .word 0x01010101 | ||
204 | .word MC_put_x_16_align0 | ||
205 | .word MC_put_x_16_align1 | ||
206 | .word MC_put_x_16_align2 | ||
207 | .word MC_put_x_16_align3 | ||
208 | |||
209 | MC_put_x_16_align0: | ||
210 | ldmia r1, {r4-r8} | ||
211 | add r1, r1, r2 | ||
212 | @@ pld [r1] | ||
213 | AVG_PW r7, r8 | ||
214 | AVG_PW r6, r7 | ||
215 | AVG_PW r5, r6 | ||
216 | AVG_PW r4, r5 | ||
217 | stmia r0, {r5-r8} | ||
218 | subs r3, r3, #1 | ||
219 | add r0, r0, r2 | ||
220 | bne MC_put_x_16_align0 | ||
221 | ldmpc regs=r4-HIGHEST_REG @@ update PC with LR content. | ||
222 | |||
223 | MC_put_x_16_align1: | ||
224 | and r1, r1, #0xFFFFFFFC | ||
225 | 1: ldmia r1, {r4-r8} | ||
226 | add r1, r1, r2 | ||
227 | @@ pld [r1] | ||
228 | ADJ_ALIGN_QW 8, r4, r5, r6, r7, r8 | ||
229 | AVG_PW r7, r8 | ||
230 | AVG_PW r6, r7 | ||
231 | AVG_PW r5, r6 | ||
232 | AVG_PW r4, r5 | ||
233 | stmia r0, {r5-r8} | ||
234 | subs r3, r3, #1 | ||
235 | add r0, r0, r2 | ||
236 | bne 1b | ||
237 | ldmpc regs=r4-HIGHEST_REG @@ update PC with LR content. | ||
238 | |||
239 | MC_put_x_16_align2: | ||
240 | and r1, r1, #0xFFFFFFFC | ||
241 | 1: ldmia r1, {r4-r8} | ||
242 | add r1, r1, r2 | ||
243 | @@ pld [r1] | ||
244 | ADJ_ALIGN_QW 16, r4, r5, r6, r7, r8 | ||
245 | AVG_PW r7, r8 | ||
246 | AVG_PW r6, r7 | ||
247 | AVG_PW r5, r6 | ||
248 | AVG_PW r4, r5 | ||
249 | stmia r0, {r5-r8} | ||
250 | subs r3, r3, #1 | ||
251 | add r0, r0, r2 | ||
252 | bne 1b | ||
253 | ldmpc regs=r4-HIGHEST_REG @@ update PC with LR content. | ||
254 | |||
255 | MC_put_x_16_align3: | ||
256 | and r1, r1, #0xFFFFFFFC | ||
257 | 1: ldmia r1, {r4-r8} | ||
258 | add r1, r1, r2 | ||
259 | @@ pld [r1] | ||
260 | ADJ_ALIGN_QW 24, r4, r5, r6, r7, r8 | ||
261 | AVG_PW r7, r8 | ||
262 | AVG_PW r6, r7 | ||
263 | AVG_PW r5, r6 | ||
264 | AVG_PW r4, r5 | ||
265 | stmia r0, {r5-r8} | ||
266 | subs r3, r3, #1 | ||
267 | add r0, r0, r2 | ||
268 | bne 1b | ||
269 | ldmpc regs=r4-HIGHEST_REG @@ update PC with LR content. | ||
270 | |||
271 | @ ---------------------------------------------------------------- | ||
272 | .align | ||
273 | .global MC_put_x_8 | ||
274 | MC_put_x_8: | ||
275 | @@ void func(uint8_t * dest, const uint8_t * ref, int stride, int height) | ||
276 | @@ pld [r1] | ||
277 | stmfd sp!, {r6-HIGHEST_REG, lr} @ R14 is also called LR | ||
278 | and r6, r1, #3 | ||
279 | ldr r12, 2f | ||
280 | #if ARM_ARCH < 6 | ||
281 | mvn r11, r12 | ||
282 | #endif | ||
283 | ldr pc, [pc, r6, lsl #2] | ||
284 | 2: .word 0x01010101 | ||
285 | .word MC_put_x_8_align0 | ||
286 | .word MC_put_x_8_align1 | ||
287 | .word MC_put_x_8_align2 | ||
288 | .word MC_put_x_8_align3 | ||
289 | |||
290 | MC_put_x_8_align0: | ||
291 | ldmia r1, {r6-r8} | ||
292 | add r1, r1, r2 | ||
293 | @@ pld [r1] | ||
294 | AVG_PW r7, r8 | ||
295 | AVG_PW r6, r7 | ||
296 | stmia r0, {r7-r8} | ||
297 | subs r3, r3, #1 | ||
298 | add r0, r0, r2 | ||
299 | bne MC_put_x_8_align0 | ||
300 | ldmpc regs=r6-HIGHEST_REG @@ update PC with LR content. | ||
301 | |||
302 | MC_put_x_8_align1: | ||
303 | and r1, r1, #0xFFFFFFFC | ||
304 | 1: ldmia r1, {r6-r8} | ||
305 | add r1, r1, r2 | ||
306 | @@ pld [r1] | ||
307 | ADJ_ALIGN_DW 8, r6, r7, r8 | ||
308 | AVG_PW r7, r8 | ||
309 | AVG_PW r6, r7 | ||
310 | stmia r0, {r7-r8} | ||
311 | subs r3, r3, #1 | ||
312 | add r0, r0, r2 | ||
313 | bne 1b | ||
314 | ldmpc regs=r6-HIGHEST_REG @@ update PC with LR content. | ||
315 | |||
316 | MC_put_x_8_align2: | ||
317 | and r1, r1, #0xFFFFFFFC | ||
318 | 1: ldmia r1, {r6-r8} | ||
319 | add r1, r1, r2 | ||
320 | @@ pld [r1] | ||
321 | ADJ_ALIGN_DW 16, r6, r7, r8 | ||
322 | AVG_PW r7, r8 | ||
323 | AVG_PW r6, r7 | ||
324 | stmia r0, {r7-r8} | ||
325 | subs r3, r3, #1 | ||
326 | add r0, r0, r2 | ||
327 | bne 1b | ||
328 | ldmpc regs=r6-HIGHEST_REG @@ update PC with LR content. | ||
329 | |||
330 | MC_put_x_8_align3: | ||
331 | and r1, r1, #0xFFFFFFFC | ||
332 | 1: ldmia r1, {r6-r8} | ||
333 | add r1, r1, r2 | ||
334 | @@ pld [r1] | ||
335 | ADJ_ALIGN_DW 24, r6, r7, r8 | ||
336 | AVG_PW r7, r8 | ||
337 | AVG_PW r6, r7 | ||
338 | stmia r0, {r7-r8} | ||
339 | subs r3, r3, #1 | ||
340 | add r0, r0, r2 | ||
341 | bne 1b | ||
342 | ldmpc regs=r6-HIGHEST_REG @@ update PC with LR content. | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/motion_comp_c.c b/apps/plugins/mpegplayer/libmpeg2/motion_comp_c.c new file mode 100644 index 0000000000..9a8640e7e6 --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/motion_comp_c.c | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | * motion_comp.c | ||
3 | * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> | ||
4 | * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | ||
5 | * | ||
6 | * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. | ||
7 | * See http://libmpeg2.sourceforge.net/ for updates. | ||
8 | * | ||
9 | * mpeg2dec is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * mpeg2dec is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | ||
23 | * $Id$ | ||
24 | */ | ||
25 | #include <inttypes.h> | ||
26 | #include "mpeg2.h" | ||
27 | #include "attributes.h" | ||
28 | #include "mpeg2_internal.h" | ||
29 | #include "motion_comp.h" | ||
30 | |||
31 | /* definitions of the actual mc functions */ | ||
32 | |||
33 | MC_FUNC (put, o) | ||
34 | MC_FUNC (avg, o) | ||
35 | MC_FUNC (put, x) | ||
36 | MC_FUNC (avg, x) | ||
37 | MC_FUNC (put, y) | ||
38 | MC_FUNC (avg, y) | ||
39 | MC_FUNC (put, xy) | ||
40 | MC_FUNC (avg, xy) | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/motion_comp_coldfire_c.c b/apps/plugins/mpegplayer/libmpeg2/motion_comp_coldfire_c.c new file mode 100644 index 0000000000..b97e3510e7 --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/motion_comp_coldfire_c.c | |||
@@ -0,0 +1,38 @@ | |||
1 | /* | ||
2 | * Based on: | ||
3 | * motion_comp_arm.c | ||
4 | * Copyright (C) 2004 AGAWA Koji <i (AT) atty (DOT) jp> | ||
5 | * | ||
6 | * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. | ||
7 | * See http://libmpeg2.sourceforge.net/ for updates. | ||
8 | * | ||
9 | * mpeg2dec is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * mpeg2dec is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | */ | ||
23 | #include <inttypes.h> | ||
24 | #include "mpeg2.h" | ||
25 | #include "attributes.h" | ||
26 | #include "mpeg2_internal.h" | ||
27 | #include "motion_comp.h" | ||
28 | |||
29 | /* definitions of the actual mc functions */ | ||
30 | |||
31 | /* MC_FUNC (put, o) <= ASM */ | ||
32 | MC_FUNC (avg, o) | ||
33 | /* MC_FUNC (put, x) <= ASM */ | ||
34 | MC_FUNC (avg, x) | ||
35 | MC_FUNC (put, y) | ||
36 | MC_FUNC (avg, y) | ||
37 | MC_FUNC (put, xy) | ||
38 | MC_FUNC (avg, xy) | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/motion_comp_coldfire_s.S b/apps/plugins/mpegplayer/libmpeg2/motion_comp_coldfire_s.S new file mode 100644 index 0000000000..55d87cb708 --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/motion_comp_coldfire_s.S | |||
@@ -0,0 +1,436 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2007 Jens Arnold | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | .macro LEFT8_PW dW1, dW2 | needs %d0 == 24, clobbers %d2 | ||
23 | lsl.l #8, \dW1 | changes dW1, keeps dW2 | ||
24 | move.l \dW2, %d2 | ||
25 | lsr.l %d0, %d2 | ||
26 | or.l %d2, \dW1 | ||
27 | .endm | ||
28 | |||
29 | .macro LEFT24_PW dW1, dW2 | needs %d0 == 24, clobbers %d2 | ||
30 | lsl.l %d0, \dW1 | changes dW1, keeps dW2 | ||
31 | move.l \dW2, %d2 | ||
32 | lsr.l #8, %d2 | ||
33 | or.l %d2, \dW1 | ||
34 | .endm | ||
35 | |||
36 | /*****************************************************************************/ | ||
37 | |||
38 | .align 2 | ||
39 | .global MC_put_o_8 | ||
40 | .type MC_put_o_8, @function | ||
41 | |||
42 | MC_put_o_8: | ||
43 | movem.l (4,%sp), %a0-%a1 | dest, source | ||
44 | move.l %a1, %d0 | ||
45 | and.l #3, %d0 | ||
46 | sub.l %d0, %a1 | align source | ||
47 | jmp.l (2, %pc, %d0.l*4) | ||
48 | bra.w .po8_0 | ||
49 | bra.w .po8_1 | ||
50 | bra.w .po8_2 | ||
51 | | last table entry coincides with target | ||
52 | |||
53 | .po8_3: | ||
54 | lea.l (-5*4,%sp), %sp | ||
55 | movem.l %d2-%d5/%a2, (%sp) | save some registers | ||
56 | move.l (5*4+12,%sp), %a2 | stride | ||
57 | move.l (5*4+16,%sp), %d1 | height | ||
58 | moveq.l #24, %d0 | shift amount | ||
59 | 1: | ||
60 | movem.l (%a1), %d3-%d5 | ||
61 | add.l %a2, %a1 | ||
62 | LEFT24_PW %d3, %d4 | ||
63 | lsl.l %d0, %d4 | ||
64 | lsr.l #8, %d5 | ||
65 | or.l %d5, %d4 | ||
66 | movem.l %d3-%d4, (%a0) | ||
67 | add.l %a2, %a0 | ||
68 | subq.l #1, %d1 | ||
69 | bne.s 1b | ||
70 | movem.l (%sp), %d2-%d5/%a2 | ||
71 | lea.l (5*4,%sp), %sp | ||
72 | rts | ||
73 | |||
74 | .po8_2: | ||
75 | lea.l (-3*4,%sp), %sp | ||
76 | movem.l %d2-%d4, (%sp) | save some registers | ||
77 | movem.l (3*4+12,%sp), %d0-%d1 | stride, height | ||
78 | 1: | ||
79 | movem.l (%a1), %d2-%d4 | ||
80 | add.l %d0, %a1 | ||
81 | swap %d2 | ||
82 | swap %d3 | ||
83 | move.w %d3, %d2 | ||
84 | swap %d4 | ||
85 | move.w %d4, %d3 | ||
86 | movem.l %d2-%d3, (%a0) | ||
87 | add.l %d0, %a0 | ||
88 | subq.l #1, %d1 | ||
89 | bne.s 1b | ||
90 | movem.l (%sp), %d2-%d4 | ||
91 | lea.l (3*4,%sp), %sp | ||
92 | rts | ||
93 | |||
94 | .po8_1: | ||
95 | lea.l (-5*4,%sp), %sp | ||
96 | movem.l %d2-%d5/%a2, (%sp) | save some registers | ||
97 | move.l (5*4+12,%sp), %a2 | stride | ||
98 | move.l (5*4+16,%sp), %d1 | height | ||
99 | moveq.l #24, %d0 | shift amount | ||
100 | 1: | ||
101 | movem.l (%a1), %d3-%d5 | ||
102 | add.l %a2, %a1 | ||
103 | LEFT8_PW %d3, %d4 | ||
104 | lsl.l #8, %d4 | ||
105 | lsr.l %d0, %d5 | ||
106 | or.l %d5, %d4 | ||
107 | movem.l %d3-%d4, (%a0) | ||
108 | add.l %a2, %a0 | ||
109 | subq.l #1, %d1 | ||
110 | bne.s 1b | ||
111 | movem.l (%sp), %d2-%d5/%a2 | ||
112 | lea.l (5*4,%sp), %sp | ||
113 | rts | ||
114 | |||
115 | .po8_0: | ||
116 | movem.l (12,%sp), %d0-%d1 | stride, height | ||
117 | subq.l #4, %d0 | adjust for increment within the loop | ||
118 | 1: | ||
119 | move.l (%a1)+, (%a0)+ | ||
120 | move.l (%a1), (%a0) | ||
121 | add.l %d0, %a0 | ||
122 | add.l %d0, %a1 | ||
123 | subq.l #1, %d1 | ||
124 | bne.s 1b | ||
125 | rts | ||
126 | |||
127 | /*****************************************************************************/ | ||
128 | |||
129 | .align 2 | ||
130 | .global MC_put_o_16 | ||
131 | .type MC_put_o_16, @function | ||
132 | |||
133 | MC_put_o_16: | ||
134 | lea.l (-7*4,%sp), %sp | ||
135 | movem.l %d2-%d7/%a2, (%sp) | save some registers | ||
136 | movem.l (7*4+4,%sp), %a0-%a2| dest, source, stride | ||
137 | move.l (7*4+16,%sp), %d1 | height | ||
138 | move.l %a1, %d0 | ||
139 | and.l #3, %d0 | ||
140 | sub.l %d0, %a1 | ||
141 | jmp.l (2, %pc, %d0.l*4) | ||
142 | bra.w .po16_0 | ||
143 | bra.w .po16_1 | ||
144 | bra.w .po16_2 | ||
145 | | last table entry coincides with target | ||
146 | |||
147 | .po16_3: | ||
148 | moveq.l #24, %d0 | shift amount | ||
149 | 1: | ||
150 | movem.l (%a1), %d3-%d7 | ||
151 | add.l %a2, %a1 | ||
152 | LEFT24_PW %d3, %d4 | ||
153 | LEFT24_PW %d4, %d5 | ||
154 | LEFT24_PW %d5, %d6 | ||
155 | lsl.l %d0, %d6 | ||
156 | lsr.l #8, %d7 | ||
157 | or.l %d7, %d6 | ||
158 | movem.l %d3-%d6, (%a0) | ||
159 | add.l %a2, %a0 | ||
160 | subq.l #1, %d1 | ||
161 | bne.s 1b | ||
162 | movem.l (%sp), %d2-%d7/%a2 | ||
163 | lea.l (7*4,%sp), %sp | ||
164 | rts | ||
165 | |||
166 | .po16_2: | ||
167 | 1: | ||
168 | movem.l (%a1), %d3-%d7 | ||
169 | add.l %a2, %a1 | ||
170 | swap %d3 | ||
171 | swap %d4 | ||
172 | move.w %d4, %d3 | ||
173 | swap %d5 | ||
174 | move.w %d5, %d4 | ||
175 | swap %d6 | ||
176 | move.w %d6, %d5 | ||
177 | swap %d7 | ||
178 | move.w %d7, %d6 | ||
179 | movem.l %d3-%d6, (%a0) | ||
180 | add.l %a2, %a0 | ||
181 | subq.l #1, %d1 | ||
182 | bne.s 1b | ||
183 | movem.l (%sp), %d2-%d7/%a2 | ||
184 | lea.l (7*4,%sp), %sp | ||
185 | rts | ||
186 | |||
187 | .po16_1: | ||
188 | moveq.l #24, %d0 | shift amount | ||
189 | 1: | ||
190 | movem.l (%a1), %d3-%d7 | ||
191 | add.l %a2, %a1 | ||
192 | LEFT8_PW %d3, %d4 | ||
193 | LEFT8_PW %d4, %d5 | ||
194 | LEFT8_PW %d5, %d6 | ||
195 | lsl.l #8, %d6 | ||
196 | lsr.l %d0, %d7 | ||
197 | or.l %d7, %d6 | ||
198 | movem.l %d3-%d6, (%a0) | ||
199 | add.l %a2, %a0 | ||
200 | subq.l #1, %d1 | ||
201 | bne.s 1b | ||
202 | movem.l (%sp), %d2-%d7/%a2 | ||
203 | lea.l (7*4,%sp), %sp | ||
204 | rts | ||
205 | |||
206 | .po16_0: | ||
207 | 1: | ||
208 | movem.l (%a1), %d3-%d6 | ||
209 | add.l %a2, %a1 | ||
210 | movem.l %d3-%d6, (%a0) | ||
211 | add.l %a2, %a0 | ||
212 | subq.l #1, %d1 | ||
213 | bne.s 1b | ||
214 | movem.l (%sp), %d2-%d7/%a2 | ||
215 | lea.l (7*4,%sp), %sp | ||
216 | rts | ||
217 | |||
218 | /*****************************************************************************/ | ||
219 | |||
220 | .macro AVG_PW dW1, dW2 | needs %d0 == 24, clobbers %d1, %d2, | ||
221 | move.l \dW1, %d1 | changes dW1, keeps dW2 | ||
222 | lsl.l #8, \dW1 | ||
223 | move.l \dW2, %d2 | ||
224 | lsr.l %d0, %d2 | ||
225 | or.l %d2, \dW1 | ||
226 | move.l %d1, %d2 | ||
227 | eor.l \dW1, %d1 | ||
228 | and.l %d2, \dW1 | ||
229 | move.l #0xfefefefe, %d2 | ||
230 | and.l %d1, %d2 | ||
231 | eor.l %d2, %d1 | ||
232 | lsr.l #1, %d2 | ||
233 | add.l %d2, \dW1 | ||
234 | add.l %d1, \dW1 | ||
235 | .endm | ||
236 | |||
237 | /*****************************************************************************/ | ||
238 | |||
239 | .align 2 | ||
240 | .global MC_put_x_8 | ||
241 | .type MC_put_x_8, @function | ||
242 | |||
243 | MC_put_x_8: | ||
244 | lea.l (-6*4,%sp), %sp | ||
245 | movem.l %d2-%d6/%a2, (%sp) | save some registers | ||
246 | movem.l (6*4+4,%sp), %a0-%a2| dest, source, stride | ||
247 | move.l (6*4+16,%sp), %d6 | height | ||
248 | move.l %a1, %d0 | ||
249 | and.l #3, %d0 | ||
250 | sub.l %d0, %a1 | ||
251 | jmp.l (2, %pc, %d0.l*4) | ||
252 | bra.w .px8_0 | ||
253 | bra.w .px8_1 | ||
254 | bra.w .px8_2 | ||
255 | | last table entry coincides with target | ||
256 | |||
257 | .px8_3: | ||
258 | moveq.l #24, %d0 | ||
259 | 1: | ||
260 | movem.l (%a1), %d3-%d5 | ||
261 | add.l %a2, %a1 | ||
262 | LEFT24_PW %d3, %d4 | ||
263 | LEFT24_PW %d4, %d5 | ||
264 | lsl.l %d0, %d5 | ||
265 | AVG_PW %d3, %d4 | ||
266 | AVG_PW %d4, %d5 | ||
267 | movem.l %d3-%d4, (%a0) | ||
268 | add.l %a2, %a0 | ||
269 | subq.l #1, %d6 | ||
270 | bne.s 1b | ||
271 | movem.l (%sp), %d2-%d6/%a2 | ||
272 | lea.l (6*4,%sp), %sp | ||
273 | rts | ||
274 | |||
275 | .px8_2: | ||
276 | moveq.l #24, %d0 | ||
277 | 1: | ||
278 | movem.l (%a1), %d3-%d5 | ||
279 | add.l %a2, %a1 | ||
280 | swap %d3 | ||
281 | swap %d4 | ||
282 | move.w %d4, %d3 | ||
283 | swap %d5 | ||
284 | move.w %d5, %d4 | ||
285 | AVG_PW %d3, %d4 | ||
286 | AVG_PW %d4, %d5 | ||
287 | movem.l %d3-%d4, (%a0) | ||
288 | add.l %a2, %a0 | ||
289 | subq.l #1, %d6 | ||
290 | bne.s 1b | ||
291 | movem.l (%sp), %d2-%d6/%a2 | ||
292 | lea.l (6*4,%sp), %sp | ||
293 | rts | ||
294 | |||
295 | .px8_1: | ||
296 | moveq.l #24, %d0 | ||
297 | 1: | ||
298 | movem.l (%a1), %d3-%d5 | ||
299 | add.l %a2, %a1 | ||
300 | LEFT8_PW %d3, %d4 | ||
301 | LEFT8_PW %d4, %d5 | ||
302 | lsl.l #8, %d5 | ||
303 | AVG_PW %d3, %d4 | ||
304 | AVG_PW %d4, %d5 | ||
305 | movem.l %d3-%d4, (%a0) | ||
306 | add.l %a2, %a0 | ||
307 | subq.l #1, %d6 | ||
308 | bne.s 1b | ||
309 | movem.l (%sp), %d2-%d6/%a2 | ||
310 | lea.l (6*4,%sp), %sp | ||
311 | rts | ||
312 | |||
313 | .px8_0: | ||
314 | moveq.l #24, %d0 | ||
315 | 1: | ||
316 | movem.l (%a1), %d3-%d5 | ||
317 | add.l %a2, %a1 | ||
318 | AVG_PW %d3, %d4 | ||
319 | AVG_PW %d4, %d5 | ||
320 | movem.l %d3-%d4, (%a0) | ||
321 | add.l %a2, %a0 | ||
322 | subq.l #1, %d6 | ||
323 | bne.s 1b | ||
324 | movem.l (%sp), %d2-%d6/%a2 | ||
325 | lea.l (6*4,%sp), %sp | ||
326 | rts | ||
327 | |||
328 | /*****************************************************************************/ | ||
329 | |||
330 | .align 2 | ||
331 | .global MC_put_x_16 | ||
332 | .type MC_put_x_16, @function | ||
333 | |||
334 | MC_put_x_16: | ||
335 | lea.l (-8*4,%sp), %sp | ||
336 | movem.l %d2-%d7/%a2-%a3, (%sp) | save some registers | ||
337 | movem.l (8*4+4,%sp), %a0-%a3 | dest, source, stride, height | ||
338 | move.l %a1, %d0 | ||
339 | and.l #3, %d0 | ||
340 | sub.l %d0, %a1 | ||
341 | jmp.l (2, %pc, %d0.l*4) | ||
342 | bra.w .px16_0 | ||
343 | bra.w .px16_1 | ||
344 | bra.w .px16_2 | ||
345 | | last table entry coincides with target | ||
346 | |||
347 | .px16_3: | ||
348 | moveq.l #24, %d0 | ||
349 | 1: | ||
350 | movem.l (%a1), %d3-%d7 | ||
351 | add.l %a2, %a1 | ||
352 | LEFT24_PW %d3, %d4 | ||
353 | LEFT24_PW %d4, %d5 | ||
354 | LEFT24_PW %d5, %d6 | ||
355 | LEFT24_PW %d6, %d7 | ||
356 | lsl.l %d0, %d7 | ||
357 | AVG_PW %d3, %d4 | ||
358 | AVG_PW %d4, %d5 | ||
359 | AVG_PW %d5, %d6 | ||
360 | AVG_PW %d6, %d7 | ||
361 | movem.l %d3-%d6, (%a0) | ||
362 | add.l %a2, %a0 | ||
363 | subq.l #1, %a3 | ||
364 | tst.l %a3 | ||
365 | bne.w 1b | ||
366 | movem.l (%sp), %d2-%d7/%a2-%a3 | ||
367 | lea.l (8*4,%sp), %sp | ||
368 | rts | ||
369 | |||
370 | .px16_2: | ||
371 | moveq.l #24, %d0 | ||
372 | 1: | ||
373 | movem.l (%a1), %d3-%d7 | ||
374 | add.l %a2, %a1 | ||
375 | swap %d3 | ||
376 | swap %d4 | ||
377 | move.w %d4, %d3 | ||
378 | swap %d5 | ||
379 | move.w %d5, %d4 | ||
380 | swap %d6 | ||
381 | move.w %d6, %d5 | ||
382 | swap %d7 | ||
383 | move.w %d7, %d6 | ||
384 | AVG_PW %d3, %d4 | ||
385 | AVG_PW %d4, %d5 | ||
386 | AVG_PW %d5, %d6 | ||
387 | AVG_PW %d6, %d7 | ||
388 | movem.l %d3-%d6, (%a0) | ||
389 | add.l %a2, %a0 | ||
390 | subq.l #1, %a3 | ||
391 | tst.l %a3 | ||
392 | bne.w 1b | ||
393 | movem.l (%sp), %d2-%d7/%a2-%a3 | ||
394 | lea.l (8*4,%sp), %sp | ||
395 | rts | ||
396 | |||
397 | .px16_1: | ||
398 | moveq.l #24, %d0 | ||
399 | 1: | ||
400 | movem.l (%a1), %d3-%d7 | ||
401 | add.l %a2, %a1 | ||
402 | LEFT8_PW %d3, %d4 | ||
403 | LEFT8_PW %d4, %d5 | ||
404 | LEFT8_PW %d5, %d6 | ||
405 | LEFT8_PW %d6, %d7 | ||
406 | lsl.l #8, %d7 | ||
407 | AVG_PW %d3, %d4 | ||
408 | AVG_PW %d4, %d5 | ||
409 | AVG_PW %d5, %d6 | ||
410 | AVG_PW %d6, %d7 | ||
411 | movem.l %d3-%d6, (%a0) | ||
412 | add.l %a2, %a0 | ||
413 | subq.l #1, %a3 | ||
414 | tst.l %a3 | ||
415 | bne.w 1b | ||
416 | movem.l (%sp), %d2-%d7/%a2-%a3 | ||
417 | lea.l (8*4,%sp), %sp | ||
418 | rts | ||
419 | |||
420 | .px16_0: | ||
421 | moveq.l #24, %d0 | ||
422 | 1: | ||
423 | movem.l (%a1), %d3-%d7 | ||
424 | add.l %a2, %a1 | ||
425 | AVG_PW %d3, %d4 | ||
426 | AVG_PW %d4, %d5 | ||
427 | AVG_PW %d5, %d6 | ||
428 | AVG_PW %d6, %d7 | ||
429 | movem.l %d3-%d6, (%a0) | ||
430 | add.l %a2, %a0 | ||
431 | subq.l #1, %a3 | ||
432 | tst.l %a3 | ||
433 | bne.w 1b | ||
434 | movem.l (%sp), %d2-%d7/%a2-%a3 | ||
435 | lea.l (8*4,%sp), %sp | ||
436 | rts | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/mpeg2.h b/apps/plugins/mpegplayer/libmpeg2/mpeg2.h new file mode 100644 index 0000000000..bd14ead96e --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/mpeg2.h | |||
@@ -0,0 +1,223 @@ | |||
1 | /* | ||
2 | * mpeg2.h | ||
3 | * Copyright (C) 2000-2004 Michel Lespinasse <walken@zoy.org> | ||
4 | * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | ||
5 | * | ||
6 | * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. | ||
7 | * See http://libmpeg2.sourceforge.net/ for updates. | ||
8 | * | ||
9 | * mpeg2dec is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * mpeg2dec is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | ||
23 | * $Id$ | ||
24 | * libmpeg2 sync history: | ||
25 | * 2008-07-01 - CVS revision 1.67 | ||
26 | */ | ||
27 | |||
28 | #ifndef MPEG2_H | ||
29 | #define MPEG2_H | ||
30 | |||
31 | #include "mpeg2dec_config.h" | ||
32 | |||
33 | #define MPEG2_VERSION(a,b,c) (((a)<<16)|((b)<<8)|(c)) | ||
34 | #define MPEG2_RELEASE MPEG2_VERSION (0, 5, 0) /* 0.5.0 */ | ||
35 | |||
36 | #define SEQ_FLAG_MPEG2 1 | ||
37 | #define SEQ_FLAG_CONSTRAINED_PARAMETERS 2 | ||
38 | #define SEQ_FLAG_PROGRESSIVE_SEQUENCE 4 | ||
39 | #define SEQ_FLAG_LOW_DELAY 8 | ||
40 | #define SEQ_FLAG_COLOUR_DESCRIPTION 16 | ||
41 | |||
42 | #define SEQ_MASK_VIDEO_FORMAT 0xe0 | ||
43 | #define SEQ_VIDEO_FORMAT_COMPONENT 0x00 | ||
44 | #define SEQ_VIDEO_FORMAT_PAL 0x20 | ||
45 | #define SEQ_VIDEO_FORMAT_NTSC 0x40 | ||
46 | #define SEQ_VIDEO_FORMAT_SECAM 0x60 | ||
47 | #define SEQ_VIDEO_FORMAT_MAC 0x80 | ||
48 | #define SEQ_VIDEO_FORMAT_UNSPECIFIED 0xa0 | ||
49 | |||
50 | typedef struct mpeg2_sequence_s | ||
51 | { | ||
52 | unsigned int width, height; | ||
53 | unsigned int chroma_width, chroma_height; | ||
54 | unsigned int byte_rate; | ||
55 | unsigned int vbv_buffer_size; | ||
56 | uint32_t flags; | ||
57 | |||
58 | unsigned int picture_width, picture_height; | ||
59 | unsigned int display_width, display_height; | ||
60 | unsigned int pixel_width, pixel_height; | ||
61 | unsigned int frame_period; | ||
62 | |||
63 | uint8_t profile_level_id; | ||
64 | uint8_t colour_primaries; | ||
65 | uint8_t transfer_characteristics; | ||
66 | uint8_t matrix_coefficients; | ||
67 | } mpeg2_sequence_t; | ||
68 | |||
69 | #define GOP_FLAG_DROP_FRAME 1 | ||
70 | #define GOP_FLAG_BROKEN_LINK 2 | ||
71 | #define GOP_FLAG_CLOSED_GOP 4 | ||
72 | |||
73 | typedef struct mpeg2_gop_s | ||
74 | { | ||
75 | uint8_t hours; | ||
76 | uint8_t minutes; | ||
77 | uint8_t seconds; | ||
78 | uint8_t pictures; | ||
79 | uint32_t flags; | ||
80 | } mpeg2_gop_t; | ||
81 | |||
82 | #define PIC_MASK_CODING_TYPE 7 | ||
83 | #define PIC_FLAG_CODING_TYPE_I 1 | ||
84 | #define PIC_FLAG_CODING_TYPE_P 2 | ||
85 | #define PIC_FLAG_CODING_TYPE_B 3 | ||
86 | #define PIC_FLAG_CODING_TYPE_D 4 | ||
87 | |||
88 | #define PIC_FLAG_TOP_FIELD_FIRST 8 | ||
89 | #define PIC_FLAG_PROGRESSIVE_FRAME 16 | ||
90 | #define PIC_FLAG_COMPOSITE_DISPLAY 32 | ||
91 | #define PIC_FLAG_SKIP 64 | ||
92 | #define PIC_FLAG_TAGS 128 | ||
93 | #define PIC_MASK_COMPOSITE_DISPLAY 0xfffff000 | ||
94 | |||
95 | typedef struct mpeg2_picture_s | ||
96 | { | ||
97 | unsigned int temporal_reference; | ||
98 | unsigned int nb_fields; | ||
99 | uint32_t tag, tag2; | ||
100 | uint32_t flags; | ||
101 | struct | ||
102 | { | ||
103 | int x, y; | ||
104 | } display_offset[3]; | ||
105 | } mpeg2_picture_t; | ||
106 | |||
107 | typedef struct mpeg2_fbuf_s | ||
108 | { | ||
109 | uint8_t * buf[MPEG2_COMPONENTS]; | ||
110 | void * id; | ||
111 | } mpeg2_fbuf_t; | ||
112 | |||
113 | typedef struct mpeg2_info_s | ||
114 | { | ||
115 | const mpeg2_sequence_t * sequence; | ||
116 | const mpeg2_gop_t * gop; | ||
117 | const mpeg2_picture_t * current_picture; | ||
118 | const mpeg2_picture_t * current_picture_2nd; | ||
119 | const mpeg2_fbuf_t * current_fbuf; | ||
120 | const mpeg2_picture_t * display_picture; | ||
121 | const mpeg2_picture_t * display_picture_2nd; | ||
122 | const mpeg2_fbuf_t * display_fbuf; | ||
123 | const mpeg2_fbuf_t * discard_fbuf; | ||
124 | const uint8_t * user_data; | ||
125 | unsigned int user_data_len; | ||
126 | } mpeg2_info_t; | ||
127 | |||
128 | typedef struct mpeg2dec_s mpeg2dec_t; | ||
129 | typedef struct mpeg2_decoder_s mpeg2_decoder_t; | ||
130 | |||
131 | typedef enum | ||
132 | { | ||
133 | STATE_INTERNAL_NORETURN = -1, | ||
134 | STATE_BUFFER = 0, | ||
135 | STATE_SEQUENCE = 1, | ||
136 | STATE_SEQUENCE_REPEATED = 2, | ||
137 | STATE_SEQUENCE_MODIFIED = 3, | ||
138 | STATE_GOP = 4, | ||
139 | STATE_PICTURE = 5, | ||
140 | STATE_SLICE_1ST = 6, | ||
141 | STATE_PICTURE_2ND = 7, | ||
142 | STATE_SLICE = 8, | ||
143 | STATE_END = 9, | ||
144 | STATE_INVALID = 10, | ||
145 | STATE_INVALID_END = 11, | ||
146 | } mpeg2_state_t; | ||
147 | |||
148 | typedef struct mpeg2_convert_init_s | ||
149 | { | ||
150 | unsigned int id_size; | ||
151 | unsigned int buf_size[MPEG2_COMPONENTS]; | ||
152 | void (* start)(void * id, const mpeg2_fbuf_t * fbuf, | ||
153 | const mpeg2_picture_t * picture, const mpeg2_gop_t * gop); | ||
154 | void (* copy)(void * id, uint8_t * const * src, unsigned int v_offset); | ||
155 | } mpeg2_convert_init_t; | ||
156 | |||
157 | typedef enum | ||
158 | { | ||
159 | MPEG2_CONVERT_SET = 0, | ||
160 | MPEG2_CONVERT_STRIDE = 1, | ||
161 | MPEG2_CONVERT_START = 2 | ||
162 | } mpeg2_convert_stage_t; | ||
163 | |||
164 | typedef int mpeg2_convert_t (int stage, void * id, | ||
165 | const mpeg2_sequence_t * sequence, int stride, | ||
166 | void * arg, mpeg2_convert_init_t * result); | ||
167 | int mpeg2_convert (mpeg2dec_t * mpeg2dec, mpeg2_convert_t convert, void * arg); | ||
168 | int mpeg2_stride (mpeg2dec_t * mpeg2dec, int stride); | ||
169 | void mpeg2_set_buf (mpeg2dec_t * mpeg2dec, uint8_t * buf[MPEG2_COMPONENTS], | ||
170 | void * id); | ||
171 | void mpeg2_custom_fbuf (mpeg2dec_t * mpeg2dec, int custom_fbuf); | ||
172 | |||
173 | mpeg2dec_t * mpeg2_init (void); | ||
174 | const mpeg2_info_t * mpeg2_info (mpeg2dec_t * mpeg2dec); | ||
175 | void mpeg2_close (mpeg2dec_t * mpeg2dec); | ||
176 | |||
177 | void mpeg2_buffer (mpeg2dec_t * mpeg2dec, uint8_t * start, uint8_t * end); | ||
178 | int mpeg2_getpos (mpeg2dec_t * mpeg2dec); | ||
179 | mpeg2_state_t mpeg2_parse (mpeg2dec_t * mpeg2dec); | ||
180 | |||
181 | void mpeg2_reset (mpeg2dec_t * mpeg2dec, int full_reset); | ||
182 | void mpeg2_skip (mpeg2dec_t * mpeg2dec, int skip); | ||
183 | void mpeg2_slice_region (mpeg2dec_t * mpeg2dec, int start, int end); | ||
184 | |||
185 | void mpeg2_tag_picture (mpeg2dec_t * mpeg2dec, uint32_t tag, uint32_t tag2); | ||
186 | |||
187 | void mpeg2_init_fbuf (mpeg2_decoder_t * decoder, | ||
188 | uint8_t * current_fbuf[MPEG2_COMPONENTS], | ||
189 | uint8_t * forward_fbuf[MPEG2_COMPONENTS], | ||
190 | uint8_t * backward_fbuf[MPEG2_COMPONENTS]); | ||
191 | void mpeg2_slice (mpeg2_decoder_t * decoder, int code, const uint8_t * buffer); | ||
192 | |||
193 | int mpeg2_guess_aspect (const mpeg2_sequence_t * sequence, | ||
194 | unsigned int * pixel_width, | ||
195 | unsigned int * pixel_height); | ||
196 | |||
197 | typedef enum | ||
198 | { | ||
199 | MPEG2_ALLOC_MPEG2DEC = 0, | ||
200 | MPEG2_ALLOC_CHUNK = 1, | ||
201 | MPEG2_ALLOC_YUV = 2, | ||
202 | MPEG2_ALLOC_CONVERT_ID = 3, | ||
203 | MPEG2_ALLOC_CONVERTED = 4, | ||
204 | MPEG_ALLOC_CODEC_MALLOC, | ||
205 | MPEG_ALLOC_CODEC_CALLOC, | ||
206 | MPEG_ALLOC_MPEG2_BUFFER, | ||
207 | MPEG_ALLOC_AUDIOBUF, | ||
208 | MPEG_ALLOC_PCMOUT, | ||
209 | MPEG_ALLOC_DISKBUF, | ||
210 | __MPEG_ALLOC_FIRST = -256, | ||
211 | } mpeg2_alloc_t; | ||
212 | |||
213 | void * mpeg2_malloc (unsigned size, mpeg2_alloc_t reason); | ||
214 | #if 0 | ||
215 | void mpeg2_free (void * buf); | ||
216 | #endif | ||
217 | /* allocates a dedicated buffer and locks all previous allocation in place */ | ||
218 | void * mpeg2_bufalloc(unsigned size, mpeg2_alloc_t reason); | ||
219 | /* clears all non-dedicated buffer space */ | ||
220 | void mpeg2_mem_reset(void); | ||
221 | void mpeg2_alloc_init(unsigned char* buf, int mallocsize); | ||
222 | |||
223 | #endif /* MPEG2_H */ | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/mpeg2_internal.h b/apps/plugins/mpegplayer/libmpeg2/mpeg2_internal.h new file mode 100644 index 0000000000..e04562e18d --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/mpeg2_internal.h | |||
@@ -0,0 +1,274 @@ | |||
1 | /* | ||
2 | * mpeg2_internal.h | ||
3 | * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> | ||
4 | * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | ||
5 | * | ||
6 | * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. | ||
7 | * See http://libmpeg2.sourceforge.net/ for updates. | ||
8 | * | ||
9 | * mpeg2dec is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * mpeg2dec is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | ||
23 | * $Id$ | ||
24 | * libmpeg2 sync history: | ||
25 | * 2008-07-01 - CVS revision 1.89 | ||
26 | */ | ||
27 | #ifndef MPEG2_INTERNAL_H | ||
28 | #define MPEG2_INTERNAL_H | ||
29 | |||
30 | #include "config.h" /* for Rockbox CPU_ #defines */ | ||
31 | |||
32 | /* macroblock modes */ | ||
33 | #define MACROBLOCK_INTRA 1 | ||
34 | #define MACROBLOCK_PATTERN 2 | ||
35 | #define MACROBLOCK_MOTION_BACKWARD 4 | ||
36 | #define MACROBLOCK_MOTION_FORWARD 8 | ||
37 | #define MACROBLOCK_QUANT 16 | ||
38 | #define DCT_TYPE_INTERLACED 32 | ||
39 | /* motion_type */ | ||
40 | #define MOTION_TYPE_SHIFT 6 | ||
41 | #define MC_FIELD 1 | ||
42 | #define MC_FRAME 2 | ||
43 | #define MC_16X8 2 | ||
44 | #define MC_DMV 3 | ||
45 | |||
46 | /* picture structure */ | ||
47 | #define TOP_FIELD 1 | ||
48 | #define BOTTOM_FIELD 2 | ||
49 | #define FRAME_PICTURE 3 | ||
50 | |||
51 | /* picture coding type */ | ||
52 | #define I_TYPE 1 | ||
53 | #define P_TYPE 2 | ||
54 | #define B_TYPE 3 | ||
55 | #define D_TYPE 4 | ||
56 | |||
57 | typedef void mpeg2_mc_fct (uint8_t *, const uint8_t *, int, int); | ||
58 | |||
59 | typedef struct | ||
60 | { | ||
61 | uint8_t * ref[2][MPEG2_COMPONENTS]; | ||
62 | uint8_t ** ref2[2]; | ||
63 | int pmv[2][2]; | ||
64 | int f_code[2]; | ||
65 | } motion_t; | ||
66 | |||
67 | typedef void motion_parser_t(mpeg2_decoder_t * decoder, | ||
68 | motion_t * motion, | ||
69 | mpeg2_mc_fct * const * table); | ||
70 | |||
71 | struct mpeg2_decoder_s | ||
72 | { | ||
73 | /* first, state that carries information from one macroblock to the */ | ||
74 | /* next inside a slice, and is never used outside of mpeg2_slice() */ | ||
75 | |||
76 | /* bit parsing stuff */ | ||
77 | uint32_t bitstream_buf; /* current 32 bit working set */ | ||
78 | int bitstream_bits; /* used bits in working set */ | ||
79 | const uint8_t * bitstream_ptr; /* buffer with stream data */ | ||
80 | |||
81 | uint8_t * dest[MPEG2_COMPONENTS]; | ||
82 | |||
83 | int offset; | ||
84 | int stride; | ||
85 | int uv_stride; | ||
86 | int slice_stride; | ||
87 | int slice_uv_stride; | ||
88 | int stride_frame; | ||
89 | unsigned int limit_x; | ||
90 | unsigned int limit_y_16; | ||
91 | unsigned int limit_y_8; | ||
92 | unsigned int limit_y; | ||
93 | |||
94 | /* Motion vectors */ | ||
95 | /* The f_ and b_ correspond to the forward and backward motion */ | ||
96 | /* predictors */ | ||
97 | motion_t b_motion; | ||
98 | motion_t f_motion; | ||
99 | motion_parser_t * motion_parser[5]; | ||
100 | |||
101 | /* predictor for DC coefficients in intra blocks */ | ||
102 | int16_t dc_dct_pred[MPEG2_COMPONENTS]; | ||
103 | |||
104 | /* DCT coefficients */ | ||
105 | int16_t * DCTblock; /* put buffer separately to have it in IRAM */ | ||
106 | |||
107 | uint8_t * picture_dest[MPEG2_COMPONENTS]; | ||
108 | void (* convert) (void * convert_id, uint8_t * const * src, | ||
109 | unsigned int v_offset); | ||
110 | void * convert_id; | ||
111 | |||
112 | int dmv_offset; | ||
113 | unsigned int v_offset; | ||
114 | |||
115 | /* now non-slice-specific information */ | ||
116 | |||
117 | /* sequence header stuff */ | ||
118 | uint16_t * quantizer_matrix[4]; | ||
119 | uint16_t (* chroma_quantizer[2])[64]; | ||
120 | uint16_t quantizer_prescale[4][32][64]; | ||
121 | |||
122 | /* The width and height of the picture snapped to macroblock units */ | ||
123 | int width; | ||
124 | int height; | ||
125 | int vertical_position_extension; | ||
126 | int chroma_format; | ||
127 | |||
128 | /* picture header stuff */ | ||
129 | |||
130 | /* what type of picture this is (I, P, B, D) */ | ||
131 | int coding_type; | ||
132 | |||
133 | /* picture coding extension stuff */ | ||
134 | |||
135 | /* quantization factor for intra dc coefficients */ | ||
136 | int intra_dc_precision; | ||
137 | /* top/bottom/both fields */ | ||
138 | int picture_structure; | ||
139 | /* bool to indicate all predictions are frame based */ | ||
140 | int frame_pred_frame_dct; | ||
141 | /* bool to indicate whether intra blocks have motion vectors */ | ||
142 | /* (for concealment) */ | ||
143 | int concealment_motion_vectors; | ||
144 | /* bool to use different vlc tables */ | ||
145 | int intra_vlc_format; | ||
146 | /* used for DMV MC */ | ||
147 | int top_field_first; | ||
148 | |||
149 | /* stuff derived from bitstream */ | ||
150 | |||
151 | /* pointer to the zigzag scan we're supposed to be using */ | ||
152 | const uint8_t * scan; | ||
153 | |||
154 | int second_field; | ||
155 | |||
156 | int mpeg1; | ||
157 | }; | ||
158 | |||
159 | typedef struct | ||
160 | { | ||
161 | mpeg2_fbuf_t fbuf; | ||
162 | } fbuf_alloc_t; | ||
163 | |||
164 | struct mpeg2dec_s | ||
165 | { | ||
166 | mpeg2_decoder_t decoder; | ||
167 | |||
168 | mpeg2_info_t info; | ||
169 | |||
170 | uint32_t shift; | ||
171 | int is_display_initialized; | ||
172 | mpeg2_state_t (* action) (struct mpeg2dec_s * mpeg2dec); | ||
173 | mpeg2_state_t state; | ||
174 | uint32_t ext_state; | ||
175 | |||
176 | /* allocated in init - gcc has problems allocating such big structures */ | ||
177 | uint8_t * ATTR_ALIGN(4) chunk_buffer; | ||
178 | /* pointer to start of the current chunk */ | ||
179 | uint8_t * chunk_start; | ||
180 | /* pointer to current position in chunk_buffer */ | ||
181 | uint8_t * chunk_ptr; | ||
182 | /* last start code ? */ | ||
183 | uint8_t code; | ||
184 | |||
185 | /* picture tags */ | ||
186 | uint32_t tag_current, tag2_current, tag_previous, tag2_previous; | ||
187 | int num_tags; | ||
188 | int bytes_since_tag; | ||
189 | |||
190 | int first; | ||
191 | int alloc_index_user; | ||
192 | int alloc_index; | ||
193 | uint8_t first_decode_slice; | ||
194 | uint8_t nb_decode_slices; | ||
195 | |||
196 | unsigned int user_data_len; | ||
197 | |||
198 | mpeg2_sequence_t new_sequence; | ||
199 | mpeg2_sequence_t sequence; | ||
200 | mpeg2_gop_t new_gop; | ||
201 | mpeg2_gop_t gop; | ||
202 | mpeg2_picture_t new_picture; | ||
203 | mpeg2_picture_t pictures[4]; | ||
204 | mpeg2_picture_t * picture; | ||
205 | /*const*/ mpeg2_fbuf_t * fbuf[3]; /* 0: current fbuf, 1-2: prediction fbufs */ | ||
206 | |||
207 | fbuf_alloc_t fbuf_alloc[3]; | ||
208 | int custom_fbuf; | ||
209 | |||
210 | uint8_t * yuv_buf[3][MPEG2_COMPONENTS]; | ||
211 | int yuv_index; | ||
212 | mpeg2_convert_t * convert; | ||
213 | void * convert_arg; | ||
214 | unsigned int convert_id_size; | ||
215 | int convert_stride; | ||
216 | void (* convert_start) (void * id, const mpeg2_fbuf_t * fbuf, | ||
217 | const mpeg2_picture_t * picture, | ||
218 | const mpeg2_gop_t * gop); | ||
219 | |||
220 | uint8_t * buf_start; | ||
221 | uint8_t * buf_end; | ||
222 | |||
223 | int16_t display_offset_x, display_offset_y; | ||
224 | |||
225 | int copy_matrix; | ||
226 | int8_t q_scale_type, scaled[4]; | ||
227 | uint8_t quantizer_matrix[4][64]; | ||
228 | uint8_t new_quantizer_matrix[4][64]; | ||
229 | }; | ||
230 | |||
231 | /* decode.c */ | ||
232 | mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec); | ||
233 | mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec); | ||
234 | |||
235 | /* header.c */ | ||
236 | void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec); | ||
237 | void mpeg2_reset_info (mpeg2_info_t * info); | ||
238 | int mpeg2_header_sequence (mpeg2dec_t * mpeg2dec); | ||
239 | int mpeg2_header_gop (mpeg2dec_t * mpeg2dec); | ||
240 | int mpeg2_header_picture (mpeg2dec_t * mpeg2dec); | ||
241 | int mpeg2_header_extension (mpeg2dec_t * mpeg2dec); | ||
242 | int mpeg2_header_user_data (mpeg2dec_t * mpeg2dec); | ||
243 | void mpeg2_header_sequence_finalize (mpeg2dec_t * mpeg2dec); | ||
244 | void mpeg2_header_gop_finalize (mpeg2dec_t * mpeg2dec); | ||
245 | void mpeg2_header_picture_finalize (mpeg2dec_t * mpeg2dec); | ||
246 | mpeg2_state_t mpeg2_header_slice_start (mpeg2dec_t * mpeg2dec); | ||
247 | mpeg2_state_t mpeg2_header_end (mpeg2dec_t * mpeg2dec); | ||
248 | void mpeg2_set_fbuf (mpeg2dec_t * mpeg2dec, int b_type); | ||
249 | |||
250 | /* idct.c */ | ||
251 | void mpeg2_idct_init (void); | ||
252 | void mpeg2_idct_copy(int16_t * block, uint8_t * dest, | ||
253 | const int stride); | ||
254 | void mpeg2_idct_add(const int last, int16_t * block, | ||
255 | uint8_t * dest, const int stride); | ||
256 | |||
257 | extern const uint8_t default_mpeg2_scan_norm[64]; | ||
258 | extern const uint8_t default_mpeg2_scan_alt[64]; | ||
259 | extern uint8_t mpeg2_scan_norm[64]; | ||
260 | extern uint8_t mpeg2_scan_alt[64]; | ||
261 | |||
262 | /* motion_comp.c */ | ||
263 | void mpeg2_mc_init (void); | ||
264 | |||
265 | typedef struct | ||
266 | { | ||
267 | mpeg2_mc_fct * put [8]; | ||
268 | mpeg2_mc_fct * avg [8]; | ||
269 | } mpeg2_mc_t; | ||
270 | |||
271 | extern const mpeg2_mc_t mpeg2_mc; | ||
272 | |||
273 | #endif /* MPEG2_INTERNAL_H */ | ||
274 | |||
diff --git a/apps/plugins/mpegplayer/libmpeg2/mpeg2dec_config.h b/apps/plugins/mpegplayer/libmpeg2/mpeg2dec_config.h new file mode 100644 index 0000000000..c34ee374df --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/mpeg2dec_config.h | |||
@@ -0,0 +1,15 @@ | |||
1 | /* $Id$ */ | ||
2 | #ifndef MPEG2DEC_CONFIG_H | ||
3 | #define MPEG2DEC_CONFIG_H | ||
4 | |||
5 | #define ATTRIBUTE_ALIGNED_MAX 16 | ||
6 | |||
7 | #ifdef HAVE_LCD_COLOR | ||
8 | #define MPEG2_COLOR 1 | ||
9 | #define MPEG2_COMPONENTS 3 | ||
10 | #else | ||
11 | #define MPEG2_COLOR 0 | ||
12 | #define MPEG2_COMPONENTS 1 | ||
13 | #endif | ||
14 | |||
15 | #endif /* MPEG2DEC_CONFIG_H */ | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/slice.c b/apps/plugins/mpegplayer/libmpeg2/slice.c new file mode 100644 index 0000000000..926333d5d0 --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/slice.c | |||
@@ -0,0 +1,2898 @@ | |||
1 | /* | ||
2 | * slice.c | ||
3 | * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> | ||
4 | * Copyright (C) 2003 Peter Gubanov <peter@elecard.net.ru> | ||
5 | * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | ||
6 | * | ||
7 | * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. | ||
8 | * See http://libmpeg2.sourceforge.net/ for updates. | ||
9 | * | ||
10 | * mpeg2dec is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * mpeg2dec is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | * | ||
24 | * $Id$ | ||
25 | * libmpeg2 sync history: | ||
26 | * 2008-07-01 - CVS revision 1.55 | ||
27 | */ | ||
28 | |||
29 | #include "plugin.h" | ||
30 | |||
31 | #include "mpeg2dec_config.h" | ||
32 | |||
33 | #include "mpeg2.h" | ||
34 | #include "attributes.h" | ||
35 | #include "mpeg2_internal.h" | ||
36 | |||
37 | #include "vlc.h" | ||
38 | |||
39 | static inline int get_macroblock_modes (mpeg2_decoder_t * const decoder) | ||
40 | { | ||
41 | #define bit_buf (decoder->bitstream_buf) | ||
42 | #define bits (decoder->bitstream_bits) | ||
43 | #define bit_ptr (decoder->bitstream_ptr) | ||
44 | |||
45 | int macroblock_modes; | ||
46 | const MBtab * tab; | ||
47 | |||
48 | switch (decoder->coding_type) | ||
49 | { | ||
50 | case I_TYPE: | ||
51 | tab = MB_I + UBITS (bit_buf, 1); | ||
52 | DUMPBITS (bit_buf, bits, tab->len); | ||
53 | macroblock_modes = tab->modes; | ||
54 | |||
55 | if (!(decoder->frame_pred_frame_dct) && | ||
56 | decoder->picture_structure == FRAME_PICTURE) | ||
57 | { | ||
58 | macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; | ||
59 | DUMPBITS (bit_buf, bits, 1); | ||
60 | } | ||
61 | |||
62 | return macroblock_modes; | ||
63 | |||
64 | case P_TYPE: | ||
65 | tab = MB_P + UBITS (bit_buf, 5); | ||
66 | DUMPBITS (bit_buf, bits, tab->len); | ||
67 | macroblock_modes = tab->modes; | ||
68 | |||
69 | if (decoder->picture_structure != FRAME_PICTURE) | ||
70 | { | ||
71 | if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) | ||
72 | { | ||
73 | macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; | ||
74 | DUMPBITS (bit_buf, bits, 2); | ||
75 | } | ||
76 | |||
77 | return macroblock_modes | MACROBLOCK_MOTION_FORWARD; | ||
78 | } | ||
79 | else if (decoder->frame_pred_frame_dct) | ||
80 | { | ||
81 | if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) | ||
82 | macroblock_modes |= MC_FRAME << MOTION_TYPE_SHIFT; | ||
83 | |||
84 | return macroblock_modes | MACROBLOCK_MOTION_FORWARD; | ||
85 | } | ||
86 | else | ||
87 | { | ||
88 | if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) | ||
89 | { | ||
90 | macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; | ||
91 | DUMPBITS (bit_buf, bits, 2); | ||
92 | } | ||
93 | |||
94 | if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) | ||
95 | { | ||
96 | macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; | ||
97 | DUMPBITS (bit_buf, bits, 1); | ||
98 | } | ||
99 | |||
100 | return macroblock_modes | MACROBLOCK_MOTION_FORWARD; | ||
101 | } | ||
102 | |||
103 | case B_TYPE: | ||
104 | tab = MB_B + UBITS (bit_buf, 6); | ||
105 | DUMPBITS (bit_buf, bits, tab->len); | ||
106 | macroblock_modes = tab->modes; | ||
107 | |||
108 | if (decoder->picture_structure != FRAME_PICTURE) | ||
109 | { | ||
110 | if (! (macroblock_modes & MACROBLOCK_INTRA)) | ||
111 | { | ||
112 | macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; | ||
113 | DUMPBITS (bit_buf, bits, 2); | ||
114 | } | ||
115 | |||
116 | return macroblock_modes; | ||
117 | } | ||
118 | else if (decoder->frame_pred_frame_dct) | ||
119 | { | ||
120 | /* if (! (macroblock_modes & MACROBLOCK_INTRA)) */ | ||
121 | macroblock_modes |= MC_FRAME << MOTION_TYPE_SHIFT; | ||
122 | return macroblock_modes; | ||
123 | } | ||
124 | else | ||
125 | { | ||
126 | if (macroblock_modes & MACROBLOCK_INTRA) | ||
127 | goto intra; | ||
128 | |||
129 | macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; | ||
130 | DUMPBITS (bit_buf, bits, 2); | ||
131 | |||
132 | if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) | ||
133 | { | ||
134 | intra: | ||
135 | macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; | ||
136 | DUMPBITS (bit_buf, bits, 1); | ||
137 | } | ||
138 | return macroblock_modes; | ||
139 | } | ||
140 | |||
141 | case D_TYPE: | ||
142 | DUMPBITS (bit_buf, bits, 1); | ||
143 | return MACROBLOCK_INTRA; | ||
144 | |||
145 | default: | ||
146 | return 0; | ||
147 | } | ||
148 | #undef bit_buf | ||
149 | #undef bits | ||
150 | #undef bit_ptr | ||
151 | } | ||
152 | |||
153 | static inline void get_quantizer_scale (mpeg2_decoder_t * const decoder) | ||
154 | { | ||
155 | #define bit_buf (decoder->bitstream_buf) | ||
156 | #define bits (decoder->bitstream_bits) | ||
157 | #define bit_ptr (decoder->bitstream_ptr) | ||
158 | |||
159 | int quantizer_scale_code; | ||
160 | |||
161 | quantizer_scale_code = UBITS (bit_buf, 5); | ||
162 | DUMPBITS (bit_buf, bits, 5); | ||
163 | |||
164 | decoder->quantizer_matrix[0] = | ||
165 | decoder->quantizer_prescale[0][quantizer_scale_code]; | ||
166 | |||
167 | decoder->quantizer_matrix[1] = | ||
168 | decoder->quantizer_prescale[1][quantizer_scale_code]; | ||
169 | |||
170 | decoder->quantizer_matrix[2] = | ||
171 | decoder->chroma_quantizer[0][quantizer_scale_code]; | ||
172 | |||
173 | decoder->quantizer_matrix[3] = | ||
174 | decoder->chroma_quantizer[1][quantizer_scale_code]; | ||
175 | #undef bit_buf | ||
176 | #undef bits | ||
177 | #undef bit_ptr | ||
178 | } | ||
179 | |||
180 | static inline int get_motion_delta (mpeg2_decoder_t * const decoder, | ||
181 | const int f_code) | ||
182 | { | ||
183 | #define bit_buf (decoder->bitstream_buf) | ||
184 | #define bits (decoder->bitstream_bits) | ||
185 | #define bit_ptr (decoder->bitstream_ptr) | ||
186 | |||
187 | int delta; | ||
188 | int sign; | ||
189 | const MVtab * tab; | ||
190 | |||
191 | if (bit_buf & 0x80000000) | ||
192 | { | ||
193 | DUMPBITS (bit_buf, bits, 1); | ||
194 | return 0; | ||
195 | } | ||
196 | else if (bit_buf >= 0x0c000000) | ||
197 | { | ||
198 | tab = MV_4 + UBITS (bit_buf, 4); | ||
199 | delta = (tab->delta << f_code) + 1; | ||
200 | bits += tab->len + f_code + 1; | ||
201 | bit_buf <<= tab->len; | ||
202 | |||
203 | sign = SBITS (bit_buf, 1); | ||
204 | bit_buf <<= 1; | ||
205 | |||
206 | if (f_code) | ||
207 | delta += UBITS (bit_buf, f_code); | ||
208 | bit_buf <<= f_code; | ||
209 | |||
210 | return (delta ^ sign) - sign; | ||
211 | } | ||
212 | else | ||
213 | { | ||
214 | tab = MV_10 + UBITS (bit_buf, 10); | ||
215 | delta = (tab->delta << f_code) + 1; | ||
216 | bits += tab->len + 1; | ||
217 | bit_buf <<= tab->len; | ||
218 | |||
219 | sign = SBITS (bit_buf, 1); | ||
220 | bit_buf <<= 1; | ||
221 | |||
222 | if (f_code) | ||
223 | { | ||
224 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
225 | delta += UBITS (bit_buf, f_code); | ||
226 | DUMPBITS (bit_buf, bits, f_code); | ||
227 | } | ||
228 | |||
229 | return (delta ^ sign) - sign; | ||
230 | |||
231 | } | ||
232 | #undef bit_buf | ||
233 | #undef bits | ||
234 | #undef bit_ptr | ||
235 | } | ||
236 | |||
237 | static inline int bound_motion_vector (const int vector, const int f_code) | ||
238 | { | ||
239 | return ((int32_t)vector << (27 - f_code)) >> (27 - f_code); | ||
240 | } | ||
241 | |||
242 | static inline int get_dmv (mpeg2_decoder_t * const decoder) | ||
243 | { | ||
244 | #define bit_buf (decoder->bitstream_buf) | ||
245 | #define bits (decoder->bitstream_bits) | ||
246 | #define bit_ptr (decoder->bitstream_ptr) | ||
247 | |||
248 | const DMVtab * tab; | ||
249 | |||
250 | tab = DMV_2 + UBITS (bit_buf, 2); | ||
251 | DUMPBITS (bit_buf, bits, tab->len); | ||
252 | return tab->dmv; | ||
253 | |||
254 | #undef bit_buf | ||
255 | #undef bits | ||
256 | #undef bit_ptr | ||
257 | } | ||
258 | |||
259 | static inline int get_coded_block_pattern (mpeg2_decoder_t * const decoder) | ||
260 | { | ||
261 | #define bit_buf (decoder->bitstream_buf) | ||
262 | #define bits (decoder->bitstream_bits) | ||
263 | #define bit_ptr (decoder->bitstream_ptr) | ||
264 | |||
265 | const CBPtab * tab; | ||
266 | |||
267 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
268 | |||
269 | if (bit_buf >= 0x20000000) | ||
270 | { | ||
271 | tab = CBP_7 + (UBITS (bit_buf, 7) - 16); | ||
272 | DUMPBITS (bit_buf, bits, tab->len); | ||
273 | return tab->cbp; | ||
274 | } | ||
275 | else | ||
276 | { | ||
277 | tab = CBP_9 + UBITS (bit_buf, 9); | ||
278 | DUMPBITS (bit_buf, bits, tab->len); | ||
279 | return tab->cbp; | ||
280 | } | ||
281 | |||
282 | #undef bit_buf | ||
283 | #undef bits | ||
284 | #undef bit_ptr | ||
285 | } | ||
286 | |||
287 | static inline int get_luma_dc_dct_diff (mpeg2_decoder_t * const decoder) | ||
288 | { | ||
289 | #define bit_buf (decoder->bitstream_buf) | ||
290 | #define bits (decoder->bitstream_bits) | ||
291 | #define bit_ptr (decoder->bitstream_ptr) | ||
292 | |||
293 | const DCtab * tab; | ||
294 | int size; | ||
295 | int dc_diff; | ||
296 | |||
297 | if (bit_buf < 0xf8000000) | ||
298 | { | ||
299 | tab = DC_lum_5 + UBITS (bit_buf, 5); | ||
300 | size = tab->size; | ||
301 | |||
302 | if (size) | ||
303 | { | ||
304 | bits += tab->len + size; | ||
305 | bit_buf <<= tab->len; | ||
306 | dc_diff = | ||
307 | UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size); | ||
308 | bit_buf <<= size; | ||
309 | return dc_diff << decoder->intra_dc_precision; | ||
310 | } | ||
311 | else | ||
312 | { | ||
313 | DUMPBITS (bit_buf, bits, 3); | ||
314 | return 0; | ||
315 | } | ||
316 | } | ||
317 | else | ||
318 | { | ||
319 | tab = DC_long + (UBITS (bit_buf, 9) - 0x1e0); | ||
320 | size = tab->size; | ||
321 | DUMPBITS (bit_buf, bits, tab->len); | ||
322 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
323 | dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size); | ||
324 | DUMPBITS (bit_buf, bits, size); | ||
325 | return dc_diff << decoder->intra_dc_precision; | ||
326 | } | ||
327 | |||
328 | #undef bit_buf | ||
329 | #undef bits | ||
330 | #undef bit_ptr | ||
331 | } | ||
332 | |||
333 | #if MPEG2_COLOR | ||
334 | static inline int get_chroma_dc_dct_diff (mpeg2_decoder_t * const decoder) | ||
335 | { | ||
336 | #define bit_buf (decoder->bitstream_buf) | ||
337 | #define bits (decoder->bitstream_bits) | ||
338 | #define bit_ptr (decoder->bitstream_ptr) | ||
339 | |||
340 | const DCtab * tab; | ||
341 | int size; | ||
342 | int dc_diff; | ||
343 | |||
344 | if (bit_buf < 0xf8000000) | ||
345 | { | ||
346 | tab = DC_chrom_5 + UBITS (bit_buf, 5); | ||
347 | size = tab->size; | ||
348 | |||
349 | if (size) | ||
350 | { | ||
351 | bits += tab->len + size; | ||
352 | bit_buf <<= tab->len; | ||
353 | dc_diff = | ||
354 | UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size); | ||
355 | bit_buf <<= size; | ||
356 | return dc_diff << decoder->intra_dc_precision; | ||
357 | } | ||
358 | else | ||
359 | { | ||
360 | DUMPBITS (bit_buf, bits, 2); | ||
361 | return 0; | ||
362 | } | ||
363 | } | ||
364 | else | ||
365 | { | ||
366 | tab = DC_long + (UBITS (bit_buf, 10) - 0x3e0); | ||
367 | size = tab->size; | ||
368 | DUMPBITS (bit_buf, bits, tab->len + 1); | ||
369 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
370 | dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size); | ||
371 | DUMPBITS (bit_buf, bits, size); | ||
372 | return dc_diff << decoder->intra_dc_precision; | ||
373 | } | ||
374 | |||
375 | #undef bit_buf | ||
376 | #undef bits | ||
377 | #undef bit_ptr | ||
378 | } | ||
379 | #endif /* MPEG2_COLOR */ | ||
380 | |||
381 | #define SATURATE(val) \ | ||
382 | do { \ | ||
383 | val <<= 4; \ | ||
384 | if (unlikely (val != (int16_t) val)) \ | ||
385 | val = (SBITS (val, 1) ^ 2047) << 4; \ | ||
386 | } while (0) | ||
387 | |||
388 | static void get_intra_block_B14 (mpeg2_decoder_t * const decoder, | ||
389 | const uint16_t * const quant_matrix) | ||
390 | { | ||
391 | uint32_t bit_buf = decoder->bitstream_buf; | ||
392 | int bits = decoder->bitstream_bits; | ||
393 | const uint8_t * bit_ptr = decoder->bitstream_ptr; | ||
394 | const uint8_t * const scan = decoder->scan; | ||
395 | int16_t * const dest = decoder->DCTblock; | ||
396 | int mismatch = ~dest[0]; | ||
397 | int i = 0; | ||
398 | int j; | ||
399 | int val; | ||
400 | const DCTtab * tab; | ||
401 | |||
402 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
403 | |||
404 | while (1) | ||
405 | { | ||
406 | if (bit_buf >= 0x28000000) | ||
407 | { | ||
408 | tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); | ||
409 | |||
410 | i += tab->run; | ||
411 | if (i >= 64) | ||
412 | break; /* end of block */ | ||
413 | |||
414 | normal_code: | ||
415 | j = scan[i]; | ||
416 | bit_buf <<= tab->len; | ||
417 | bits += tab->len + 1; | ||
418 | val = (tab->level * quant_matrix[j]) >> 4; | ||
419 | |||
420 | /* if (bitstream_get (1)) val = -val; */ | ||
421 | val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); | ||
422 | |||
423 | SATURATE (val); | ||
424 | dest[j] = val; | ||
425 | mismatch ^= val; | ||
426 | |||
427 | bit_buf <<= 1; | ||
428 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
429 | |||
430 | continue; | ||
431 | } | ||
432 | else if (bit_buf >= 0x04000000) | ||
433 | { | ||
434 | tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); | ||
435 | |||
436 | i += tab->run; | ||
437 | if (i < 64) | ||
438 | goto normal_code; | ||
439 | |||
440 | /* escape code */ | ||
441 | |||
442 | i += UBITS (bit_buf << 6, 6) - 64; | ||
443 | if (i >= 64) | ||
444 | break; /* illegal, check needed to avoid buffer overflow */ | ||
445 | |||
446 | j = scan[i]; | ||
447 | |||
448 | DUMPBITS (bit_buf, bits, 12); | ||
449 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
450 | val = (SBITS (bit_buf, 12) * quant_matrix[j]) / 16; | ||
451 | |||
452 | SATURATE (val); | ||
453 | dest[j] = val; | ||
454 | mismatch ^= val; | ||
455 | |||
456 | DUMPBITS (bit_buf, bits, 12); | ||
457 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
458 | |||
459 | continue; | ||
460 | } | ||
461 | else if (bit_buf >= 0x02000000) | ||
462 | { | ||
463 | tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); | ||
464 | i += tab->run; | ||
465 | if (i < 64) | ||
466 | goto normal_code; | ||
467 | } | ||
468 | else if (bit_buf >= 0x00800000) | ||
469 | { | ||
470 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); | ||
471 | i += tab->run; | ||
472 | if (i < 64) | ||
473 | goto normal_code; | ||
474 | } | ||
475 | else if (bit_buf >= 0x00200000) | ||
476 | { | ||
477 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); | ||
478 | i += tab->run; | ||
479 | if (i < 64) | ||
480 | goto normal_code; | ||
481 | } | ||
482 | else | ||
483 | { | ||
484 | tab = DCT_16 + UBITS (bit_buf, 16); | ||
485 | bit_buf <<= 16; | ||
486 | GETWORD (bit_buf, bits + 16, bit_ptr); | ||
487 | i += tab->run; | ||
488 | if (i < 64) | ||
489 | goto normal_code; | ||
490 | } | ||
491 | break; /* illegal, check needed to avoid buffer overflow */ | ||
492 | } | ||
493 | |||
494 | dest[63] ^= mismatch & 16; | ||
495 | DUMPBITS (bit_buf, bits, tab->len); /* dump end of block code */ | ||
496 | decoder->bitstream_buf = bit_buf; | ||
497 | decoder->bitstream_bits = bits; | ||
498 | decoder->bitstream_ptr = bit_ptr; | ||
499 | } | ||
500 | |||
501 | static void get_intra_block_B15 (mpeg2_decoder_t * const decoder, | ||
502 | const uint16_t * const quant_matrix) | ||
503 | { | ||
504 | uint32_t bit_buf = decoder->bitstream_buf; | ||
505 | int bits = decoder->bitstream_bits; | ||
506 | const uint8_t * bit_ptr = decoder->bitstream_ptr; | ||
507 | const uint8_t * const scan = decoder->scan; | ||
508 | int16_t * const dest = decoder->DCTblock; | ||
509 | int mismatch = ~dest[0]; | ||
510 | int i = 0; | ||
511 | int j; | ||
512 | int val; | ||
513 | const DCTtab * tab; | ||
514 | |||
515 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
516 | |||
517 | while (1) | ||
518 | { | ||
519 | if (bit_buf >= 0x04000000) | ||
520 | { | ||
521 | tab = DCT_B15_8 + (UBITS (bit_buf, 8) - 4); | ||
522 | |||
523 | i += tab->run; | ||
524 | |||
525 | if (i < 64) | ||
526 | { | ||
527 | normal_code: | ||
528 | j = scan[i]; | ||
529 | bit_buf <<= tab->len; | ||
530 | bits += tab->len + 1; | ||
531 | val = (tab->level * quant_matrix[j]) >> 4; | ||
532 | |||
533 | /* if (bitstream_get (1)) val = -val; */ | ||
534 | val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); | ||
535 | |||
536 | SATURATE (val); | ||
537 | dest[j] = val; | ||
538 | mismatch ^= val; | ||
539 | |||
540 | bit_buf <<= 1; | ||
541 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
542 | |||
543 | continue; | ||
544 | } | ||
545 | else | ||
546 | { | ||
547 | /* end of block. I commented out this code because if we */ | ||
548 | /* dont exit here we will still exit at the later test :) */ | ||
549 | |||
550 | /* if (i >= 128) break; */ /* end of block */ | ||
551 | |||
552 | /* escape code */ | ||
553 | |||
554 | i += UBITS (bit_buf << 6, 6) - 64; | ||
555 | if (i >= 64) | ||
556 | break; /* illegal, check against buffer overflow */ | ||
557 | |||
558 | j = scan[i]; | ||
559 | |||
560 | DUMPBITS (bit_buf, bits, 12); | ||
561 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
562 | val = (SBITS (bit_buf, 12) * quant_matrix[j]) / 16; | ||
563 | |||
564 | SATURATE (val); | ||
565 | dest[j] = val; | ||
566 | mismatch ^= val; | ||
567 | |||
568 | DUMPBITS (bit_buf, bits, 12); | ||
569 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
570 | |||
571 | continue; | ||
572 | } | ||
573 | } | ||
574 | else if (bit_buf >= 0x02000000) | ||
575 | { | ||
576 | tab = DCT_B15_10 + (UBITS (bit_buf, 10) - 8); | ||
577 | i += tab->run; | ||
578 | if (i < 64) | ||
579 | goto normal_code; | ||
580 | } | ||
581 | else if (bit_buf >= 0x00800000) | ||
582 | { | ||
583 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); | ||
584 | i += tab->run; | ||
585 | if (i < 64) | ||
586 | goto normal_code; | ||
587 | } | ||
588 | else if (bit_buf >= 0x00200000) | ||
589 | { | ||
590 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); | ||
591 | i += tab->run; | ||
592 | if (i < 64) | ||
593 | goto normal_code; | ||
594 | } | ||
595 | else | ||
596 | { | ||
597 | tab = DCT_16 + UBITS (bit_buf, 16); | ||
598 | bit_buf <<= 16; | ||
599 | GETWORD (bit_buf, bits + 16, bit_ptr); | ||
600 | i += tab->run; | ||
601 | if (i < 64) | ||
602 | goto normal_code; | ||
603 | } | ||
604 | break; /* illegal, check needed to avoid buffer overflow */ | ||
605 | } | ||
606 | |||
607 | dest[63] ^= mismatch & 16; | ||
608 | DUMPBITS (bit_buf, bits, tab->len); /* dump end of block code */ | ||
609 | decoder->bitstream_buf = bit_buf; | ||
610 | decoder->bitstream_bits = bits; | ||
611 | decoder->bitstream_ptr = bit_ptr; | ||
612 | } | ||
613 | |||
614 | static int get_non_intra_block (mpeg2_decoder_t * const decoder, | ||
615 | const uint16_t * const quant_matrix) | ||
616 | { | ||
617 | uint32_t bit_buf = decoder->bitstream_buf; | ||
618 | int bits = decoder->bitstream_bits; | ||
619 | const uint8_t * bit_ptr = decoder->bitstream_ptr; | ||
620 | const uint8_t * const scan = decoder->scan; | ||
621 | int16_t * const dest = decoder->DCTblock; | ||
622 | int mismatch = -1; | ||
623 | int i = -1; | ||
624 | int j; | ||
625 | int val; | ||
626 | const DCTtab * tab; | ||
627 | |||
628 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
629 | |||
630 | if (bit_buf >= 0x28000000) | ||
631 | { | ||
632 | tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5); | ||
633 | goto entry_1; | ||
634 | } | ||
635 | else | ||
636 | { | ||
637 | goto entry_2; | ||
638 | } | ||
639 | |||
640 | while (1) | ||
641 | { | ||
642 | if (bit_buf >= 0x28000000) | ||
643 | { | ||
644 | tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); | ||
645 | |||
646 | entry_1: | ||
647 | i += tab->run; | ||
648 | if (i >= 64) | ||
649 | break; /* end of block */ | ||
650 | |||
651 | normal_code: | ||
652 | j = scan[i]; | ||
653 | bit_buf <<= tab->len; | ||
654 | bits += tab->len + 1; | ||
655 | val = ((2 * tab->level + 1) * quant_matrix[j]) >> 5; | ||
656 | |||
657 | /* if (bitstream_get (1)) val = -val; */ | ||
658 | val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); | ||
659 | |||
660 | SATURATE (val); | ||
661 | dest[j] = val; | ||
662 | mismatch ^= val; | ||
663 | |||
664 | bit_buf <<= 1; | ||
665 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
666 | |||
667 | continue; | ||
668 | } | ||
669 | |||
670 | entry_2: | ||
671 | if (bit_buf >= 0x04000000) | ||
672 | { | ||
673 | tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); | ||
674 | |||
675 | i += tab->run; | ||
676 | if (i < 64) | ||
677 | goto normal_code; | ||
678 | |||
679 | /* escape code */ | ||
680 | |||
681 | i += UBITS (bit_buf << 6, 6) - 64; | ||
682 | if (i >= 64) | ||
683 | break; /* illegal, check needed to avoid buffer overflow */ | ||
684 | |||
685 | j = scan[i]; | ||
686 | |||
687 | DUMPBITS (bit_buf, bits, 12); | ||
688 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
689 | val = 2 * (SBITS (bit_buf, 12) + SBITS (bit_buf, 1)) + 1; | ||
690 | val = (val * quant_matrix[j]) / 32; | ||
691 | |||
692 | SATURATE (val); | ||
693 | dest[j] = val; | ||
694 | mismatch ^= val; | ||
695 | |||
696 | DUMPBITS (bit_buf, bits, 12); | ||
697 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
698 | |||
699 | continue; | ||
700 | } | ||
701 | else if (bit_buf >= 0x02000000) | ||
702 | { | ||
703 | tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); | ||
704 | i += tab->run; | ||
705 | if (i < 64) | ||
706 | goto normal_code; | ||
707 | } | ||
708 | else if (bit_buf >= 0x00800000) | ||
709 | { | ||
710 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); | ||
711 | i += tab->run; | ||
712 | if (i < 64) | ||
713 | goto normal_code; | ||
714 | } | ||
715 | else if (bit_buf >= 0x00200000) | ||
716 | { | ||
717 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); | ||
718 | i += tab->run; | ||
719 | if (i < 64) | ||
720 | goto normal_code; | ||
721 | } | ||
722 | else | ||
723 | { | ||
724 | tab = DCT_16 + UBITS (bit_buf, 16); | ||
725 | bit_buf <<= 16; | ||
726 | GETWORD (bit_buf, bits + 16, bit_ptr); | ||
727 | i += tab->run; | ||
728 | if (i < 64) | ||
729 | goto normal_code; | ||
730 | } | ||
731 | break; /* illegal, check needed to avoid buffer overflow */ | ||
732 | } | ||
733 | |||
734 | dest[63] ^= mismatch & 16; | ||
735 | DUMPBITS (bit_buf, bits, tab->len); /* dump end of block code */ | ||
736 | decoder->bitstream_buf = bit_buf; | ||
737 | decoder->bitstream_bits = bits; | ||
738 | decoder->bitstream_ptr = bit_ptr; | ||
739 | return i; | ||
740 | } | ||
741 | |||
742 | static void get_mpeg1_intra_block (mpeg2_decoder_t * const decoder) | ||
743 | { | ||
744 | uint32_t bit_buf = decoder->bitstream_buf; | ||
745 | int bits = decoder->bitstream_bits; | ||
746 | const uint8_t * bit_ptr = decoder->bitstream_ptr; | ||
747 | const uint8_t * const scan = decoder->scan; | ||
748 | const uint16_t * const quant_matrix = decoder->quantizer_matrix[0]; | ||
749 | int16_t * const dest = decoder->DCTblock; | ||
750 | int i = 0; | ||
751 | int j; | ||
752 | int val; | ||
753 | const DCTtab * tab; | ||
754 | |||
755 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
756 | |||
757 | while (1) | ||
758 | { | ||
759 | if (bit_buf >= 0x28000000) | ||
760 | { | ||
761 | tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); | ||
762 | |||
763 | i += tab->run; | ||
764 | if (i >= 64) | ||
765 | break; /* end of block */ | ||
766 | |||
767 | normal_code: | ||
768 | j = scan[i]; | ||
769 | bit_buf <<= tab->len; | ||
770 | bits += tab->len + 1; | ||
771 | val = (tab->level * quant_matrix[j]) >> 4; | ||
772 | |||
773 | /* oddification */ | ||
774 | val = (val - 1) | 1; | ||
775 | |||
776 | /* if (bitstream_get (1)) val = -val; */ | ||
777 | val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); | ||
778 | |||
779 | SATURATE (val); | ||
780 | dest[j] = val; | ||
781 | |||
782 | bit_buf <<= 1; | ||
783 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
784 | |||
785 | continue; | ||
786 | } | ||
787 | else if (bit_buf >= 0x04000000) | ||
788 | { | ||
789 | tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); | ||
790 | |||
791 | i += tab->run; | ||
792 | if (i < 64) | ||
793 | goto normal_code; | ||
794 | |||
795 | /* escape code */ | ||
796 | |||
797 | i += UBITS (bit_buf << 6, 6) - 64; | ||
798 | if (i >= 64) | ||
799 | break; /* illegal, check needed to avoid buffer overflow */ | ||
800 | |||
801 | j = scan[i]; | ||
802 | |||
803 | DUMPBITS (bit_buf, bits, 12); | ||
804 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
805 | val = SBITS (bit_buf, 8); | ||
806 | |||
807 | if (! (val & 0x7f)) | ||
808 | { | ||
809 | DUMPBITS (bit_buf, bits, 8); | ||
810 | val = UBITS (bit_buf, 8) + 2 * val; | ||
811 | } | ||
812 | |||
813 | val = (val * quant_matrix[j]) / 16; | ||
814 | |||
815 | /* oddification */ | ||
816 | val = (val + ~SBITS (val, 1)) | 1; | ||
817 | |||
818 | SATURATE (val); | ||
819 | dest[j] = val; | ||
820 | |||
821 | DUMPBITS (bit_buf, bits, 8); | ||
822 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
823 | |||
824 | continue; | ||
825 | } | ||
826 | else if (bit_buf >= 0x02000000) | ||
827 | { | ||
828 | tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); | ||
829 | i += tab->run; | ||
830 | if (i < 64) | ||
831 | goto normal_code; | ||
832 | } | ||
833 | else if (bit_buf >= 0x00800000) | ||
834 | { | ||
835 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); | ||
836 | i += tab->run; | ||
837 | if (i < 64) | ||
838 | goto normal_code; | ||
839 | } | ||
840 | else if (bit_buf >= 0x00200000) | ||
841 | { | ||
842 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); | ||
843 | i += tab->run; | ||
844 | if (i < 64) | ||
845 | goto normal_code; | ||
846 | } | ||
847 | else | ||
848 | { | ||
849 | tab = DCT_16 + UBITS (bit_buf, 16); | ||
850 | bit_buf <<= 16; | ||
851 | GETWORD (bit_buf, bits + 16, bit_ptr); | ||
852 | i += tab->run; | ||
853 | if (i < 64) | ||
854 | goto normal_code; | ||
855 | } | ||
856 | break; /* illegal, check needed to avoid buffer overflow */ | ||
857 | } | ||
858 | |||
859 | DUMPBITS (bit_buf, bits, tab->len); /* dump end of block code */ | ||
860 | decoder->bitstream_buf = bit_buf; | ||
861 | decoder->bitstream_bits = bits; | ||
862 | decoder->bitstream_ptr = bit_ptr; | ||
863 | } | ||
864 | |||
865 | static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder) | ||
866 | { | ||
867 | uint32_t bit_buf = decoder->bitstream_buf; | ||
868 | int bits = decoder->bitstream_bits; | ||
869 | const uint8_t * bit_ptr = decoder->bitstream_ptr; | ||
870 | const uint8_t * const scan = decoder->scan; | ||
871 | const uint16_t * const quant_matrix = decoder->quantizer_matrix[1]; | ||
872 | int16_t * const dest = decoder->DCTblock; | ||
873 | int i = -1; | ||
874 | int j; | ||
875 | int val; | ||
876 | const DCTtab * tab; | ||
877 | |||
878 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
879 | if (bit_buf >= 0x28000000) | ||
880 | { | ||
881 | tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5); | ||
882 | goto entry_1; | ||
883 | } | ||
884 | else | ||
885 | { | ||
886 | goto entry_2; | ||
887 | } | ||
888 | |||
889 | while (1) | ||
890 | { | ||
891 | if (bit_buf >= 0x28000000) | ||
892 | { | ||
893 | tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); | ||
894 | |||
895 | entry_1: | ||
896 | i += tab->run; | ||
897 | if (i >= 64) | ||
898 | break; /* end of block */ | ||
899 | |||
900 | normal_code: | ||
901 | j = scan[i]; | ||
902 | bit_buf <<= tab->len; | ||
903 | bits += tab->len + 1; | ||
904 | val = ((2 * tab->level + 1) * quant_matrix[j]) >> 5; | ||
905 | |||
906 | /* oddification */ | ||
907 | val = (val - 1) | 1; | ||
908 | |||
909 | /* if (bitstream_get (1)) val = -val; */ | ||
910 | val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); | ||
911 | |||
912 | SATURATE (val); | ||
913 | dest[j] = val; | ||
914 | |||
915 | bit_buf <<= 1; | ||
916 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
917 | |||
918 | continue; | ||
919 | } | ||
920 | |||
921 | entry_2: | ||
922 | if (bit_buf >= 0x04000000) | ||
923 | { | ||
924 | tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); | ||
925 | |||
926 | i += tab->run; | ||
927 | if (i < 64) | ||
928 | goto normal_code; | ||
929 | |||
930 | /* escape code */ | ||
931 | |||
932 | i += UBITS (bit_buf << 6, 6) - 64; | ||
933 | if (i >= 64) | ||
934 | break; /* illegal, check needed to avoid buffer overflow */ | ||
935 | |||
936 | j = scan[i]; | ||
937 | |||
938 | DUMPBITS (bit_buf, bits, 12); | ||
939 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
940 | val = SBITS (bit_buf, 8); | ||
941 | |||
942 | if (! (val & 0x7f)) | ||
943 | { | ||
944 | DUMPBITS (bit_buf, bits, 8); | ||
945 | val = UBITS (bit_buf, 8) + 2 * val; | ||
946 | } | ||
947 | |||
948 | val = 2 * (val + SBITS (val, 1)) + 1; | ||
949 | val = (val * quant_matrix[j]) / 32; | ||
950 | |||
951 | /* oddification */ | ||
952 | val = (val + ~SBITS (val, 1)) | 1; | ||
953 | |||
954 | SATURATE (val); | ||
955 | dest[j] = val; | ||
956 | |||
957 | DUMPBITS (bit_buf, bits, 8); | ||
958 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
959 | |||
960 | continue; | ||
961 | |||
962 | } | ||
963 | else if (bit_buf >= 0x02000000) | ||
964 | { | ||
965 | tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); | ||
966 | i += tab->run; | ||
967 | if (i < 64) | ||
968 | goto normal_code; | ||
969 | } | ||
970 | else if (bit_buf >= 0x00800000) | ||
971 | { | ||
972 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); | ||
973 | i += tab->run; | ||
974 | if (i < 64) | ||
975 | goto normal_code; | ||
976 | } | ||
977 | else if (bit_buf >= 0x00200000) | ||
978 | { | ||
979 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); | ||
980 | i += tab->run; | ||
981 | if (i < 64) | ||
982 | goto normal_code; | ||
983 | } | ||
984 | else | ||
985 | { | ||
986 | tab = DCT_16 + UBITS (bit_buf, 16); | ||
987 | bit_buf <<= 16; | ||
988 | GETWORD (bit_buf, bits + 16, bit_ptr); | ||
989 | i += tab->run; | ||
990 | if (i < 64) | ||
991 | goto normal_code; | ||
992 | } | ||
993 | break; /* illegal, check needed to avoid buffer overflow */ | ||
994 | } | ||
995 | |||
996 | DUMPBITS (bit_buf, bits, tab->len); /* dump end of block code */ | ||
997 | decoder->bitstream_buf = bit_buf; | ||
998 | decoder->bitstream_bits = bits; | ||
999 | decoder->bitstream_ptr = bit_ptr; | ||
1000 | return i; | ||
1001 | } | ||
1002 | |||
1003 | static inline void slice_intra_DCT (mpeg2_decoder_t * const decoder, | ||
1004 | const int cc, | ||
1005 | uint8_t * const dest, const int stride) | ||
1006 | { | ||
1007 | #define bit_buf (decoder->bitstream_buf) | ||
1008 | #define bits (decoder->bitstream_bits) | ||
1009 | #define bit_ptr (decoder->bitstream_ptr) | ||
1010 | |||
1011 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1012 | /* Get the intra DC coefficient and inverse quantize it */ | ||
1013 | if (cc == 0) | ||
1014 | { | ||
1015 | decoder->dc_dct_pred[0] += get_luma_dc_dct_diff (decoder); | ||
1016 | decoder->DCTblock[0] = decoder->dc_dct_pred[0]; | ||
1017 | |||
1018 | } | ||
1019 | #if MPEG2_COLOR | ||
1020 | else | ||
1021 | { | ||
1022 | decoder->dc_dct_pred[cc] += get_chroma_dc_dct_diff (decoder); | ||
1023 | decoder->DCTblock[0] = decoder->dc_dct_pred[cc]; | ||
1024 | } | ||
1025 | #endif | ||
1026 | |||
1027 | if (decoder->mpeg1) | ||
1028 | { | ||
1029 | if (decoder->coding_type != D_TYPE) | ||
1030 | get_mpeg1_intra_block (decoder); | ||
1031 | } | ||
1032 | else if (decoder->intra_vlc_format) | ||
1033 | { | ||
1034 | get_intra_block_B15 (decoder, decoder->quantizer_matrix[cc ? 2 : 0]); | ||
1035 | } | ||
1036 | else | ||
1037 | { | ||
1038 | get_intra_block_B14 (decoder, decoder->quantizer_matrix[cc ? 2 : 0]); | ||
1039 | } | ||
1040 | |||
1041 | mpeg2_idct_copy (decoder->DCTblock, dest, stride); | ||
1042 | |||
1043 | #undef bit_buf | ||
1044 | #undef bits | ||
1045 | #undef bit_ptr | ||
1046 | } | ||
1047 | |||
1048 | static inline void slice_non_intra_DCT (mpeg2_decoder_t * const decoder, | ||
1049 | const int cc, | ||
1050 | uint8_t * const dest, const int stride) | ||
1051 | { | ||
1052 | int last; | ||
1053 | |||
1054 | if (decoder->mpeg1) | ||
1055 | { | ||
1056 | last = get_mpeg1_non_intra_block (decoder); | ||
1057 | } | ||
1058 | else | ||
1059 | { | ||
1060 | last = get_non_intra_block (decoder, | ||
1061 | decoder->quantizer_matrix[cc ? 3 : 1]); | ||
1062 | } | ||
1063 | |||
1064 | mpeg2_idct_add (last, decoder->DCTblock, dest, stride); | ||
1065 | } | ||
1066 | |||
1067 | #if !MPEG2_COLOR | ||
1068 | static void skip_mpeg1_intra_block (mpeg2_decoder_t * const decoder) | ||
1069 | { | ||
1070 | uint32_t bit_buf = decoder->bitstream_buf; | ||
1071 | int bits = decoder->bitstream_bits; | ||
1072 | const uint8_t * bit_ptr = decoder->bitstream_ptr; | ||
1073 | int i = 0; | ||
1074 | const DCTtab * tab; | ||
1075 | |||
1076 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1077 | |||
1078 | while (1) | ||
1079 | { | ||
1080 | if (bit_buf >= 0x28000000) | ||
1081 | { | ||
1082 | tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); | ||
1083 | |||
1084 | i += tab->run; | ||
1085 | if (i >= 64) | ||
1086 | break; /* end of block */ | ||
1087 | |||
1088 | normal_code: | ||
1089 | bit_buf <<= tab->len + 1; | ||
1090 | bits += tab->len + 1; | ||
1091 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1092 | continue; | ||
1093 | } | ||
1094 | else if (bit_buf >= 0x04000000) | ||
1095 | { | ||
1096 | tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); | ||
1097 | |||
1098 | i += tab->run; | ||
1099 | if (i < 64) | ||
1100 | goto normal_code; | ||
1101 | |||
1102 | /* escape code */ | ||
1103 | |||
1104 | i += UBITS (bit_buf << 6, 6) - 64; | ||
1105 | if (i >= 64) | ||
1106 | break; /* illegal, check needed to avoid buffer overflow */ | ||
1107 | |||
1108 | DUMPBITS (bit_buf, bits, 12); | ||
1109 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1110 | |||
1111 | if (!(SBITS (bit_buf, 8) & 0x7f)) | ||
1112 | DUMPBITS (bit_buf, bits, 8); | ||
1113 | |||
1114 | DUMPBITS (bit_buf, bits, 8); | ||
1115 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1116 | |||
1117 | continue; | ||
1118 | } | ||
1119 | else if (bit_buf >= 0x02000000) | ||
1120 | { | ||
1121 | tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); | ||
1122 | i += tab->run; | ||
1123 | if (i < 64) | ||
1124 | goto normal_code; | ||
1125 | } | ||
1126 | else if (bit_buf >= 0x00800000) | ||
1127 | { | ||
1128 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); | ||
1129 | i += tab->run; | ||
1130 | if (i < 64) | ||
1131 | goto normal_code; | ||
1132 | } | ||
1133 | else if (bit_buf >= 0x00200000) | ||
1134 | { | ||
1135 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); | ||
1136 | i += tab->run; | ||
1137 | if (i < 64) | ||
1138 | goto normal_code; | ||
1139 | } | ||
1140 | else | ||
1141 | { | ||
1142 | tab = DCT_16 + UBITS (bit_buf, 16); | ||
1143 | bit_buf <<= 16; | ||
1144 | GETWORD (bit_buf, bits + 16, bit_ptr); | ||
1145 | i += tab->run; | ||
1146 | if (i < 64) | ||
1147 | goto normal_code; | ||
1148 | } | ||
1149 | break; /* illegal, check needed to avoid buffer overflow */ | ||
1150 | } | ||
1151 | |||
1152 | DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ | ||
1153 | decoder->bitstream_buf = bit_buf; | ||
1154 | decoder->bitstream_bits = bits; | ||
1155 | decoder->bitstream_ptr = bit_ptr; | ||
1156 | } | ||
1157 | |||
1158 | static void skip_intra_block_B14 (mpeg2_decoder_t * const decoder) | ||
1159 | { | ||
1160 | uint32_t bit_buf = decoder->bitstream_buf; | ||
1161 | int bits = decoder->bitstream_bits; | ||
1162 | const uint8_t * bit_ptr = decoder->bitstream_ptr; | ||
1163 | int i = 0; | ||
1164 | const DCTtab * tab; | ||
1165 | |||
1166 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1167 | |||
1168 | while (1) | ||
1169 | { | ||
1170 | if (bit_buf >= 0x28000000) | ||
1171 | { | ||
1172 | tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); | ||
1173 | |||
1174 | i += tab->run; | ||
1175 | if (i >= 64) | ||
1176 | break; /* end of block */ | ||
1177 | |||
1178 | normal_code: | ||
1179 | bit_buf <<= tab->len + 1; | ||
1180 | bits += tab->len + 1; | ||
1181 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1182 | continue; | ||
1183 | } | ||
1184 | else if (bit_buf >= 0x04000000) | ||
1185 | { | ||
1186 | tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); | ||
1187 | |||
1188 | i += tab->run; | ||
1189 | if (i < 64) | ||
1190 | goto normal_code; | ||
1191 | |||
1192 | /* escape code */ | ||
1193 | |||
1194 | i += UBITS (bit_buf << 6, 6) - 64; | ||
1195 | if (i >= 64) | ||
1196 | break; /* illegal, check needed to avoid buffer overflow */ | ||
1197 | |||
1198 | DUMPBITS (bit_buf, bits, 12); /* Can't dump more than 16 atm */ | ||
1199 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1200 | DUMPBITS (bit_buf, bits, 12); | ||
1201 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1202 | continue; | ||
1203 | } | ||
1204 | else if (bit_buf >= 0x02000000) | ||
1205 | { | ||
1206 | tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); | ||
1207 | i += tab->run; | ||
1208 | if (i < 64) | ||
1209 | goto normal_code; | ||
1210 | } | ||
1211 | else if (bit_buf >= 0x00800000) | ||
1212 | { | ||
1213 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); | ||
1214 | i += tab->run; | ||
1215 | if (i < 64) | ||
1216 | goto normal_code; | ||
1217 | } | ||
1218 | else if (bit_buf >= 0x00200000) | ||
1219 | { | ||
1220 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); | ||
1221 | i += tab->run; | ||
1222 | if (i < 64) | ||
1223 | goto normal_code; | ||
1224 | } | ||
1225 | else | ||
1226 | { | ||
1227 | tab = DCT_16 + UBITS (bit_buf, 16); | ||
1228 | bit_buf <<= 16; | ||
1229 | GETWORD (bit_buf, bits + 16, bit_ptr); | ||
1230 | i += tab->run; | ||
1231 | if (i < 64) | ||
1232 | goto normal_code; | ||
1233 | } | ||
1234 | break; /* illegal, check needed to avoid buffer overflow */ | ||
1235 | } | ||
1236 | |||
1237 | DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ | ||
1238 | decoder->bitstream_buf = bit_buf; | ||
1239 | decoder->bitstream_bits = bits; | ||
1240 | decoder->bitstream_ptr = bit_ptr; | ||
1241 | } | ||
1242 | |||
1243 | static void skip_intra_block_B15 (mpeg2_decoder_t * const decoder) | ||
1244 | { | ||
1245 | uint32_t bit_buf = decoder->bitstream_buf; | ||
1246 | int bits = decoder->bitstream_bits; | ||
1247 | const uint8_t * bit_ptr = decoder->bitstream_ptr; | ||
1248 | int i = 0; | ||
1249 | const DCTtab * tab; | ||
1250 | |||
1251 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1252 | |||
1253 | while (1) | ||
1254 | { | ||
1255 | if (bit_buf >= 0x04000000) | ||
1256 | { | ||
1257 | tab = DCT_B15_8 + (UBITS (bit_buf, 8) - 4); | ||
1258 | |||
1259 | i += tab->run; | ||
1260 | |||
1261 | if (i < 64) | ||
1262 | { | ||
1263 | normal_code: | ||
1264 | bit_buf <<= tab->len + 1; | ||
1265 | bits += tab->len + 1; | ||
1266 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1267 | continue; | ||
1268 | } | ||
1269 | else | ||
1270 | { | ||
1271 | /* end of block. I commented out this code because if we */ | ||
1272 | /* dont exit here we will still exit at the later test :) */ | ||
1273 | |||
1274 | /* if (i >= 128) break; */ /* end of block */ | ||
1275 | |||
1276 | /* escape code */ | ||
1277 | |||
1278 | i += UBITS (bit_buf << 6, 6) - 64; | ||
1279 | if (i >= 64) | ||
1280 | break; /* illegal, check against buffer overflow */ | ||
1281 | |||
1282 | DUMPBITS (bit_buf, bits, 12); /* Can't dump more than 16 atm */ | ||
1283 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1284 | DUMPBITS (bit_buf, bits, 12); | ||
1285 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1286 | continue; | ||
1287 | } | ||
1288 | } | ||
1289 | else if (bit_buf >= 0x02000000) | ||
1290 | { | ||
1291 | tab = DCT_B15_10 + (UBITS (bit_buf, 10) - 8); | ||
1292 | i += tab->run; | ||
1293 | if (i < 64) | ||
1294 | goto normal_code; | ||
1295 | } | ||
1296 | else if (bit_buf >= 0x00800000) | ||
1297 | { | ||
1298 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); | ||
1299 | i += tab->run; | ||
1300 | if (i < 64) | ||
1301 | goto normal_code; | ||
1302 | } | ||
1303 | else if (bit_buf >= 0x00200000) | ||
1304 | { | ||
1305 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); | ||
1306 | i += tab->run; | ||
1307 | if (i < 64) | ||
1308 | goto normal_code; | ||
1309 | } | ||
1310 | else | ||
1311 | { | ||
1312 | tab = DCT_16 + UBITS (bit_buf, 16); | ||
1313 | bit_buf <<= 16; | ||
1314 | GETWORD (bit_buf, bits + 16, bit_ptr); | ||
1315 | i += tab->run; | ||
1316 | if (i < 64) | ||
1317 | goto normal_code; | ||
1318 | } | ||
1319 | break; /* illegal, check needed to avoid buffer overflow */ | ||
1320 | } | ||
1321 | |||
1322 | DUMPBITS (bit_buf, bits, 4); /* dump end of block code */ | ||
1323 | decoder->bitstream_buf = bit_buf; | ||
1324 | decoder->bitstream_bits = bits; | ||
1325 | decoder->bitstream_ptr = bit_ptr; | ||
1326 | } | ||
1327 | |||
1328 | static void skip_non_intra_block (mpeg2_decoder_t * const decoder) | ||
1329 | { | ||
1330 | uint32_t bit_buf = decoder->bitstream_buf; | ||
1331 | int bits = decoder->bitstream_bits; | ||
1332 | const uint8_t * bit_ptr = decoder->bitstream_ptr; | ||
1333 | int i = -1; | ||
1334 | const DCTtab * tab; | ||
1335 | |||
1336 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1337 | |||
1338 | if (bit_buf >= 0x28000000) | ||
1339 | { | ||
1340 | tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5); | ||
1341 | goto entry_1; | ||
1342 | } | ||
1343 | else | ||
1344 | { | ||
1345 | goto entry_2; | ||
1346 | } | ||
1347 | |||
1348 | while (1) | ||
1349 | { | ||
1350 | if (bit_buf >= 0x28000000) | ||
1351 | { | ||
1352 | tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); | ||
1353 | |||
1354 | entry_1: | ||
1355 | i += tab->run; | ||
1356 | if (i >= 64) | ||
1357 | break; /* end of block */ | ||
1358 | |||
1359 | normal_code: | ||
1360 | bit_buf <<= tab->len + 1; | ||
1361 | bits += tab->len + 1; | ||
1362 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1363 | |||
1364 | continue; | ||
1365 | } | ||
1366 | |||
1367 | entry_2: | ||
1368 | if (bit_buf >= 0x04000000) | ||
1369 | { | ||
1370 | tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); | ||
1371 | |||
1372 | i += tab->run; | ||
1373 | if (i < 64) | ||
1374 | goto normal_code; | ||
1375 | |||
1376 | /* escape code */ | ||
1377 | |||
1378 | i += UBITS (bit_buf << 6, 6) - 64; | ||
1379 | if (i >= 64) | ||
1380 | break; /* illegal, check needed to avoid buffer overflow */ | ||
1381 | |||
1382 | if (decoder->mpeg1) | ||
1383 | { | ||
1384 | DUMPBITS (bit_buf, bits, 12); | ||
1385 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1386 | |||
1387 | if (!(SBITS (bit_buf, 8) & 0x7f)) | ||
1388 | DUMPBITS (bit_buf, bits, 8); | ||
1389 | |||
1390 | DUMPBITS (bit_buf, bits, 8); | ||
1391 | } | ||
1392 | else | ||
1393 | { | ||
1394 | DUMPBITS (bit_buf, bits, 12); | ||
1395 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1396 | DUMPBITS (bit_buf, bits, 12); | ||
1397 | } | ||
1398 | |||
1399 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1400 | continue; | ||
1401 | } | ||
1402 | else if (bit_buf >= 0x02000000) | ||
1403 | { | ||
1404 | tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); | ||
1405 | i += tab->run; | ||
1406 | if (i < 64) | ||
1407 | goto normal_code; | ||
1408 | } | ||
1409 | else if (bit_buf >= 0x00800000) | ||
1410 | { | ||
1411 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); | ||
1412 | i += tab->run; | ||
1413 | if (i < 64) | ||
1414 | goto normal_code; | ||
1415 | } | ||
1416 | else if (bit_buf >= 0x00200000) | ||
1417 | { | ||
1418 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); | ||
1419 | i += tab->run; | ||
1420 | if (i < 64) | ||
1421 | goto normal_code; | ||
1422 | } | ||
1423 | else | ||
1424 | { | ||
1425 | tab = DCT_16 + UBITS (bit_buf, 16); | ||
1426 | bit_buf <<= 16; | ||
1427 | GETWORD (bit_buf, bits + 16, bit_ptr); | ||
1428 | i += tab->run; | ||
1429 | if (i < 64) | ||
1430 | goto normal_code; | ||
1431 | } | ||
1432 | break; /* illegal, check needed to avoid buffer overflow */ | ||
1433 | } | ||
1434 | |||
1435 | DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ | ||
1436 | decoder->bitstream_buf = bit_buf; | ||
1437 | decoder->bitstream_bits = bits; | ||
1438 | decoder->bitstream_ptr = bit_ptr; | ||
1439 | } | ||
1440 | |||
1441 | static void skip_chroma_dc_dct_diff (mpeg2_decoder_t * const decoder) | ||
1442 | { | ||
1443 | #define bit_buf (decoder->bitstream_buf) | ||
1444 | #define bits (decoder->bitstream_bits) | ||
1445 | #define bit_ptr (decoder->bitstream_ptr) | ||
1446 | |||
1447 | const DCtab * tab; | ||
1448 | int size; | ||
1449 | |||
1450 | if (bit_buf < 0xf8000000) | ||
1451 | { | ||
1452 | tab = DC_chrom_5 + UBITS (bit_buf, 5); | ||
1453 | size = tab->size; | ||
1454 | |||
1455 | if (size) | ||
1456 | { | ||
1457 | bits += tab->len + size; | ||
1458 | bit_buf <<= tab->len; | ||
1459 | bit_buf <<= size; | ||
1460 | } | ||
1461 | else | ||
1462 | { | ||
1463 | DUMPBITS (bit_buf, bits, 2); | ||
1464 | } | ||
1465 | } | ||
1466 | else | ||
1467 | { | ||
1468 | tab = DC_long + (UBITS (bit_buf, 10) - 0x3e0); | ||
1469 | size = tab->size; | ||
1470 | DUMPBITS (bit_buf, bits, tab->len + 1); | ||
1471 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1472 | DUMPBITS (bit_buf, bits, size); | ||
1473 | } | ||
1474 | |||
1475 | #undef bit_buf | ||
1476 | #undef bits | ||
1477 | #undef bit_ptr | ||
1478 | } | ||
1479 | |||
1480 | static void skip_chroma_non_intra (mpeg2_decoder_t * const decoder, | ||
1481 | uint32_t coded_block_pattern) | ||
1482 | { | ||
1483 | static const uint32_t cbp_mask[3] = | ||
1484 | { | ||
1485 | 0x00000030, | ||
1486 | 0xc0000030, | ||
1487 | 0xfc000030, | ||
1488 | }; | ||
1489 | |||
1490 | uint32_t cbp = coded_block_pattern & | ||
1491 | cbp_mask[MIN((unsigned)decoder->chroma_format, 2u)]; | ||
1492 | |||
1493 | while (cbp) | ||
1494 | { | ||
1495 | skip_non_intra_block (decoder); | ||
1496 | cbp &= (cbp - 1); | ||
1497 | } | ||
1498 | } | ||
1499 | |||
1500 | static void skip_chroma_intra (mpeg2_decoder_t * const decoder) | ||
1501 | { | ||
1502 | #define bit_buf (decoder->bitstream_buf) | ||
1503 | #define bits (decoder->bitstream_bits) | ||
1504 | #define bit_ptr (decoder->bitstream_ptr) | ||
1505 | int i = 2 << decoder->chroma_format; | ||
1506 | |||
1507 | if ((unsigned)i > 8) | ||
1508 | i = 8; | ||
1509 | |||
1510 | while (i-- > 0) | ||
1511 | { | ||
1512 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1513 | |||
1514 | skip_chroma_dc_dct_diff (decoder); | ||
1515 | |||
1516 | if (decoder->mpeg1) | ||
1517 | { | ||
1518 | if (decoder->coding_type != D_TYPE) | ||
1519 | skip_mpeg1_intra_block (decoder); | ||
1520 | } | ||
1521 | else if (decoder->intra_vlc_format) | ||
1522 | { | ||
1523 | skip_intra_block_B15 (decoder); | ||
1524 | } | ||
1525 | else | ||
1526 | { | ||
1527 | skip_intra_block_B14 (decoder); | ||
1528 | } | ||
1529 | } | ||
1530 | |||
1531 | if (decoder->chroma_format == 0 && decoder->coding_type == D_TYPE) | ||
1532 | { | ||
1533 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1534 | DUMPBITS (bit_buf, bits, 1); | ||
1535 | } | ||
1536 | |||
1537 | #undef bit_buf | ||
1538 | #undef bits | ||
1539 | #undef bit_ptr | ||
1540 | } | ||
1541 | #endif /* !MPEG2_COLOR */ | ||
1542 | |||
1543 | #define MOTION_420(table, ref, motion_x, motion_y, size, y) \ | ||
1544 | pos_x = 2 * decoder->offset + motion_x; \ | ||
1545 | pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \ | ||
1546 | \ | ||
1547 | if (unlikely (pos_x > decoder->limit_x)) \ | ||
1548 | { \ | ||
1549 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | ||
1550 | motion_x = pos_x - 2 * decoder->offset; \ | ||
1551 | } \ | ||
1552 | \ | ||
1553 | if (unlikely (pos_y > decoder->limit_y_ ## size)) \ | ||
1554 | { \ | ||
1555 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \ | ||
1556 | motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \ | ||
1557 | } \ | ||
1558 | \ | ||
1559 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | ||
1560 | table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \ | ||
1561 | ref[0] + (pos_x >> 1) + (pos_y >> 1) * decoder->stride, \ | ||
1562 | decoder->stride, size); \ | ||
1563 | \ | ||
1564 | if (MPEG2_COLOR) \ | ||
1565 | { \ | ||
1566 | motion_x /= 2; \ | ||
1567 | motion_y /= 2; \ | ||
1568 | xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \ | ||
1569 | offset = ((decoder->offset + motion_x) >> 1) + \ | ||
1570 | ((((decoder->v_offset + motion_y) >> 1) + y/2) * \ | ||
1571 | decoder->uv_stride); \ | ||
1572 | \ | ||
1573 | table[4+xy_half] (decoder->dest[1] + y/2 * decoder->uv_stride + \ | ||
1574 | (decoder->offset >> 1), ref[1] + offset, \ | ||
1575 | decoder->uv_stride, size/2); \ | ||
1576 | table[4+xy_half] (decoder->dest[2] + y/2 * decoder->uv_stride + \ | ||
1577 | (decoder->offset >> 1), ref[2] + offset, \ | ||
1578 | decoder->uv_stride, size/2); \ | ||
1579 | } | ||
1580 | |||
1581 | #define MOTION_FIELD_420(table, ref, motion_x, motion_y, \ | ||
1582 | dest_field, op, src_field) \ | ||
1583 | pos_x = 2 * decoder->offset + motion_x; \ | ||
1584 | pos_y = decoder->v_offset + motion_y; \ | ||
1585 | \ | ||
1586 | if (unlikely (pos_x > decoder->limit_x)) \ | ||
1587 | { \ | ||
1588 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | ||
1589 | motion_x = pos_x - 2 * decoder->offset; \ | ||
1590 | } \ | ||
1591 | \ | ||
1592 | if (unlikely (pos_y > decoder->limit_y)) \ | ||
1593 | { \ | ||
1594 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ | ||
1595 | motion_y = pos_y - decoder->v_offset; \ | ||
1596 | } \ | ||
1597 | \ | ||
1598 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | ||
1599 | table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \ | ||
1600 | decoder->offset, \ | ||
1601 | (ref[0] + (pos_x >> 1) + \ | ||
1602 | ((pos_y op) + src_field) * decoder->stride), \ | ||
1603 | 2 * decoder->stride, 8); \ | ||
1604 | \ | ||
1605 | if (MPEG2_COLOR) \ | ||
1606 | { \ | ||
1607 | motion_x /= 2; \ | ||
1608 | motion_y /= 2; \ | ||
1609 | xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \ | ||
1610 | offset = ((decoder->offset + motion_x) >> 1) + \ | ||
1611 | (((decoder->v_offset >> 1) + (motion_y op) + src_field) * \ | ||
1612 | decoder->uv_stride); \ | ||
1613 | \ | ||
1614 | table[4+xy_half] (decoder->dest[1] + dest_field * decoder->uv_stride + \ | ||
1615 | (decoder->offset >> 1), ref[1] + offset, \ | ||
1616 | 2 * decoder->uv_stride, 4); \ | ||
1617 | table[4+xy_half] (decoder->dest[2] + dest_field * decoder->uv_stride + \ | ||
1618 | (decoder->offset >> 1), ref[2] + offset, \ | ||
1619 | 2 * decoder->uv_stride, 4); \ | ||
1620 | } | ||
1621 | |||
1622 | #define MOTION_DMV_420(table, ref, motion_x, motion_y) \ | ||
1623 | pos_x = 2 * decoder->offset + motion_x; \ | ||
1624 | pos_y = decoder->v_offset + motion_y; \ | ||
1625 | \ | ||
1626 | if (unlikely (pos_x > decoder->limit_x)) \ | ||
1627 | { \ | ||
1628 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | ||
1629 | motion_x = pos_x - 2 * decoder->offset; \ | ||
1630 | } \ | ||
1631 | \ | ||
1632 | if (unlikely (pos_y > decoder->limit_y)) \ | ||
1633 | { \ | ||
1634 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ | ||
1635 | motion_y = pos_y - decoder->v_offset; \ | ||
1636 | } \ | ||
1637 | \ | ||
1638 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | ||
1639 | offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \ | ||
1640 | table[xy_half] (decoder->dest[0] + decoder->offset, \ | ||
1641 | ref[0] + offset, 2 * decoder->stride, 8); \ | ||
1642 | table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \ | ||
1643 | ref[0] + decoder->stride + offset, \ | ||
1644 | 2 * decoder->stride, 8); \ | ||
1645 | \ | ||
1646 | if (MPEG2_COLOR) \ | ||
1647 | { \ | ||
1648 | motion_x /= 2; \ | ||
1649 | motion_y /= 2; \ | ||
1650 | xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \ | ||
1651 | offset = ((decoder->offset + motion_x) >> 1) + \ | ||
1652 | (((decoder->v_offset >> 1) + (motion_y & ~1)) * \ | ||
1653 | decoder->uv_stride); \ | ||
1654 | \ | ||
1655 | table[4+xy_half] (decoder->dest[1] + (decoder->offset >> 1), \ | ||
1656 | ref[1] + offset, 2 * decoder->uv_stride, 4); \ | ||
1657 | table[4+xy_half] (decoder->dest[1] + decoder->uv_stride + \ | ||
1658 | (decoder->offset >> 1), \ | ||
1659 | ref[1] + decoder->uv_stride + offset, \ | ||
1660 | 2 * decoder->uv_stride, 4); \ | ||
1661 | table[4+xy_half] (decoder->dest[2] + (decoder->offset >> 1), \ | ||
1662 | ref[2] + offset, 2 * decoder->uv_stride, 4); \ | ||
1663 | table[4+xy_half] (decoder->dest[2] + decoder->uv_stride + \ | ||
1664 | (decoder->offset >> 1), \ | ||
1665 | ref[2] + decoder->uv_stride + offset, \ | ||
1666 | 2 * decoder->uv_stride, 4); \ | ||
1667 | } | ||
1668 | |||
1669 | #define MOTION_ZERO_420(table, ref) \ | ||
1670 | table[0] (decoder->dest[0] + decoder->offset, \ | ||
1671 | (ref[0] + decoder->offset + \ | ||
1672 | decoder->v_offset * decoder->stride), decoder->stride, 16); \ | ||
1673 | \ | ||
1674 | if (MPEG2_COLOR) \ | ||
1675 | { \ | ||
1676 | offset = ((decoder->offset >> 1) + \ | ||
1677 | (decoder->v_offset >> 1) * decoder->uv_stride); \ | ||
1678 | \ | ||
1679 | table[4] (decoder->dest[1] + (decoder->offset >> 1), \ | ||
1680 | ref[1] + offset, decoder->uv_stride, 8); \ | ||
1681 | table[4] (decoder->dest[2] + (decoder->offset >> 1), \ | ||
1682 | ref[2] + offset, decoder->uv_stride, 8); \ | ||
1683 | } | ||
1684 | |||
1685 | #define MOTION_422(table, ref, motion_x, motion_y, size, y) \ | ||
1686 | pos_x = 2 * decoder->offset + motion_x; \ | ||
1687 | pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \ | ||
1688 | \ | ||
1689 | if (unlikely (pos_x > decoder->limit_x)) \ | ||
1690 | { \ | ||
1691 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | ||
1692 | motion_x = pos_x - 2 * decoder->offset; \ | ||
1693 | } \ | ||
1694 | \ | ||
1695 | if (unlikely (pos_y > decoder->limit_y_ ## size)) \ | ||
1696 | { \ | ||
1697 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \ | ||
1698 | motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \ | ||
1699 | } \ | ||
1700 | \ | ||
1701 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | ||
1702 | offset = (pos_x >> 1) + (pos_y >> 1) * decoder->stride; \ | ||
1703 | \ | ||
1704 | table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \ | ||
1705 | ref[0] + offset, decoder->stride, size); \ | ||
1706 | \ | ||
1707 | if (MPEG2_COLOR) \ | ||
1708 | { \ | ||
1709 | offset = (offset + (motion_x & (motion_x < 0))) >> 1; \ | ||
1710 | motion_x /= 2; \ | ||
1711 | xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \ | ||
1712 | \ | ||
1713 | table[4+xy_half] (decoder->dest[1] + y * decoder->uv_stride + \ | ||
1714 | (decoder->offset >> 1), ref[1] + offset, \ | ||
1715 | decoder->uv_stride, size); \ | ||
1716 | table[4+xy_half] (decoder->dest[2] + y * decoder->uv_stride + \ | ||
1717 | (decoder->offset >> 1), ref[2] + offset, \ | ||
1718 | decoder->uv_stride, size); \ | ||
1719 | } | ||
1720 | |||
1721 | #define MOTION_FIELD_422(table, ref, motion_x, motion_y, \ | ||
1722 | dest_field, op, src_field) \ | ||
1723 | pos_x = 2 * decoder->offset + motion_x; \ | ||
1724 | pos_y = decoder->v_offset + motion_y; \ | ||
1725 | \ | ||
1726 | if (unlikely (pos_x > decoder->limit_x)) \ | ||
1727 | { \ | ||
1728 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | ||
1729 | motion_x = pos_x - 2 * decoder->offset; \ | ||
1730 | } \ | ||
1731 | \ | ||
1732 | if (unlikely (pos_y > decoder->limit_y)) \ | ||
1733 | { \ | ||
1734 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ | ||
1735 | motion_y = pos_y - decoder->v_offset; \ | ||
1736 | } \ | ||
1737 | \ | ||
1738 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | ||
1739 | offset = (pos_x >> 1) + ((pos_y op) + src_field) * decoder->stride; \ | ||
1740 | \ | ||
1741 | table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \ | ||
1742 | decoder->offset, ref[0] + offset, \ | ||
1743 | 2 * decoder->stride, 8); \ | ||
1744 | \ | ||
1745 | if (MPEG2_COLOR) \ | ||
1746 | { \ | ||
1747 | offset = (offset + (motion_x & (motion_x < 0))) >> 1; \ | ||
1748 | motion_x /= 2; \ | ||
1749 | xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \ | ||
1750 | \ | ||
1751 | table[4+xy_half] (decoder->dest[1] + dest_field * decoder->uv_stride + \ | ||
1752 | (decoder->offset >> 1), ref[1] + offset, \ | ||
1753 | 2 * decoder->uv_stride, 8); \ | ||
1754 | table[4+xy_half] (decoder->dest[2] + dest_field * decoder->uv_stride + \ | ||
1755 | (decoder->offset >> 1), ref[2] + offset, \ | ||
1756 | 2 * decoder->uv_stride, 8); \ | ||
1757 | } | ||
1758 | |||
1759 | #define MOTION_DMV_422(table, ref, motion_x, motion_y) \ | ||
1760 | pos_x = 2 * decoder->offset + motion_x; \ | ||
1761 | pos_y = decoder->v_offset + motion_y; \ | ||
1762 | \ | ||
1763 | if (unlikely (pos_x > decoder->limit_x)) \ | ||
1764 | { \ | ||
1765 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | ||
1766 | motion_x = pos_x - 2 * decoder->offset; \ | ||
1767 | } \ | ||
1768 | \ | ||
1769 | if (unlikely (pos_y > decoder->limit_y)) \ | ||
1770 | { \ | ||
1771 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ | ||
1772 | motion_y = pos_y - decoder->v_offset; \ | ||
1773 | } \ | ||
1774 | \ | ||
1775 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | ||
1776 | offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \ | ||
1777 | \ | ||
1778 | table[xy_half] (decoder->dest[0] + decoder->offset, \ | ||
1779 | ref[0] + offset, 2 * decoder->stride, 8); \ | ||
1780 | table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \ | ||
1781 | ref[0] + decoder->stride + offset, \ | ||
1782 | 2 * decoder->stride, 8); \ | ||
1783 | \ | ||
1784 | if (MPEG2_COLOR) \ | ||
1785 | { \ | ||
1786 | offset = (offset + (motion_x & (motion_x < 0))) >> 1; \ | ||
1787 | motion_x /= 2; \ | ||
1788 | xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \ | ||
1789 | \ | ||
1790 | table[4+xy_half] (decoder->dest[1] + (decoder->offset >> 1), \ | ||
1791 | ref[1] + offset, 2 * decoder->uv_stride, 8); \ | ||
1792 | table[4+xy_half] (decoder->dest[1] + decoder->uv_stride + \ | ||
1793 | (decoder->offset >> 1), \ | ||
1794 | ref[1] + decoder->uv_stride + offset, \ | ||
1795 | 2 * decoder->uv_stride, 8); \ | ||
1796 | table[4+xy_half] (decoder->dest[2] + (decoder->offset >> 1), \ | ||
1797 | ref[2] + offset, 2 * decoder->uv_stride, 8); \ | ||
1798 | table[4+xy_half] (decoder->dest[2] + decoder->uv_stride + \ | ||
1799 | (decoder->offset >> 1), \ | ||
1800 | ref[2] + decoder->uv_stride + offset, \ | ||
1801 | 2 * decoder->uv_stride, 8); \ | ||
1802 | } | ||
1803 | |||
1804 | #define MOTION_ZERO_422(table, ref) \ | ||
1805 | offset = decoder->offset + decoder->v_offset * decoder->stride; \ | ||
1806 | table[0] (decoder->dest[0] + decoder->offset, \ | ||
1807 | ref[0] + offset, decoder->stride, 16); \ | ||
1808 | \ | ||
1809 | if (MPEG2_COLOR) \ | ||
1810 | { \ | ||
1811 | offset >>= 1; \ | ||
1812 | table[4] (decoder->dest[1] + (decoder->offset >> 1), \ | ||
1813 | ref[1] + offset, decoder->uv_stride, 16); \ | ||
1814 | table[4] (decoder->dest[2] + (decoder->offset >> 1), \ | ||
1815 | ref[2] + offset, decoder->uv_stride, 16); \ | ||
1816 | } | ||
1817 | |||
1818 | #define MOTION_444(table, ref, motion_x, motion_y, size, y) \ | ||
1819 | pos_x = 2 * decoder->offset + motion_x; \ | ||
1820 | pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \ | ||
1821 | \ | ||
1822 | if (unlikely (pos_x > decoder->limit_x)) \ | ||
1823 | { \ | ||
1824 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | ||
1825 | motion_x = pos_x - 2 * decoder->offset; \ | ||
1826 | } \ | ||
1827 | \ | ||
1828 | if (unlikely (pos_y > decoder->limit_y_ ## size)) \ | ||
1829 | { \ | ||
1830 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \ | ||
1831 | motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \ | ||
1832 | } \ | ||
1833 | \ | ||
1834 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | ||
1835 | offset = (pos_x >> 1) + (pos_y >> 1) * decoder->stride; \ | ||
1836 | \ | ||
1837 | table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \ | ||
1838 | ref[0] + offset, decoder->stride, size); \ | ||
1839 | \ | ||
1840 | if (MPEG2_COLOR) \ | ||
1841 | { \ | ||
1842 | table[xy_half] (decoder->dest[1] + y * decoder->stride + decoder->offset, \ | ||
1843 | ref[1] + offset, decoder->stride, size); \ | ||
1844 | table[xy_half] (decoder->dest[2] + y * decoder->stride + decoder->offset, \ | ||
1845 | ref[2] + offset, decoder->stride, size); \ | ||
1846 | } | ||
1847 | |||
1848 | #define MOTION_FIELD_444(table, ref, motion_x, motion_y, \ | ||
1849 | dest_field, op, src_field) \ | ||
1850 | pos_x = 2 * decoder->offset + motion_x; \ | ||
1851 | pos_y = decoder->v_offset + motion_y; \ | ||
1852 | \ | ||
1853 | if (unlikely (pos_x > decoder->limit_x)) \ | ||
1854 | { \ | ||
1855 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | ||
1856 | motion_x = pos_x - 2 * decoder->offset; \ | ||
1857 | } \ | ||
1858 | \ | ||
1859 | if (unlikely (pos_y > decoder->limit_y)) \ | ||
1860 | { \ | ||
1861 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ | ||
1862 | motion_y = pos_y - decoder->v_offset; \ | ||
1863 | } \ | ||
1864 | \ | ||
1865 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | ||
1866 | offset = (pos_x >> 1) + ((pos_y op) + src_field) * decoder->stride; \ | ||
1867 | \ | ||
1868 | table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \ | ||
1869 | decoder->offset, ref[0] + offset, \ | ||
1870 | 2 * decoder->stride, 8); \ | ||
1871 | \ | ||
1872 | if (MPEG2_COLOR) \ | ||
1873 | { \ | ||
1874 | table[xy_half] (decoder->dest[1] + dest_field * decoder->stride + \ | ||
1875 | decoder->offset, ref[1] + offset, \ | ||
1876 | 2 * decoder->stride, 8); \ | ||
1877 | table[xy_half] (decoder->dest[2] + dest_field * decoder->stride + \ | ||
1878 | decoder->offset, ref[2] + offset, \ | ||
1879 | 2 * decoder->stride, 8); \ | ||
1880 | } | ||
1881 | |||
1882 | #define MOTION_DMV_444(table, ref, motion_x, motion_y) \ | ||
1883 | pos_x = 2 * decoder->offset + motion_x; \ | ||
1884 | pos_y = decoder->v_offset + motion_y; \ | ||
1885 | \ | ||
1886 | if (unlikely (pos_x > decoder->limit_x)) \ | ||
1887 | { \ | ||
1888 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | ||
1889 | motion_x = pos_x - 2 * decoder->offset; \ | ||
1890 | } \ | ||
1891 | \ | ||
1892 | if (unlikely (pos_y > decoder->limit_y)) \ | ||
1893 | { \ | ||
1894 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ | ||
1895 | motion_y = pos_y - decoder->v_offset; \ | ||
1896 | } \ | ||
1897 | \ | ||
1898 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | ||
1899 | offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \ | ||
1900 | \ | ||
1901 | table[xy_half] (decoder->dest[0] + decoder->offset, \ | ||
1902 | ref[0] + offset, 2 * decoder->stride, 8); \ | ||
1903 | table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \ | ||
1904 | ref[0] + decoder->stride + offset, \ | ||
1905 | 2 * decoder->stride, 8); \ | ||
1906 | \ | ||
1907 | if (MPEG2_COLOR) \ | ||
1908 | { \ | ||
1909 | table[xy_half] (decoder->dest[1] + decoder->offset, \ | ||
1910 | ref[1] + offset, 2 * decoder->stride, 8); \ | ||
1911 | table[xy_half] (decoder->dest[1] + decoder->stride + decoder->offset, \ | ||
1912 | ref[1] + decoder->stride + offset, \ | ||
1913 | 2 * decoder->stride, 8); \ | ||
1914 | table[xy_half] (decoder->dest[2] + decoder->offset, \ | ||
1915 | ref[2] + offset, 2 * decoder->stride, 8); \ | ||
1916 | table[xy_half] (decoder->dest[2] + decoder->stride + decoder->offset, \ | ||
1917 | ref[2] + decoder->stride + offset, \ | ||
1918 | 2 * decoder->stride, 8); \ | ||
1919 | } | ||
1920 | |||
1921 | #define MOTION_ZERO_444(table, ref) \ | ||
1922 | offset = decoder->offset + decoder->v_offset * decoder->stride; \ | ||
1923 | \ | ||
1924 | table[0] (decoder->dest[0] + decoder->offset, \ | ||
1925 | ref[0] + offset, decoder->stride, 16); \ | ||
1926 | \ | ||
1927 | if (MPEG2_COLOR) \ | ||
1928 | { \ | ||
1929 | table[4] (decoder->dest[1] + decoder->offset, \ | ||
1930 | ref[1] + offset, decoder->stride, 16); \ | ||
1931 | table[4] (decoder->dest[2] + decoder->offset, \ | ||
1932 | ref[2] + offset, decoder->stride, 16); \ | ||
1933 | } | ||
1934 | |||
1935 | #define bit_buf (decoder->bitstream_buf) | ||
1936 | #define bits (decoder->bitstream_bits) | ||
1937 | #define bit_ptr (decoder->bitstream_ptr) | ||
1938 | |||
1939 | static void motion_mp1 (mpeg2_decoder_t * const decoder, | ||
1940 | motion_t * const motion, | ||
1941 | mpeg2_mc_fct * const * const table) | ||
1942 | { | ||
1943 | int motion_x, motion_y; | ||
1944 | unsigned int pos_x, pos_y, xy_half, offset; | ||
1945 | |||
1946 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1947 | motion_x = motion->pmv[0][0] + | ||
1948 | (get_motion_delta (decoder, | ||
1949 | motion->f_code[0]) << motion->f_code[1]); | ||
1950 | motion_x = bound_motion_vector (motion_x, | ||
1951 | motion->f_code[0] + motion->f_code[1]); | ||
1952 | motion->pmv[0][0] = motion_x; | ||
1953 | |||
1954 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1955 | motion_y = motion->pmv[0][1] + | ||
1956 | (get_motion_delta (decoder, | ||
1957 | motion->f_code[0]) << motion->f_code[1]); | ||
1958 | motion_y = bound_motion_vector (motion_y, | ||
1959 | motion->f_code[0] + motion->f_code[1]); | ||
1960 | motion->pmv[0][1] = motion_y; | ||
1961 | |||
1962 | MOTION_420 (table, motion->ref[0], motion_x, motion_y, 16, 0); | ||
1963 | } | ||
1964 | |||
1965 | #define MOTION_FUNCTIONS(FORMAT, MOTION, MOTION_FIELD, \ | ||
1966 | MOTION_DMV, MOTION_ZERO) \ | ||
1967 | \ | ||
1968 | static void motion_fr_frame_##FORMAT (mpeg2_decoder_t * const decoder, \ | ||
1969 | motion_t * const motion, \ | ||
1970 | mpeg2_mc_fct * const * const table) \ | ||
1971 | { \ | ||
1972 | int motion_x, motion_y; \ | ||
1973 | unsigned int pos_x, pos_y, xy_half, offset; \ | ||
1974 | \ | ||
1975 | NEEDBITS (bit_buf, bits, bit_ptr); \ | ||
1976 | motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ | ||
1977 | motion->f_code[0]); \ | ||
1978 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | ||
1979 | motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ | ||
1980 | \ | ||
1981 | NEEDBITS (bit_buf, bits, bit_ptr); \ | ||
1982 | motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ | ||
1983 | motion->f_code[1]); \ | ||
1984 | motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ | ||
1985 | motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \ | ||
1986 | \ | ||
1987 | MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0); \ | ||
1988 | } \ | ||
1989 | \ | ||
1990 | static void motion_fr_field_##FORMAT (mpeg2_decoder_t * const decoder, \ | ||
1991 | motion_t * const motion, \ | ||
1992 | mpeg2_mc_fct * const * const table) \ | ||
1993 | { \ | ||
1994 | int motion_x, motion_y, field; \ | ||
1995 | unsigned int pos_x, pos_y, xy_half, offset; \ | ||
1996 | \ | ||
1997 | NEEDBITS (bit_buf, bits, bit_ptr); \ | ||
1998 | field = UBITS (bit_buf, 1); \ | ||
1999 | DUMPBITS (bit_buf, bits, 1); \ | ||
2000 | \ | ||
2001 | motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ | ||
2002 | motion->f_code[0]); \ | ||
2003 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | ||
2004 | motion->pmv[0][0] = motion_x; \ | ||
2005 | \ | ||
2006 | NEEDBITS (bit_buf, bits, bit_ptr); \ | ||
2007 | motion_y = ((motion->pmv[0][1] >> 1) + \ | ||
2008 | get_motion_delta (decoder, motion->f_code[1])); \ | ||
2009 | /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \ | ||
2010 | motion->pmv[0][1] = motion_y << 1; \ | ||
2011 | \ | ||
2012 | MOTION_FIELD (table, motion->ref[0], motion_x, motion_y, 0, & ~1, field); \ | ||
2013 | \ | ||
2014 | NEEDBITS (bit_buf, bits, bit_ptr); \ | ||
2015 | field = UBITS (bit_buf, 1); \ | ||
2016 | DUMPBITS (bit_buf, bits, 1); \ | ||
2017 | \ | ||
2018 | motion_x = motion->pmv[1][0] + get_motion_delta (decoder, \ | ||
2019 | motion->f_code[0]); \ | ||
2020 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | ||
2021 | motion->pmv[1][0] = motion_x; \ | ||
2022 | \ | ||
2023 | NEEDBITS (bit_buf, bits, bit_ptr); \ | ||
2024 | motion_y = ((motion->pmv[1][1] >> 1) + \ | ||
2025 | get_motion_delta (decoder, motion->f_code[1])); \ | ||
2026 | /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \ | ||
2027 | motion->pmv[1][1] = motion_y << 1; \ | ||
2028 | \ | ||
2029 | MOTION_FIELD (table, motion->ref[0], motion_x, motion_y, 1, & ~1, field); \ | ||
2030 | } \ | ||
2031 | \ | ||
2032 | static void motion_fr_dmv_##FORMAT (mpeg2_decoder_t * const decoder, \ | ||
2033 | motion_t * const motion, \ | ||
2034 | mpeg2_mc_fct * const * const table) \ | ||
2035 | { \ | ||
2036 | int motion_x, motion_y, dmv_x, dmv_y, m, other_x, other_y; \ | ||
2037 | unsigned int pos_x, pos_y, xy_half, offset; \ | ||
2038 | \ | ||
2039 | (void)table; \ | ||
2040 | NEEDBITS (bit_buf, bits, bit_ptr); \ | ||
2041 | motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ | ||
2042 | motion->f_code[0]); \ | ||
2043 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | ||
2044 | motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ | ||
2045 | NEEDBITS (bit_buf, bits, bit_ptr); \ | ||
2046 | dmv_x = get_dmv (decoder); \ | ||
2047 | \ | ||
2048 | motion_y = ((motion->pmv[0][1] >> 1) + \ | ||
2049 | get_motion_delta (decoder, motion->f_code[1])); \ | ||
2050 | /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \ | ||
2051 | motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1; \ | ||
2052 | dmv_y = get_dmv (decoder); \ | ||
2053 | \ | ||
2054 | m = decoder->top_field_first ? 1 : 3; \ | ||
2055 | other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; \ | ||
2056 | other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1; \ | ||
2057 | MOTION_FIELD (mpeg2_mc.put, motion->ref[0], other_x, other_y, 0, | 1, 0); \ | ||
2058 | \ | ||
2059 | m = decoder->top_field_first ? 3 : 1; \ | ||
2060 | other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; \ | ||
2061 | other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1; \ | ||
2062 | MOTION_FIELD (mpeg2_mc.put, motion->ref[0], other_x, other_y, 1, & ~1, 0);\ | ||
2063 | \ | ||
2064 | MOTION_DMV (mpeg2_mc.avg, motion->ref[0], motion_x, motion_y); \ | ||
2065 | } \ | ||
2066 | \ | ||
2067 | static void motion_reuse_##FORMAT (mpeg2_decoder_t * const decoder, \ | ||
2068 | motion_t * const motion, \ | ||
2069 | mpeg2_mc_fct * const * const table) \ | ||
2070 | { \ | ||
2071 | int motion_x, motion_y; \ | ||
2072 | unsigned int pos_x, pos_y, xy_half, offset; \ | ||
2073 | \ | ||
2074 | motion_x = motion->pmv[0][0]; \ | ||
2075 | motion_y = motion->pmv[0][1]; \ | ||
2076 | \ | ||
2077 | MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0); \ | ||
2078 | } \ | ||
2079 | \ | ||
2080 | static void motion_zero_##FORMAT (mpeg2_decoder_t * const decoder, \ | ||
2081 | motion_t * const motion, \ | ||
2082 | mpeg2_mc_fct * const * const table) \ | ||
2083 | { \ | ||
2084 | unsigned int offset; \ | ||
2085 | \ | ||
2086 | motion->pmv[0][0] = motion->pmv[0][1] = 0; \ | ||
2087 | motion->pmv[1][0] = motion->pmv[1][1] = 0; \ | ||
2088 | \ | ||
2089 | MOTION_ZERO (table, motion->ref[0]); \ | ||
2090 | } \ | ||
2091 | \ | ||
2092 | static void motion_fi_field_##FORMAT (mpeg2_decoder_t * const decoder, \ | ||
2093 | motion_t * const motion, \ | ||
2094 | mpeg2_mc_fct * const * const table) \ | ||
2095 | { \ | ||
2096 | int motion_x, motion_y; \ | ||
2097 | uint8_t ** ref_field; \ | ||
2098 | unsigned int pos_x, pos_y, xy_half, offset; \ | ||
2099 | \ | ||
2100 | NEEDBITS (bit_buf, bits, bit_ptr); \ | ||
2101 | ref_field = motion->ref2[UBITS (bit_buf, 1)]; \ | ||
2102 | DUMPBITS (bit_buf, bits, 1); \ | ||
2103 | \ | ||
2104 | motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ | ||
2105 | motion->f_code[0]); \ | ||
2106 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | ||
2107 | motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ | ||
2108 | \ | ||
2109 | NEEDBITS (bit_buf, bits, bit_ptr); \ | ||
2110 | motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ | ||
2111 | motion->f_code[1]); \ | ||
2112 | motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ | ||
2113 | motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \ | ||
2114 | \ | ||
2115 | MOTION (table, ref_field, motion_x, motion_y, 16, 0); \ | ||
2116 | } \ | ||
2117 | \ | ||
2118 | static void motion_fi_16x8_##FORMAT (mpeg2_decoder_t * const decoder, \ | ||
2119 | motion_t * const motion, \ | ||
2120 | mpeg2_mc_fct * const * const table) \ | ||
2121 | { \ | ||
2122 | int motion_x, motion_y; \ | ||
2123 | uint8_t ** ref_field; \ | ||
2124 | unsigned int pos_x, pos_y, xy_half, offset; \ | ||
2125 | \ | ||
2126 | NEEDBITS (bit_buf, bits, bit_ptr); \ | ||
2127 | ref_field = motion->ref2[UBITS (bit_buf, 1)]; \ | ||
2128 | DUMPBITS (bit_buf, bits, 1); \ | ||
2129 | \ | ||
2130 | motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ | ||
2131 | motion->f_code[0]); \ | ||
2132 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | ||
2133 | motion->pmv[0][0] = motion_x; \ | ||
2134 | \ | ||
2135 | NEEDBITS (bit_buf, bits, bit_ptr); \ | ||
2136 | motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ | ||
2137 | motion->f_code[1]); \ | ||
2138 | motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ | ||
2139 | motion->pmv[0][1] = motion_y; \ | ||
2140 | \ | ||
2141 | MOTION (table, ref_field, motion_x, motion_y, 8, 0); \ | ||
2142 | \ | ||
2143 | NEEDBITS (bit_buf, bits, bit_ptr); \ | ||
2144 | ref_field = motion->ref2[UBITS (bit_buf, 1)]; \ | ||
2145 | DUMPBITS (bit_buf, bits, 1); \ | ||
2146 | \ | ||
2147 | motion_x = motion->pmv[1][0] + get_motion_delta (decoder, \ | ||
2148 | motion->f_code[0]); \ | ||
2149 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | ||
2150 | motion->pmv[1][0] = motion_x; \ | ||
2151 | \ | ||
2152 | NEEDBITS (bit_buf, bits, bit_ptr); \ | ||
2153 | motion_y = motion->pmv[1][1] + get_motion_delta (decoder, \ | ||
2154 | motion->f_code[1]); \ | ||
2155 | motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ | ||
2156 | motion->pmv[1][1] = motion_y; \ | ||
2157 | \ | ||
2158 | MOTION (table, ref_field, motion_x, motion_y, 8, 8); \ | ||
2159 | } \ | ||
2160 | \ | ||
2161 | static void motion_fi_dmv_##FORMAT (mpeg2_decoder_t * const decoder, \ | ||
2162 | motion_t * const motion, \ | ||
2163 | mpeg2_mc_fct * const * const table) \ | ||
2164 | { \ | ||
2165 | int motion_x, motion_y, other_x, other_y; \ | ||
2166 | unsigned int pos_x, pos_y, xy_half, offset; \ | ||
2167 | \ | ||
2168 | (void)table; \ | ||
2169 | NEEDBITS (bit_buf, bits, bit_ptr); \ | ||
2170 | motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ | ||
2171 | motion->f_code[0]); \ | ||
2172 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | ||
2173 | motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ | ||
2174 | NEEDBITS (bit_buf, bits, bit_ptr); \ | ||
2175 | other_x = ((motion_x + (motion_x > 0)) >> 1) + get_dmv (decoder); \ | ||
2176 | \ | ||
2177 | motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ | ||
2178 | motion->f_code[1]); \ | ||
2179 | motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ | ||
2180 | motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \ | ||
2181 | other_y = (((motion_y + (motion_y > 0)) >> 1) + get_dmv (decoder) + \ | ||
2182 | decoder->dmv_offset); \ | ||
2183 | \ | ||
2184 | MOTION (mpeg2_mc.put, motion->ref[0], motion_x, motion_y, 16, 0); \ | ||
2185 | MOTION (mpeg2_mc.avg, motion->ref[1], other_x, other_y, 16, 0); \ | ||
2186 | } \ | ||
2187 | |||
2188 | MOTION_FUNCTIONS (420, MOTION_420, MOTION_FIELD_420, MOTION_DMV_420, | ||
2189 | MOTION_ZERO_420) | ||
2190 | MOTION_FUNCTIONS (422, MOTION_422, MOTION_FIELD_422, MOTION_DMV_422, | ||
2191 | MOTION_ZERO_422) | ||
2192 | MOTION_FUNCTIONS (444, MOTION_444, MOTION_FIELD_444, MOTION_DMV_444, | ||
2193 | MOTION_ZERO_444) | ||
2194 | |||
2195 | /* like motion_frame, but parsing without actual motion compensation */ | ||
2196 | static void motion_fr_conceal (mpeg2_decoder_t * const decoder) | ||
2197 | { | ||
2198 | int tmp; | ||
2199 | |||
2200 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
2201 | tmp = (decoder->f_motion.pmv[0][0] + | ||
2202 | get_motion_delta (decoder, decoder->f_motion.f_code[0])); | ||
2203 | tmp = bound_motion_vector (tmp, decoder->f_motion.f_code[0]); | ||
2204 | decoder->f_motion.pmv[1][0] = decoder->f_motion.pmv[0][0] = tmp; | ||
2205 | |||
2206 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
2207 | tmp = (decoder->f_motion.pmv[0][1] + | ||
2208 | get_motion_delta (decoder, decoder->f_motion.f_code[1])); | ||
2209 | tmp = bound_motion_vector (tmp, decoder->f_motion.f_code[1]); | ||
2210 | decoder->f_motion.pmv[1][1] = decoder->f_motion.pmv[0][1] = tmp; | ||
2211 | |||
2212 | DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */ | ||
2213 | } | ||
2214 | |||
2215 | static void motion_fi_conceal (mpeg2_decoder_t * const decoder) | ||
2216 | { | ||
2217 | int tmp; | ||
2218 | |||
2219 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
2220 | DUMPBITS (bit_buf, bits, 1); /* remove field_select */ | ||
2221 | |||
2222 | tmp = decoder->f_motion.pmv[0][0] + | ||
2223 | get_motion_delta (decoder, decoder->f_motion.f_code[0]); | ||
2224 | tmp = bound_motion_vector (tmp, decoder->f_motion.f_code[0]); | ||
2225 | |||
2226 | decoder->f_motion.pmv[1][0] = | ||
2227 | decoder->f_motion.pmv[0][0] = tmp; | ||
2228 | |||
2229 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
2230 | |||
2231 | tmp = (decoder->f_motion.pmv[0][1] + | ||
2232 | get_motion_delta (decoder, decoder->f_motion.f_code[1])); | ||
2233 | tmp = bound_motion_vector (tmp, decoder->f_motion.f_code[1]); | ||
2234 | |||
2235 | decoder->f_motion.pmv[1][1] = | ||
2236 | decoder->f_motion.pmv[0][1] = tmp; | ||
2237 | |||
2238 | DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */ | ||
2239 | } | ||
2240 | |||
2241 | #undef bit_buf | ||
2242 | #undef bits | ||
2243 | #undef bit_ptr | ||
2244 | |||
2245 | #define MOTION_CALL(routine, direction) \ | ||
2246 | do { \ | ||
2247 | if ((direction) & MACROBLOCK_MOTION_FORWARD) \ | ||
2248 | routine (decoder, &decoder->f_motion, mpeg2_mc.put); \ | ||
2249 | \ | ||
2250 | if ((direction) & MACROBLOCK_MOTION_BACKWARD) \ | ||
2251 | { \ | ||
2252 | routine (decoder, &decoder->b_motion, \ | ||
2253 | ((direction) & MACROBLOCK_MOTION_FORWARD ? \ | ||
2254 | mpeg2_mc.avg : mpeg2_mc.put)); \ | ||
2255 | } \ | ||
2256 | } while (0) | ||
2257 | |||
2258 | #define NEXT_MACROBLOCK \ | ||
2259 | do { \ | ||
2260 | decoder->offset += 16; \ | ||
2261 | \ | ||
2262 | if (decoder->offset == decoder->width) \ | ||
2263 | { \ | ||
2264 | do { /* just so we can use the break statement */ \ | ||
2265 | if (decoder->convert) \ | ||
2266 | { \ | ||
2267 | decoder->convert (decoder->convert_id, decoder->dest, \ | ||
2268 | decoder->v_offset); \ | ||
2269 | if (decoder->coding_type == B_TYPE) \ | ||
2270 | break; \ | ||
2271 | } \ | ||
2272 | \ | ||
2273 | decoder->dest[0] += decoder->slice_stride; \ | ||
2274 | if (MPEG2_COLOR) \ | ||
2275 | { \ | ||
2276 | decoder->dest[1] += decoder->slice_uv_stride; \ | ||
2277 | decoder->dest[2] += decoder->slice_uv_stride; \ | ||
2278 | } \ | ||
2279 | } while (0); \ | ||
2280 | \ | ||
2281 | decoder->v_offset += 16; \ | ||
2282 | \ | ||
2283 | if (decoder->v_offset > decoder->limit_y) \ | ||
2284 | return; \ | ||
2285 | \ | ||
2286 | decoder->offset = 0; \ | ||
2287 | } \ | ||
2288 | } while (0) | ||
2289 | |||
2290 | void mpeg2_init_fbuf (mpeg2_decoder_t * decoder, | ||
2291 | uint8_t * current_fbuf[MPEG2_COMPONENTS], | ||
2292 | uint8_t * forward_fbuf[MPEG2_COMPONENTS], | ||
2293 | uint8_t * backward_fbuf[MPEG2_COMPONENTS]) | ||
2294 | { | ||
2295 | int offset, stride, height, bottom_field; | ||
2296 | |||
2297 | stride = decoder->stride_frame; | ||
2298 | bottom_field = (decoder->picture_structure == BOTTOM_FIELD); | ||
2299 | offset = bottom_field ? stride : 0; | ||
2300 | height = decoder->height; | ||
2301 | |||
2302 | decoder->picture_dest[0] = current_fbuf[0] + offset; | ||
2303 | #if MPEG2_COLOR | ||
2304 | decoder->picture_dest[1] = current_fbuf[1] + (offset >> 1); | ||
2305 | decoder->picture_dest[2] = current_fbuf[2] + (offset >> 1); | ||
2306 | #endif | ||
2307 | |||
2308 | decoder->f_motion.ref[0][0] = forward_fbuf[0] + offset; | ||
2309 | #if MPEG2_COLOR | ||
2310 | decoder->f_motion.ref[0][1] = forward_fbuf[1] + (offset >> 1); | ||
2311 | decoder->f_motion.ref[0][2] = forward_fbuf[2] + (offset >> 1); | ||
2312 | #endif | ||
2313 | |||
2314 | decoder->b_motion.ref[0][0] = backward_fbuf[0] + offset; | ||
2315 | #if MPEG2_COLOR | ||
2316 | decoder->b_motion.ref[0][1] = backward_fbuf[1] + (offset >> 1); | ||
2317 | decoder->b_motion.ref[0][2] = backward_fbuf[2] + (offset >> 1); | ||
2318 | #endif | ||
2319 | |||
2320 | if (decoder->picture_structure != FRAME_PICTURE) | ||
2321 | { | ||
2322 | decoder->dmv_offset = bottom_field ? 1 : -1; | ||
2323 | decoder->f_motion.ref2[0] = decoder->f_motion.ref[bottom_field]; | ||
2324 | decoder->f_motion.ref2[1] = decoder->f_motion.ref[!bottom_field]; | ||
2325 | decoder->b_motion.ref2[0] = decoder->b_motion.ref[bottom_field]; | ||
2326 | decoder->b_motion.ref2[1] = decoder->b_motion.ref[!bottom_field]; | ||
2327 | offset = stride - offset; | ||
2328 | |||
2329 | if (decoder->second_field && (decoder->coding_type != B_TYPE)) | ||
2330 | forward_fbuf = current_fbuf; | ||
2331 | |||
2332 | decoder->f_motion.ref[1][0] = forward_fbuf[0] + offset; | ||
2333 | #if MPEG2_COLOR | ||
2334 | decoder->f_motion.ref[1][1] = forward_fbuf[1] + (offset >> 1); | ||
2335 | decoder->f_motion.ref[1][2] = forward_fbuf[2] + (offset >> 1); | ||
2336 | #endif | ||
2337 | decoder->b_motion.ref[1][0] = backward_fbuf[0] + offset; | ||
2338 | #if MPEG2_COLOR | ||
2339 | decoder->b_motion.ref[1][1] = backward_fbuf[1] + (offset >> 1); | ||
2340 | decoder->b_motion.ref[1][2] = backward_fbuf[2] + (offset >> 1); | ||
2341 | #endif | ||
2342 | stride <<= 1; | ||
2343 | height >>= 1; | ||
2344 | } | ||
2345 | |||
2346 | decoder->stride = stride; | ||
2347 | decoder->slice_stride = 16 * stride; | ||
2348 | #if MPEG2_COLOR | ||
2349 | decoder->uv_stride = stride >> 1; | ||
2350 | decoder->slice_uv_stride = | ||
2351 | decoder->slice_stride >> (2 - decoder->chroma_format); | ||
2352 | #endif | ||
2353 | decoder->limit_x = 2 * decoder->width - 32; | ||
2354 | decoder->limit_y_16 = 2 * height - 32; | ||
2355 | decoder->limit_y_8 = 2 * height - 16; | ||
2356 | decoder->limit_y = height - 16; | ||
2357 | |||
2358 | if (decoder->mpeg1) | ||
2359 | { | ||
2360 | decoder->motion_parser[0] = motion_zero_420; | ||
2361 | decoder->motion_parser[MC_FRAME] = motion_mp1; | ||
2362 | decoder->motion_parser[4] = motion_reuse_420; | ||
2363 | } | ||
2364 | else if (decoder->picture_structure == FRAME_PICTURE) | ||
2365 | { | ||
2366 | if (decoder->chroma_format == 0) | ||
2367 | { | ||
2368 | decoder->motion_parser[0] = motion_zero_420; | ||
2369 | decoder->motion_parser[MC_FIELD] = motion_fr_field_420; | ||
2370 | decoder->motion_parser[MC_FRAME] = motion_fr_frame_420; | ||
2371 | decoder->motion_parser[MC_DMV] = motion_fr_dmv_420; | ||
2372 | decoder->motion_parser[4] = motion_reuse_420; | ||
2373 | } | ||
2374 | else if (decoder->chroma_format == 1) | ||
2375 | { | ||
2376 | decoder->motion_parser[0] = motion_zero_422; | ||
2377 | decoder->motion_parser[MC_FIELD] = motion_fr_field_422; | ||
2378 | decoder->motion_parser[MC_FRAME] = motion_fr_frame_422; | ||
2379 | decoder->motion_parser[MC_DMV] = motion_fr_dmv_422; | ||
2380 | decoder->motion_parser[4] = motion_reuse_422; | ||
2381 | } | ||
2382 | else | ||
2383 | { | ||
2384 | decoder->motion_parser[0] = motion_zero_444; | ||
2385 | decoder->motion_parser[MC_FIELD] = motion_fr_field_444; | ||
2386 | decoder->motion_parser[MC_FRAME] = motion_fr_frame_444; | ||
2387 | decoder->motion_parser[MC_DMV] = motion_fr_dmv_444; | ||
2388 | decoder->motion_parser[4] = motion_reuse_444; | ||
2389 | } | ||
2390 | } | ||
2391 | else | ||
2392 | { | ||
2393 | if (decoder->chroma_format == 0) | ||
2394 | { | ||
2395 | decoder->motion_parser[0] = motion_zero_420; | ||
2396 | decoder->motion_parser[MC_FIELD] = motion_fi_field_420; | ||
2397 | decoder->motion_parser[MC_16X8] = motion_fi_16x8_420; | ||
2398 | decoder->motion_parser[MC_DMV] = motion_fi_dmv_420; | ||
2399 | decoder->motion_parser[4] = motion_reuse_420; | ||
2400 | } | ||
2401 | else if (decoder->chroma_format == 1) | ||
2402 | { | ||
2403 | decoder->motion_parser[0] = motion_zero_422; | ||
2404 | decoder->motion_parser[MC_FIELD] = motion_fi_field_422; | ||
2405 | decoder->motion_parser[MC_16X8] = motion_fi_16x8_422; | ||
2406 | decoder->motion_parser[MC_DMV] = motion_fi_dmv_422; | ||
2407 | decoder->motion_parser[4] = motion_reuse_422; | ||
2408 | } | ||
2409 | else | ||
2410 | { | ||
2411 | decoder->motion_parser[0] = motion_zero_444; | ||
2412 | decoder->motion_parser[MC_FIELD] = motion_fi_field_444; | ||
2413 | decoder->motion_parser[MC_16X8] = motion_fi_16x8_444; | ||
2414 | decoder->motion_parser[MC_DMV] = motion_fi_dmv_444; | ||
2415 | decoder->motion_parser[4] = motion_reuse_444; | ||
2416 | } | ||
2417 | } | ||
2418 | } | ||
2419 | |||
2420 | static inline int slice_init (mpeg2_decoder_t * const decoder, int code) | ||
2421 | { | ||
2422 | #define bit_buf (decoder->bitstream_buf) | ||
2423 | #define bits (decoder->bitstream_bits) | ||
2424 | #define bit_ptr (decoder->bitstream_ptr) | ||
2425 | |||
2426 | int offset; | ||
2427 | const MBAtab * mba; | ||
2428 | |||
2429 | #if MPEG2_COLOR | ||
2430 | decoder->dc_dct_pred[0] = decoder->dc_dct_pred[1] = | ||
2431 | decoder->dc_dct_pred[2] = 16384; | ||
2432 | #else | ||
2433 | decoder->dc_dct_pred[0] = 16384; | ||
2434 | #endif | ||
2435 | |||
2436 | decoder->f_motion.pmv[0][0] = decoder->f_motion.pmv[0][1] = 0; | ||
2437 | decoder->f_motion.pmv[1][0] = decoder->f_motion.pmv[1][1] = 0; | ||
2438 | decoder->b_motion.pmv[0][0] = decoder->b_motion.pmv[0][1] = 0; | ||
2439 | decoder->b_motion.pmv[1][0] = decoder->b_motion.pmv[1][1] = 0; | ||
2440 | |||
2441 | if (decoder->vertical_position_extension) | ||
2442 | { | ||
2443 | code += UBITS (bit_buf, 3) << 7; | ||
2444 | DUMPBITS (bit_buf, bits, 3); | ||
2445 | } | ||
2446 | |||
2447 | decoder->v_offset = (code - 1) * 16; | ||
2448 | offset = 0; | ||
2449 | |||
2450 | if (!(decoder->convert) || decoder->coding_type != B_TYPE) | ||
2451 | { | ||
2452 | offset = (code - 1) * decoder->slice_stride; | ||
2453 | } | ||
2454 | |||
2455 | decoder->dest[0] = decoder->picture_dest[0] + offset; | ||
2456 | #if MPEG2_COLOR | ||
2457 | offset >>= (2 - decoder->chroma_format); | ||
2458 | decoder->dest[1] = decoder->picture_dest[1] + offset; | ||
2459 | decoder->dest[2] = decoder->picture_dest[2] + offset; | ||
2460 | #endif | ||
2461 | |||
2462 | get_quantizer_scale (decoder); | ||
2463 | |||
2464 | /* ignore intra_slice and all the extra data */ | ||
2465 | while (bit_buf & 0x80000000) | ||
2466 | { | ||
2467 | DUMPBITS (bit_buf, bits, 9); | ||
2468 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
2469 | } | ||
2470 | |||
2471 | /* decode initial macroblock address increment */ | ||
2472 | offset = 0; | ||
2473 | while (1) | ||
2474 | { | ||
2475 | if (bit_buf >= 0x08000000) | ||
2476 | { | ||
2477 | mba = MBA_5 + (UBITS (bit_buf, 6) - 2); | ||
2478 | break; | ||
2479 | } | ||
2480 | else if (bit_buf >= 0x01800000) | ||
2481 | { | ||
2482 | mba = MBA_11 + (UBITS (bit_buf, 12) - 24); | ||
2483 | break; | ||
2484 | } | ||
2485 | else | ||
2486 | { | ||
2487 | switch (UBITS (bit_buf, 12)) | ||
2488 | { | ||
2489 | case 8: /* macroblock_escape */ | ||
2490 | offset += 33; | ||
2491 | DUMPBITS (bit_buf, bits, 11); | ||
2492 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
2493 | continue; | ||
2494 | case 15: /* macroblock_stuffing (MPEG1 only) */ | ||
2495 | bit_buf &= 0xfffff; | ||
2496 | DUMPBITS (bit_buf, bits, 11); | ||
2497 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
2498 | continue; | ||
2499 | default: /* error */ | ||
2500 | return 1; | ||
2501 | } | ||
2502 | } | ||
2503 | } | ||
2504 | |||
2505 | DUMPBITS (bit_buf, bits, mba->len + 1); | ||
2506 | decoder->offset = (offset + mba->mba) << 4; | ||
2507 | |||
2508 | while (decoder->offset - decoder->width >= 0) | ||
2509 | { | ||
2510 | decoder->offset -= decoder->width; | ||
2511 | |||
2512 | if (!(decoder->convert) || decoder->coding_type != B_TYPE) | ||
2513 | { | ||
2514 | decoder->dest[0] += decoder->slice_stride; | ||
2515 | #if MPEG2_COLOR | ||
2516 | decoder->dest[1] += decoder->slice_uv_stride; | ||
2517 | decoder->dest[2] += decoder->slice_uv_stride; | ||
2518 | #endif | ||
2519 | } | ||
2520 | |||
2521 | decoder->v_offset += 16; | ||
2522 | } | ||
2523 | |||
2524 | if (decoder->v_offset > decoder->limit_y) | ||
2525 | return 1; | ||
2526 | |||
2527 | return 0; | ||
2528 | |||
2529 | #undef bit_buf | ||
2530 | #undef bits | ||
2531 | #undef bit_ptr | ||
2532 | } | ||
2533 | |||
2534 | void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code, | ||
2535 | const uint8_t * const buffer) | ||
2536 | { | ||
2537 | #define bit_buf (decoder->bitstream_buf) | ||
2538 | #define bits (decoder->bitstream_bits) | ||
2539 | #define bit_ptr (decoder->bitstream_ptr) | ||
2540 | |||
2541 | bitstream_init (decoder, buffer); | ||
2542 | |||
2543 | if (slice_init (decoder, code)) | ||
2544 | return; | ||
2545 | |||
2546 | while (1) | ||
2547 | { | ||
2548 | int macroblock_modes; | ||
2549 | int mba_inc; | ||
2550 | const MBAtab * mba; | ||
2551 | |||
2552 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
2553 | |||
2554 | macroblock_modes = get_macroblock_modes (decoder); | ||
2555 | |||
2556 | /* maybe integrate MACROBLOCK_QUANT test into get_macroblock_modes ? */ | ||
2557 | if (macroblock_modes & MACROBLOCK_QUANT) | ||
2558 | get_quantizer_scale (decoder); | ||
2559 | |||
2560 | if (macroblock_modes & MACROBLOCK_INTRA) | ||
2561 | { | ||
2562 | int DCT_offset, DCT_stride; | ||
2563 | int offset; | ||
2564 | uint8_t * dest_y; | ||
2565 | |||
2566 | if (decoder->concealment_motion_vectors) | ||
2567 | { | ||
2568 | if (decoder->picture_structure == FRAME_PICTURE) | ||
2569 | motion_fr_conceal (decoder); | ||
2570 | else | ||
2571 | motion_fi_conceal (decoder); | ||
2572 | } | ||
2573 | else | ||
2574 | { | ||
2575 | decoder->f_motion.pmv[0][0] = decoder->f_motion.pmv[0][1] = 0; | ||
2576 | decoder->f_motion.pmv[1][0] = decoder->f_motion.pmv[1][1] = 0; | ||
2577 | decoder->b_motion.pmv[0][0] = decoder->b_motion.pmv[0][1] = 0; | ||
2578 | decoder->b_motion.pmv[1][0] = decoder->b_motion.pmv[1][1] = 0; | ||
2579 | } | ||
2580 | |||
2581 | if (macroblock_modes & DCT_TYPE_INTERLACED) | ||
2582 | { | ||
2583 | DCT_offset = decoder->stride; | ||
2584 | DCT_stride = decoder->stride * 2; | ||
2585 | } | ||
2586 | else | ||
2587 | { | ||
2588 | DCT_offset = decoder->stride * 8; | ||
2589 | DCT_stride = decoder->stride; | ||
2590 | } | ||
2591 | |||
2592 | offset = decoder->offset; | ||
2593 | dest_y = decoder->dest[0] + offset; | ||
2594 | slice_intra_DCT (decoder, 0, dest_y, DCT_stride); | ||
2595 | slice_intra_DCT (decoder, 0, dest_y + 8, DCT_stride); | ||
2596 | slice_intra_DCT (decoder, 0, dest_y + DCT_offset, DCT_stride); | ||
2597 | slice_intra_DCT (decoder, 0, dest_y + DCT_offset + 8, DCT_stride); | ||
2598 | |||
2599 | #if MPEG2_COLOR | ||
2600 | if (likely (decoder->chroma_format == 0)) | ||
2601 | { | ||
2602 | slice_intra_DCT (decoder, 1, decoder->dest[1] + (offset >> 1), | ||
2603 | decoder->uv_stride); | ||
2604 | slice_intra_DCT (decoder, 2, decoder->dest[2] + (offset >> 1), | ||
2605 | decoder->uv_stride); | ||
2606 | |||
2607 | if (decoder->coding_type == D_TYPE) | ||
2608 | { | ||
2609 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
2610 | DUMPBITS (bit_buf, bits, 1); | ||
2611 | } | ||
2612 | } | ||
2613 | else if (likely (decoder->chroma_format == 1)) | ||
2614 | { | ||
2615 | uint8_t * dest_u = decoder->dest[1] + (offset >> 1); | ||
2616 | uint8_t * dest_v = decoder->dest[2] + (offset >> 1); | ||
2617 | |||
2618 | DCT_stride >>= 1; | ||
2619 | DCT_offset >>= 1; | ||
2620 | |||
2621 | slice_intra_DCT (decoder, 1, dest_u, DCT_stride); | ||
2622 | slice_intra_DCT (decoder, 2, dest_v, DCT_stride); | ||
2623 | slice_intra_DCT (decoder, 1, dest_u + DCT_offset, DCT_stride); | ||
2624 | slice_intra_DCT (decoder, 2, dest_v + DCT_offset, DCT_stride); | ||
2625 | } | ||
2626 | else | ||
2627 | { | ||
2628 | uint8_t * dest_u = decoder->dest[1] + offset; | ||
2629 | uint8_t * dest_v = decoder->dest[2] + offset; | ||
2630 | |||
2631 | slice_intra_DCT (decoder, 1, dest_u, DCT_stride); | ||
2632 | slice_intra_DCT (decoder, 2, dest_v, DCT_stride); | ||
2633 | slice_intra_DCT (decoder, 1, dest_u + DCT_offset, DCT_stride); | ||
2634 | slice_intra_DCT (decoder, 2, dest_v + DCT_offset, DCT_stride); | ||
2635 | slice_intra_DCT (decoder, 1, dest_u + 8, DCT_stride); | ||
2636 | slice_intra_DCT (decoder, 2, dest_v + 8, DCT_stride); | ||
2637 | slice_intra_DCT (decoder, 1, dest_u + DCT_offset + 8, | ||
2638 | DCT_stride); | ||
2639 | slice_intra_DCT (decoder, 2, dest_v + DCT_offset + 8, | ||
2640 | DCT_stride); | ||
2641 | } | ||
2642 | #else | ||
2643 | skip_chroma_intra(decoder); | ||
2644 | #endif /* MPEG2_COLOR */ | ||
2645 | } | ||
2646 | else | ||
2647 | { | ||
2648 | motion_parser_t * parser; | ||
2649 | |||
2650 | parser = | ||
2651 | decoder->motion_parser[macroblock_modes >> MOTION_TYPE_SHIFT]; | ||
2652 | MOTION_CALL (parser, macroblock_modes); | ||
2653 | |||
2654 | if (macroblock_modes & MACROBLOCK_PATTERN) | ||
2655 | { | ||
2656 | int coded_block_pattern; | ||
2657 | int DCT_offset, DCT_stride; | ||
2658 | |||
2659 | if (macroblock_modes & DCT_TYPE_INTERLACED) | ||
2660 | { | ||
2661 | DCT_offset = decoder->stride; | ||
2662 | DCT_stride = decoder->stride * 2; | ||
2663 | } | ||
2664 | else | ||
2665 | { | ||
2666 | DCT_offset = decoder->stride * 8; | ||
2667 | DCT_stride = decoder->stride; | ||
2668 | } | ||
2669 | |||
2670 | coded_block_pattern = get_coded_block_pattern (decoder); | ||
2671 | |||
2672 | if (likely (decoder->chroma_format == 0)) | ||
2673 | { | ||
2674 | int offset = decoder->offset; | ||
2675 | uint8_t * dest_y = decoder->dest[0] + offset; | ||
2676 | |||
2677 | if (coded_block_pattern & 1) | ||
2678 | slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride); | ||
2679 | |||
2680 | if (coded_block_pattern & 2) | ||
2681 | slice_non_intra_DCT (decoder, 0, dest_y + 8, | ||
2682 | DCT_stride); | ||
2683 | |||
2684 | if (coded_block_pattern & 4) | ||
2685 | slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset, | ||
2686 | DCT_stride); | ||
2687 | |||
2688 | if (coded_block_pattern & 8) | ||
2689 | slice_non_intra_DCT (decoder, 0, | ||
2690 | dest_y + DCT_offset + 8, | ||
2691 | DCT_stride); | ||
2692 | #if MPEG2_COLOR | ||
2693 | if (coded_block_pattern & 16) | ||
2694 | slice_non_intra_DCT (decoder, 1, | ||
2695 | decoder->dest[1] + (offset >> 1), | ||
2696 | decoder->uv_stride); | ||
2697 | |||
2698 | if (coded_block_pattern & 32) | ||
2699 | slice_non_intra_DCT (decoder, 2, | ||
2700 | decoder->dest[2] + (offset >> 1), | ||
2701 | decoder->uv_stride); | ||
2702 | #endif /* MPEG2_COLOR */ | ||
2703 | } | ||
2704 | else if (likely (decoder->chroma_format == 1)) | ||
2705 | { | ||
2706 | int offset; | ||
2707 | uint8_t * dest_y; | ||
2708 | |||
2709 | coded_block_pattern |= bit_buf & (3 << 30); | ||
2710 | DUMPBITS (bit_buf, bits, 2); | ||
2711 | |||
2712 | offset = decoder->offset; | ||
2713 | dest_y = decoder->dest[0] + offset; | ||
2714 | |||
2715 | if (coded_block_pattern & 1) | ||
2716 | slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride); | ||
2717 | |||
2718 | if (coded_block_pattern & 2) | ||
2719 | slice_non_intra_DCT (decoder, 0, dest_y + 8, | ||
2720 | DCT_stride); | ||
2721 | |||
2722 | if (coded_block_pattern & 4) | ||
2723 | slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset, | ||
2724 | DCT_stride); | ||
2725 | |||
2726 | if (coded_block_pattern & 8) | ||
2727 | slice_non_intra_DCT (decoder, 0, | ||
2728 | dest_y + DCT_offset + 8, | ||
2729 | DCT_stride); | ||
2730 | #if MPEG2_COLOR | ||
2731 | DCT_stride >>= 1; | ||
2732 | DCT_offset = (DCT_offset + offset) >> 1; | ||
2733 | |||
2734 | if (coded_block_pattern & 16) | ||
2735 | slice_non_intra_DCT (decoder, 1, | ||
2736 | decoder->dest[1] + (offset >> 1), | ||
2737 | DCT_stride); | ||
2738 | |||
2739 | if (coded_block_pattern & 32) | ||
2740 | slice_non_intra_DCT (decoder, 2, | ||
2741 | decoder->dest[2] + (offset >> 1), | ||
2742 | DCT_stride); | ||
2743 | |||
2744 | if (coded_block_pattern & (2 << 30)) | ||
2745 | slice_non_intra_DCT (decoder, 1, | ||
2746 | decoder->dest[1] + DCT_offset, | ||
2747 | DCT_stride); | ||
2748 | |||
2749 | if (coded_block_pattern & (1 << 30)) | ||
2750 | slice_non_intra_DCT (decoder, 2, | ||
2751 | decoder->dest[2] + DCT_offset, | ||
2752 | DCT_stride); | ||
2753 | #endif /* MPEG2_COLOR */ | ||
2754 | } | ||
2755 | else | ||
2756 | { | ||
2757 | int offset = decoder->offset; | ||
2758 | uint8_t * dest_y = decoder->dest[0] + offset; | ||
2759 | #if MPEG2_COLOR | ||
2760 | uint8_t * dest_u = decoder->dest[1] + offset; | ||
2761 | uint8_t * dest_v = decoder->dest[2] + offset; | ||
2762 | #endif | ||
2763 | coded_block_pattern |= bit_buf & (63 << 26); | ||
2764 | DUMPBITS (bit_buf, bits, 6); | ||
2765 | |||
2766 | if (coded_block_pattern & 1) | ||
2767 | slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride); | ||
2768 | |||
2769 | if (coded_block_pattern & 2) | ||
2770 | slice_non_intra_DCT (decoder, 0, dest_y + 8, | ||
2771 | DCT_stride); | ||
2772 | |||
2773 | if (coded_block_pattern & 4) | ||
2774 | slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset, | ||
2775 | DCT_stride); | ||
2776 | |||
2777 | if (coded_block_pattern & 8) | ||
2778 | slice_non_intra_DCT (decoder, 0, | ||
2779 | dest_y + DCT_offset + 8, | ||
2780 | DCT_stride); | ||
2781 | #if MPEG2_COLOR | ||
2782 | if (coded_block_pattern & 16) | ||
2783 | slice_non_intra_DCT (decoder, 1, dest_u, DCT_stride); | ||
2784 | |||
2785 | if (coded_block_pattern & 32) | ||
2786 | slice_non_intra_DCT (decoder, 2, dest_v, DCT_stride); | ||
2787 | |||
2788 | if (coded_block_pattern & (32 << 26)) | ||
2789 | slice_non_intra_DCT (decoder, 1, dest_u + DCT_offset, | ||
2790 | DCT_stride); | ||
2791 | |||
2792 | if (coded_block_pattern & (16 << 26)) | ||
2793 | slice_non_intra_DCT (decoder, 2, dest_v + DCT_offset, | ||
2794 | DCT_stride); | ||
2795 | |||
2796 | if (coded_block_pattern & (8 << 26)) | ||
2797 | slice_non_intra_DCT (decoder, 1, dest_u + 8, | ||
2798 | DCT_stride); | ||
2799 | |||
2800 | if (coded_block_pattern & (4 << 26)) | ||
2801 | slice_non_intra_DCT (decoder, 2, dest_v + 8, | ||
2802 | DCT_stride); | ||
2803 | |||
2804 | if (coded_block_pattern & (2 << 26)) | ||
2805 | slice_non_intra_DCT (decoder, 1, | ||
2806 | dest_u + DCT_offset + 8, | ||
2807 | DCT_stride); | ||
2808 | |||
2809 | if (coded_block_pattern & (1 << 26)) | ||
2810 | slice_non_intra_DCT (decoder, 2, | ||
2811 | dest_v + DCT_offset + 8, | ||
2812 | DCT_stride); | ||
2813 | #endif /* MPEG2_COLOR */ | ||
2814 | } | ||
2815 | #if !MPEG2_COLOR | ||
2816 | skip_chroma_non_intra(decoder, coded_block_pattern); | ||
2817 | #endif | ||
2818 | } | ||
2819 | |||
2820 | #if MPEG2_COLOR | ||
2821 | decoder->dc_dct_pred[0] = decoder->dc_dct_pred[1] = | ||
2822 | decoder->dc_dct_pred[2] = 16384; | ||
2823 | #else | ||
2824 | decoder->dc_dct_pred[0] = 16384; | ||
2825 | #endif | ||
2826 | } | ||
2827 | |||
2828 | NEXT_MACROBLOCK; | ||
2829 | |||
2830 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
2831 | mba_inc = 0; | ||
2832 | |||
2833 | while (1) | ||
2834 | { | ||
2835 | if (bit_buf >= 0x10000000) | ||
2836 | { | ||
2837 | mba = MBA_5 + (UBITS (bit_buf, 5) - 2); | ||
2838 | break; | ||
2839 | } | ||
2840 | else if (bit_buf >= 0x03000000) | ||
2841 | { | ||
2842 | mba = MBA_11 + (UBITS (bit_buf, 11) - 24); | ||
2843 | break; | ||
2844 | } | ||
2845 | else | ||
2846 | { | ||
2847 | switch (UBITS (bit_buf, 11)) | ||
2848 | { | ||
2849 | case 8: /* macroblock_escape */ | ||
2850 | mba_inc += 33; | ||
2851 | /* pass through */ | ||
2852 | case 15: /* macroblock_stuffing (MPEG1 only) */ | ||
2853 | DUMPBITS (bit_buf, bits, 11); | ||
2854 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
2855 | continue; | ||
2856 | default: /* end of slice, or error */ | ||
2857 | return; | ||
2858 | } | ||
2859 | } | ||
2860 | } | ||
2861 | |||
2862 | DUMPBITS (bit_buf, bits, mba->len); | ||
2863 | mba_inc += mba->mba; | ||
2864 | |||
2865 | if (mba_inc) | ||
2866 | { | ||
2867 | #if MPEG2_COLOR | ||
2868 | decoder->dc_dct_pred[0] = decoder->dc_dct_pred[1] = | ||
2869 | decoder->dc_dct_pred[2] = 16384; | ||
2870 | #else | ||
2871 | decoder->dc_dct_pred[0] = 16384; | ||
2872 | #endif | ||
2873 | if (decoder->coding_type == P_TYPE) | ||
2874 | { | ||
2875 | do | ||
2876 | { | ||
2877 | MOTION_CALL (decoder->motion_parser[0], | ||
2878 | MACROBLOCK_MOTION_FORWARD); | ||
2879 | NEXT_MACROBLOCK; | ||
2880 | } | ||
2881 | while (--mba_inc); | ||
2882 | } | ||
2883 | else | ||
2884 | { | ||
2885 | do | ||
2886 | { | ||
2887 | MOTION_CALL (decoder->motion_parser[4], macroblock_modes); | ||
2888 | NEXT_MACROBLOCK; | ||
2889 | } | ||
2890 | while (--mba_inc); | ||
2891 | } | ||
2892 | } | ||
2893 | } | ||
2894 | |||
2895 | #undef bit_buf | ||
2896 | #undef bits | ||
2897 | #undef bit_ptr | ||
2898 | } | ||
diff --git a/apps/plugins/mpegplayer/libmpeg2/vlc.h b/apps/plugins/mpegplayer/libmpeg2/vlc.h new file mode 100644 index 0000000000..d1b6a98cde --- /dev/null +++ b/apps/plugins/mpegplayer/libmpeg2/vlc.h | |||
@@ -0,0 +1,433 @@ | |||
1 | /* | ||
2 | * vlc.h | ||
3 | * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> | ||
4 | * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | ||
5 | * | ||
6 | * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. | ||
7 | * See http://libmpeg2.sourceforge.net/ for updates. | ||
8 | * | ||
9 | * mpeg2dec is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * mpeg2dec is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | ||
23 | * $Id$ | ||
24 | * libmpeg2 sync history: | ||
25 | * 2008-07-01 - CVS revision 1.12 | ||
26 | */ | ||
27 | |||
28 | #define GETWORD(bit_buf, shift, bit_ptr) \ | ||
29 | do { \ | ||
30 | bit_buf |= ((bit_ptr[0] << 8) | bit_ptr[1]) << (shift); \ | ||
31 | bit_ptr += 2; \ | ||
32 | } while (0) | ||
33 | |||
34 | static inline void bitstream_init (mpeg2_decoder_t * decoder, | ||
35 | const uint8_t * start) | ||
36 | { | ||
37 | decoder->bitstream_buf = | ||
38 | (start[0] << 24) | (start[1] << 16) | (start[2] << 8) | start[3]; | ||
39 | decoder->bitstream_ptr = start + 4; | ||
40 | decoder->bitstream_bits = -16; | ||
41 | } | ||
42 | |||
43 | /* make sure that there are at least 16 valid bits in bit_buf */ | ||
44 | #define NEEDBITS(bit_buf, bits, bit_ptr) \ | ||
45 | do { \ | ||
46 | if (unlikely (bits > 0)) { \ | ||
47 | GETWORD (bit_buf, bits, bit_ptr); \ | ||
48 | bits -= 16; \ | ||
49 | } \ | ||
50 | } while (0) | ||
51 | |||
52 | /* remove num valid bits from bit_buf */ | ||
53 | #define DUMPBITS(bit_buf, bits, num) \ | ||
54 | do { \ | ||
55 | bit_buf <<= (num); \ | ||
56 | bits += (num); \ | ||
57 | } while (0) | ||
58 | |||
59 | /* take num bits from the high part of bit_buf and zero extend them */ | ||
60 | #define UBITS(bit_buf,num) (((uint32_t)(bit_buf)) >> (32 - (num))) | ||
61 | |||
62 | /* take num bits from the high part of bit_buf and sign extend them */ | ||
63 | #define SBITS(bit_buf,num) (((int32_t)(bit_buf)) >> (32 - (num))) | ||
64 | |||
65 | typedef struct { | ||
66 | uint8_t modes; | ||
67 | uint8_t len; | ||
68 | } MBtab; | ||
69 | |||
70 | typedef struct { | ||
71 | uint8_t delta; | ||
72 | uint8_t len; | ||
73 | } MVtab; | ||
74 | |||
75 | typedef struct { | ||
76 | int8_t dmv; | ||
77 | uint8_t len; | ||
78 | } DMVtab; | ||
79 | |||
80 | typedef struct { | ||
81 | uint8_t cbp; | ||
82 | uint8_t len; | ||
83 | } CBPtab; | ||
84 | |||
85 | typedef struct { | ||
86 | uint8_t size; | ||
87 | uint8_t len; | ||
88 | } DCtab; | ||
89 | |||
90 | typedef struct { | ||
91 | uint8_t run; | ||
92 | uint8_t level; | ||
93 | uint8_t len; | ||
94 | } DCTtab; | ||
95 | |||
96 | typedef struct { | ||
97 | uint8_t mba; | ||
98 | uint8_t len; | ||
99 | } MBAtab; | ||
100 | |||
101 | |||
102 | #define INTRA MACROBLOCK_INTRA | ||
103 | #define QUANT MACROBLOCK_QUANT | ||
104 | |||
105 | static const MBtab MB_I [] ICONST_ATTR = { | ||
106 | {INTRA|QUANT, 2}, {INTRA, 1} | ||
107 | }; | ||
108 | |||
109 | #define MC MACROBLOCK_MOTION_FORWARD | ||
110 | #define CODED MACROBLOCK_PATTERN | ||
111 | |||
112 | static const MBtab MB_P [] ICONST_ATTR = { | ||
113 | {INTRA|QUANT, 6}, {CODED|QUANT, 5}, {MC|CODED|QUANT, 5}, {INTRA, 5}, | ||
114 | {MC, 3}, {MC, 3}, {MC, 3}, {MC, 3}, | ||
115 | {CODED, 2}, {CODED, 2}, {CODED, 2}, {CODED, 2}, | ||
116 | {CODED, 2}, {CODED, 2}, {CODED, 2}, {CODED, 2}, | ||
117 | {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, | ||
118 | {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, | ||
119 | {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, | ||
120 | {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1} | ||
121 | }; | ||
122 | |||
123 | #define FWD MACROBLOCK_MOTION_FORWARD | ||
124 | #define BWD MACROBLOCK_MOTION_BACKWARD | ||
125 | #define INTER MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD | ||
126 | |||
127 | static const MBtab MB_B [] ICONST_ATTR = { | ||
128 | {0, 6}, {INTRA|QUANT, 6}, | ||
129 | {BWD|CODED|QUANT, 6}, {FWD|CODED|QUANT, 6}, | ||
130 | {INTER|CODED|QUANT, 5}, {INTER|CODED|QUANT, 5}, | ||
131 | {INTRA, 5}, {INTRA, 5}, | ||
132 | {FWD, 4}, {FWD, 4}, {FWD, 4}, {FWD, 4}, | ||
133 | {FWD|CODED, 4}, {FWD|CODED, 4}, {FWD|CODED, 4}, {FWD|CODED, 4}, | ||
134 | {BWD, 3}, {BWD, 3}, {BWD, 3}, {BWD, 3}, | ||
135 | {BWD, 3}, {BWD, 3}, {BWD, 3}, {BWD, 3}, | ||
136 | {BWD|CODED, 3}, {BWD|CODED, 3}, {BWD|CODED, 3}, {BWD|CODED, 3}, | ||
137 | {BWD|CODED, 3}, {BWD|CODED, 3}, {BWD|CODED, 3}, {BWD|CODED, 3}, | ||
138 | {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2}, | ||
139 | {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2}, | ||
140 | {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2}, | ||
141 | {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2}, | ||
142 | {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, | ||
143 | {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, | ||
144 | {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, | ||
145 | {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2} | ||
146 | }; | ||
147 | |||
148 | #undef INTRA | ||
149 | #undef QUANT | ||
150 | #undef MC | ||
151 | #undef CODED | ||
152 | #undef FWD | ||
153 | #undef BWD | ||
154 | #undef INTER | ||
155 | |||
156 | |||
157 | static const MVtab MV_4 [] ICONST_ATTR = { | ||
158 | { 3, 6}, { 2, 4}, { 1, 3}, { 1, 3}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2} | ||
159 | }; | ||
160 | |||
161 | static const MVtab MV_10 [] ICONST_ATTR = { | ||
162 | { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, | ||
163 | { 0,10}, { 0,10}, { 0,10}, { 0,10}, {15,10}, {14,10}, {13,10}, {12,10}, | ||
164 | {11,10}, {10,10}, { 9, 9}, { 9, 9}, { 8, 9}, { 8, 9}, { 7, 9}, { 7, 9}, | ||
165 | { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7}, | ||
166 | { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7}, | ||
167 | { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7} | ||
168 | }; | ||
169 | |||
170 | |||
171 | static const DMVtab DMV_2 [] ICONST_ATTR = { | ||
172 | { 0, 1}, { 0, 1}, { 1, 2}, {-1, 2} | ||
173 | }; | ||
174 | |||
175 | |||
176 | static const CBPtab CBP_7 [] ICONST_ATTR = { | ||
177 | {0x11, 7}, {0x12, 7}, {0x14, 7}, {0x18, 7}, | ||
178 | {0x21, 7}, {0x22, 7}, {0x24, 7}, {0x28, 7}, | ||
179 | {0x3f, 6}, {0x3f, 6}, {0x30, 6}, {0x30, 6}, | ||
180 | {0x09, 6}, {0x09, 6}, {0x06, 6}, {0x06, 6}, | ||
181 | {0x1f, 5}, {0x1f, 5}, {0x1f, 5}, {0x1f, 5}, | ||
182 | {0x10, 5}, {0x10, 5}, {0x10, 5}, {0x10, 5}, | ||
183 | {0x2f, 5}, {0x2f, 5}, {0x2f, 5}, {0x2f, 5}, | ||
184 | {0x20, 5}, {0x20, 5}, {0x20, 5}, {0x20, 5}, | ||
185 | {0x07, 5}, {0x07, 5}, {0x07, 5}, {0x07, 5}, | ||
186 | {0x0b, 5}, {0x0b, 5}, {0x0b, 5}, {0x0b, 5}, | ||
187 | {0x0d, 5}, {0x0d, 5}, {0x0d, 5}, {0x0d, 5}, | ||
188 | {0x0e, 5}, {0x0e, 5}, {0x0e, 5}, {0x0e, 5}, | ||
189 | {0x05, 5}, {0x05, 5}, {0x05, 5}, {0x05, 5}, | ||
190 | {0x0a, 5}, {0x0a, 5}, {0x0a, 5}, {0x0a, 5}, | ||
191 | {0x03, 5}, {0x03, 5}, {0x03, 5}, {0x03, 5}, | ||
192 | {0x0c, 5}, {0x0c, 5}, {0x0c, 5}, {0x0c, 5}, | ||
193 | {0x01, 4}, {0x01, 4}, {0x01, 4}, {0x01, 4}, | ||
194 | {0x01, 4}, {0x01, 4}, {0x01, 4}, {0x01, 4}, | ||
195 | {0x02, 4}, {0x02, 4}, {0x02, 4}, {0x02, 4}, | ||
196 | {0x02, 4}, {0x02, 4}, {0x02, 4}, {0x02, 4}, | ||
197 | {0x04, 4}, {0x04, 4}, {0x04, 4}, {0x04, 4}, | ||
198 | {0x04, 4}, {0x04, 4}, {0x04, 4}, {0x04, 4}, | ||
199 | {0x08, 4}, {0x08, 4}, {0x08, 4}, {0x08, 4}, | ||
200 | {0x08, 4}, {0x08, 4}, {0x08, 4}, {0x08, 4}, | ||
201 | {0x0f, 3}, {0x0f, 3}, {0x0f, 3}, {0x0f, 3}, | ||
202 | {0x0f, 3}, {0x0f, 3}, {0x0f, 3}, {0x0f, 3}, | ||
203 | {0x0f, 3}, {0x0f, 3}, {0x0f, 3}, {0x0f, 3}, | ||
204 | {0x0f, 3}, {0x0f, 3}, {0x0f, 3}, {0x0f, 3} | ||
205 | }; | ||
206 | |||
207 | static const CBPtab CBP_9 [] ICONST_ATTR = { | ||
208 | {0, 9}, {0x00, 9}, {0x39, 9}, {0x36, 9}, | ||
209 | {0x37, 9}, {0x3b, 9}, {0x3d, 9}, {0x3e, 9}, | ||
210 | {0x17, 8}, {0x17, 8}, {0x1b, 8}, {0x1b, 8}, | ||
211 | {0x1d, 8}, {0x1d, 8}, {0x1e, 8}, {0x1e, 8}, | ||
212 | {0x27, 8}, {0x27, 8}, {0x2b, 8}, {0x2b, 8}, | ||
213 | {0x2d, 8}, {0x2d, 8}, {0x2e, 8}, {0x2e, 8}, | ||
214 | {0x19, 8}, {0x19, 8}, {0x16, 8}, {0x16, 8}, | ||
215 | {0x29, 8}, {0x29, 8}, {0x26, 8}, {0x26, 8}, | ||
216 | {0x35, 8}, {0x35, 8}, {0x3a, 8}, {0x3a, 8}, | ||
217 | {0x33, 8}, {0x33, 8}, {0x3c, 8}, {0x3c, 8}, | ||
218 | {0x15, 8}, {0x15, 8}, {0x1a, 8}, {0x1a, 8}, | ||
219 | {0x13, 8}, {0x13, 8}, {0x1c, 8}, {0x1c, 8}, | ||
220 | {0x25, 8}, {0x25, 8}, {0x2a, 8}, {0x2a, 8}, | ||
221 | {0x23, 8}, {0x23, 8}, {0x2c, 8}, {0x2c, 8}, | ||
222 | {0x31, 8}, {0x31, 8}, {0x32, 8}, {0x32, 8}, | ||
223 | {0x34, 8}, {0x34, 8}, {0x38, 8}, {0x38, 8} | ||
224 | }; | ||
225 | |||
226 | |||
227 | static const DCtab DC_lum_5 [] ICONST_ATTR = { | ||
228 | {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, | ||
229 | {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, | ||
230 | {0, 3}, {0, 3}, {0, 3}, {0, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, | ||
231 | {4, 3}, {4, 3}, {4, 3}, {4, 3}, {5, 4}, {5, 4}, {6, 5} | ||
232 | }; | ||
233 | |||
234 | static const DCtab DC_chrom_5 [] ICONST_ATTR = { | ||
235 | {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, | ||
236 | {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, | ||
237 | {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, | ||
238 | {3, 3}, {3, 3}, {3, 3}, {3, 3}, {4, 4}, {4, 4}, {5, 5} | ||
239 | }; | ||
240 | |||
241 | static const DCtab DC_long [] ICONST_ATTR = { | ||
242 | {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, { 6, 5}, { 6, 5}, | ||
243 | {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, { 6, 5}, { 6, 5}, | ||
244 | {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, { 7, 6}, { 7, 6}, | ||
245 | {8, 7}, {8, 7}, {8, 7}, {8, 7}, {9, 8}, {9, 8}, {10, 9}, {11, 9} | ||
246 | }; | ||
247 | |||
248 | |||
249 | static const DCTtab DCT_16 [] ICONST_ATTR = { | ||
250 | {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, | ||
251 | {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, | ||
252 | {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, | ||
253 | {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, | ||
254 | { 2,18, 0}, { 2,17, 0}, { 2,16, 0}, { 2,15, 0}, | ||
255 | { 7, 3, 0}, { 17, 2, 0}, { 16, 2, 0}, { 15, 2, 0}, | ||
256 | { 14, 2, 0}, { 13, 2, 0}, { 12, 2, 0}, { 32, 1, 0}, | ||
257 | { 31, 1, 0}, { 30, 1, 0}, { 29, 1, 0}, { 28, 1, 0} | ||
258 | }; | ||
259 | |||
260 | static const DCTtab DCT_15 [] ICONST_ATTR = { | ||
261 | { 1,40,15}, { 1,39,15}, { 1,38,15}, { 1,37,15}, | ||
262 | { 1,36,15}, { 1,35,15}, { 1,34,15}, { 1,33,15}, | ||
263 | { 1,32,15}, { 2,14,15}, { 2,13,15}, { 2,12,15}, | ||
264 | { 2,11,15}, { 2,10,15}, { 2, 9,15}, { 2, 8,15}, | ||
265 | { 1,31,14}, { 1,31,14}, { 1,30,14}, { 1,30,14}, | ||
266 | { 1,29,14}, { 1,29,14}, { 1,28,14}, { 1,28,14}, | ||
267 | { 1,27,14}, { 1,27,14}, { 1,26,14}, { 1,26,14}, | ||
268 | { 1,25,14}, { 1,25,14}, { 1,24,14}, { 1,24,14}, | ||
269 | { 1,23,14}, { 1,23,14}, { 1,22,14}, { 1,22,14}, | ||
270 | { 1,21,14}, { 1,21,14}, { 1,20,14}, { 1,20,14}, | ||
271 | { 1,19,14}, { 1,19,14}, { 1,18,14}, { 1,18,14}, | ||
272 | { 1,17,14}, { 1,17,14}, { 1,16,14}, { 1,16,14} | ||
273 | }; | ||
274 | |||
275 | static const DCTtab DCT_13 [] ICONST_ATTR = { | ||
276 | { 11, 2,13}, { 10, 2,13}, { 6, 3,13}, { 4, 4,13}, | ||
277 | { 3, 5,13}, { 2, 7,13}, { 2, 6,13}, { 1,15,13}, | ||
278 | { 1,14,13}, { 1,13,13}, { 1,12,13}, { 27, 1,13}, | ||
279 | { 26, 1,13}, { 25, 1,13}, { 24, 1,13}, { 23, 1,13}, | ||
280 | { 1,11,12}, { 1,11,12}, { 9, 2,12}, { 9, 2,12}, | ||
281 | { 5, 3,12}, { 5, 3,12}, { 1,10,12}, { 1,10,12}, | ||
282 | { 3, 4,12}, { 3, 4,12}, { 8, 2,12}, { 8, 2,12}, | ||
283 | { 22, 1,12}, { 22, 1,12}, { 21, 1,12}, { 21, 1,12}, | ||
284 | { 1, 9,12}, { 1, 9,12}, { 20, 1,12}, { 20, 1,12}, | ||
285 | { 19, 1,12}, { 19, 1,12}, { 2, 5,12}, { 2, 5,12}, | ||
286 | { 4, 3,12}, { 4, 3,12}, { 1, 8,12}, { 1, 8,12}, | ||
287 | { 7, 2,12}, { 7, 2,12}, { 18, 1,12}, { 18, 1,12} | ||
288 | }; | ||
289 | |||
290 | static const DCTtab DCT_B14_10 [] ICONST_ATTR = { | ||
291 | { 17, 1,10}, { 6, 2,10}, { 1, 7,10}, { 3, 3,10}, | ||
292 | { 2, 4,10}, { 16, 1,10}, { 15, 1,10}, { 5, 2,10} | ||
293 | }; | ||
294 | |||
295 | static const DCTtab DCT_B14_8 [] ICONST_ATTR = { | ||
296 | { 65, 0, 12}, { 65, 0, 12}, { 65, 0, 12}, { 65, 0, 12}, | ||
297 | { 3, 2, 7}, { 3, 2, 7}, { 10, 1, 7}, { 10, 1, 7}, | ||
298 | { 1, 4, 7}, { 1, 4, 7}, { 9, 1, 7}, { 9, 1, 7}, | ||
299 | { 8, 1, 6}, { 8, 1, 6}, { 8, 1, 6}, { 8, 1, 6}, | ||
300 | { 7, 1, 6}, { 7, 1, 6}, { 7, 1, 6}, { 7, 1, 6}, | ||
301 | { 2, 2, 6}, { 2, 2, 6}, { 2, 2, 6}, { 2, 2, 6}, | ||
302 | { 6, 1, 6}, { 6, 1, 6}, { 6, 1, 6}, { 6, 1, 6}, | ||
303 | { 14, 1, 8}, { 1, 6, 8}, { 13, 1, 8}, { 12, 1, 8}, | ||
304 | { 4, 2, 8}, { 2, 3, 8}, { 1, 5, 8}, { 11, 1, 8} | ||
305 | }; | ||
306 | |||
307 | static const DCTtab DCT_B14AC_5 [] ICONST_ATTR = { | ||
308 | { 1, 3, 5}, { 5, 1, 5}, { 4, 1, 5}, | ||
309 | { 1, 2, 4}, { 1, 2, 4}, { 3, 1, 4}, { 3, 1, 4}, | ||
310 | { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, | ||
311 | {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, | ||
312 | {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, | ||
313 | { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, | ||
314 | { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2} | ||
315 | }; | ||
316 | |||
317 | static const DCTtab DCT_B14DC_5 [] ICONST_ATTR = { | ||
318 | { 1, 3, 5}, { 5, 1, 5}, { 4, 1, 5}, | ||
319 | { 1, 2, 4}, { 1, 2, 4}, { 3, 1, 4}, { 3, 1, 4}, | ||
320 | { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, | ||
321 | { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1}, | ||
322 | { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1}, | ||
323 | { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1}, | ||
324 | { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1} | ||
325 | }; | ||
326 | |||
327 | static const DCTtab DCT_B15_10 [] ICONST_ATTR = { | ||
328 | { 6, 2, 9}, { 6, 2, 9}, { 15, 1, 9}, { 15, 1, 9}, | ||
329 | { 3, 4,10}, { 17, 1,10}, { 16, 1, 9}, { 16, 1, 9} | ||
330 | }; | ||
331 | |||
332 | static const DCTtab DCT_B15_8 [] ICONST_ATTR = { | ||
333 | { 65, 0, 12}, { 65, 0, 12}, { 65, 0, 12}, { 65, 0, 12}, | ||
334 | { 8, 1, 7}, { 8, 1, 7}, { 9, 1, 7}, { 9, 1, 7}, | ||
335 | { 7, 1, 7}, { 7, 1, 7}, { 3, 2, 7}, { 3, 2, 7}, | ||
336 | { 1, 7, 6}, { 1, 7, 6}, { 1, 7, 6}, { 1, 7, 6}, | ||
337 | { 1, 6, 6}, { 1, 6, 6}, { 1, 6, 6}, { 1, 6, 6}, | ||
338 | { 5, 1, 6}, { 5, 1, 6}, { 5, 1, 6}, { 5, 1, 6}, | ||
339 | { 6, 1, 6}, { 6, 1, 6}, { 6, 1, 6}, { 6, 1, 6}, | ||
340 | { 2, 5, 8}, { 12, 1, 8}, { 1,11, 8}, { 1,10, 8}, | ||
341 | { 14, 1, 8}, { 13, 1, 8}, { 4, 2, 8}, { 2, 4, 8}, | ||
342 | { 3, 1, 5}, { 3, 1, 5}, { 3, 1, 5}, { 3, 1, 5}, | ||
343 | { 3, 1, 5}, { 3, 1, 5}, { 3, 1, 5}, { 3, 1, 5}, | ||
344 | { 2, 2, 5}, { 2, 2, 5}, { 2, 2, 5}, { 2, 2, 5}, | ||
345 | { 2, 2, 5}, { 2, 2, 5}, { 2, 2, 5}, { 2, 2, 5}, | ||
346 | { 4, 1, 5}, { 4, 1, 5}, { 4, 1, 5}, { 4, 1, 5}, | ||
347 | { 4, 1, 5}, { 4, 1, 5}, { 4, 1, 5}, { 4, 1, 5}, | ||
348 | { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, | ||
349 | { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, | ||
350 | { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, | ||
351 | { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, | ||
352 | { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, | ||
353 | { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, | ||
354 | { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, | ||
355 | { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, | ||
356 | {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, | ||
357 | {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, | ||
358 | {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, | ||
359 | {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, | ||
360 | { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, | ||
361 | { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, | ||
362 | { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, | ||
363 | { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, | ||
364 | { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, | ||
365 | { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, | ||
366 | { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, | ||
367 | { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, | ||
368 | { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, | ||
369 | { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, | ||
370 | { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, | ||
371 | { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, | ||
372 | { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, | ||
373 | { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, | ||
374 | { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, | ||
375 | { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, | ||
376 | { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, | ||
377 | { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, | ||
378 | { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, | ||
379 | { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, | ||
380 | { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, | ||
381 | { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, | ||
382 | { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, | ||
383 | { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, | ||
384 | { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, | ||
385 | { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, | ||
386 | { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, | ||
387 | { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, | ||
388 | { 1, 4, 5}, { 1, 4, 5}, { 1, 4, 5}, { 1, 4, 5}, | ||
389 | { 1, 4, 5}, { 1, 4, 5}, { 1, 4, 5}, { 1, 4, 5}, | ||
390 | { 1, 5, 5}, { 1, 5, 5}, { 1, 5, 5}, { 1, 5, 5}, | ||
391 | { 1, 5, 5}, { 1, 5, 5}, { 1, 5, 5}, { 1, 5, 5}, | ||
392 | { 10, 1, 7}, { 10, 1, 7}, { 2, 3, 7}, { 2, 3, 7}, | ||
393 | { 11, 1, 7}, { 11, 1, 7}, { 1, 8, 7}, { 1, 8, 7}, | ||
394 | { 1, 9, 7}, { 1, 9, 7}, { 1,12, 8}, { 1,13, 8}, | ||
395 | { 3, 3, 8}, { 5, 2, 8}, { 1,14, 8}, { 1,15, 8} | ||
396 | }; | ||
397 | |||
398 | |||
399 | static const MBAtab MBA_5 [] ICONST_ATTR = { | ||
400 | {6, 5}, {5, 5}, {4, 4}, {4, 4}, {3, 4}, {3, 4}, | ||
401 | {2, 3}, {2, 3}, {2, 3}, {2, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, | ||
402 | {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, | ||
403 | {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1} | ||
404 | }; | ||
405 | |||
406 | static const MBAtab MBA_11 [] ICONST_ATTR = { | ||
407 | {32, 11}, {31, 11}, {30, 11}, {29, 11}, | ||
408 | {28, 11}, {27, 11}, {26, 11}, {25, 11}, | ||
409 | {24, 11}, {23, 11}, {22, 11}, {21, 11}, | ||
410 | {20, 10}, {20, 10}, {19, 10}, {19, 10}, | ||
411 | {18, 10}, {18, 10}, {17, 10}, {17, 10}, | ||
412 | {16, 10}, {16, 10}, {15, 10}, {15, 10}, | ||
413 | {14, 8}, {14, 8}, {14, 8}, {14, 8}, | ||
414 | {14, 8}, {14, 8}, {14, 8}, {14, 8}, | ||
415 | {13, 8}, {13, 8}, {13, 8}, {13, 8}, | ||
416 | {13, 8}, {13, 8}, {13, 8}, {13, 8}, | ||
417 | {12, 8}, {12, 8}, {12, 8}, {12, 8}, | ||
418 | {12, 8}, {12, 8}, {12, 8}, {12, 8}, | ||
419 | {11, 8}, {11, 8}, {11, 8}, {11, 8}, | ||
420 | {11, 8}, {11, 8}, {11, 8}, {11, 8}, | ||
421 | {10, 8}, {10, 8}, {10, 8}, {10, 8}, | ||
422 | {10, 8}, {10, 8}, {10, 8}, {10, 8}, | ||
423 | { 9, 8}, { 9, 8}, { 9, 8}, { 9, 8}, | ||
424 | { 9, 8}, { 9, 8}, { 9, 8}, { 9, 8}, | ||
425 | { 8, 7}, { 8, 7}, { 8, 7}, { 8, 7}, | ||
426 | { 8, 7}, { 8, 7}, { 8, 7}, { 8, 7}, | ||
427 | { 8, 7}, { 8, 7}, { 8, 7}, { 8, 7}, | ||
428 | { 8, 7}, { 8, 7}, { 8, 7}, { 8, 7}, | ||
429 | { 7, 7}, { 7, 7}, { 7, 7}, { 7, 7}, | ||
430 | { 7, 7}, { 7, 7}, { 7, 7}, { 7, 7}, | ||
431 | { 7, 7}, { 7, 7}, { 7, 7}, { 7, 7}, | ||
432 | { 7, 7}, { 7, 7}, { 7, 7}, { 7, 7} | ||
433 | }; | ||