+++ /dev/null
-AUTHORS
-=======
-
-This file lists all authors of XviD MPEG4 core library. If you think
-your name should appear on this list, please send us an email telling
-us your name, we will be pleased to add it here.
-
-The lists are classified by alphabetical order.
-
-
-Project initiators:
--------------------
-
-Christoph Lampert <gruel@web.de>
-Michael Militzer <isibaar@xvid.org>
-Peter Ross <pross@xvid.org>
-
-
-Regular contributors:
----------------------
-
-Edouard Gomez <ed.gomez@free.fr>
-Pascal Massimino <skal@planet-d.net>
-Radoslaw Czyz <xvid@syskin.cjb.net>
-
-
-Spontaneous contributors:
--------------------------
-
-Benjamin Herrenschmidt <benh@kernel.crashing.org>
-Daniel Smith <danielsmith@astroboymail.com>
-Dirk Knop <dknop@stud.uni-goettingen.de>
-Guillaume Morin <guillaume@morinfr.org>
-MinChen <chenm001@163.com>
-
-Last edited: $Date: 2005-07-13 14:36:12 $
+++ /dev/null
-//----------------------------
-// Symbian codec API
-//
-//----------------------------
-#include "rules.h"
-#include "global.h"
-#include "xvid.h"
-
-#ifdef __SYMBIAN32__
-#include <e32std.h>
-#include <e32base.h>
-//GLDEF_C TInt E32Dll(TDllReason){ return KErrNone; }
-#else
-#endif
-
-
-//----------------------------
-
-struct S_decoder{
- xvid_dec_frame_t xvid_dec_frame;
- dword size_x;
- void *dec_handle;
-};
-
-#define FCC(a, b, c, d) dword((d<<24) | (c<<16) | (b<<8) | a)
-
-//----------------------------
-
-void * InitCodec(dword sx, dword sy, dword fcc){
-
- switch(fcc){
- case FCC('x', 'v', 'i', 'd'):
- case FCC('X', 'V', 'I', 'D'):
- case FCC('D', 'I', 'V', 'X'):
- case FCC('d', 'i', 'v', 'x'):
- case FCC('D', 'X', '5', '0'):
- case FCC('3', 'I', 'V', '2'):
- case FCC('3', 'i', 'v', '2'):
- case FCC('3', 'I', 'V', 'X'):
- break;
- default:
- return NULL;
- }
- S_decoder *dec = new S_decoder;
- if (!dec) return NULL;
- dec->size_x = sx;
-
- xvid_dec_frame_t &xvid_dec_frame = dec->xvid_dec_frame;
- MemSet(&xvid_dec_frame, 0, sizeof(xvid_dec_frame));
- xvid_dec_frame.version = XVID_VERSION;
- //xvid_dec_frame.general = 0;
- //convert into true-color, we'll perform convertion to dest format ourselves
- //xvid_dec_frame.output.csp = XVID_CSP_BGR;
-
- xvid_gbl_init_t xvid_gbl_init;
- MemSet(&xvid_gbl_init, 0, sizeof(xvid_gbl_init));
- xvid_gbl_init.version = XVID_VERSION;
- xvid_gbl_init.cpu_flags = 0;
- //xvid_gbl_init.debug = XVID_DEBUG_ERROR | XVID_DEBUG_STARTCODE | XVID_DEBUG_HEADER;
- xvid_global(NULL, 0, &xvid_gbl_init, NULL);
-
- xvid_dec_create_t xvid_dec_create;
- MemSet(&xvid_dec_create, 0, sizeof(xvid_dec_create));
- xvid_dec_create.version = XVID_VERSION;
- xvid_dec_create.width = 0;
- xvid_dec_create.height = 0;
-#ifdef PROFILE
- xvid_dec_create.prof = &prof;
-#endif
- xvid_dec_create.width = sx;
- xvid_dec_create.height = sy;
-
- int ret = xvid_decore(NULL, XVID_DEC_CREATE, &xvid_dec_create, NULL);
- if(ret){
- delete dec;
- return NULL;
- }
- dec->size_x = sx;
- dec->dec_handle = xvid_dec_create.handle;
-
- return dec;
-}
-
-//----------------------------
-
-void CloseCodec(void *handle){
- S_decoder *dec = (S_decoder*)handle;
- xvid_decore(dec->dec_handle, XVID_DEC_DESTROY, NULL, NULL);
- delete dec;
-}
-
-//----------------------------
-
-int DecodeFrame(void *handle, const void *buf, dword sz_in, byte *&y, byte *&u, byte *&v, dword &pitch){
-
- S_decoder *dec = (S_decoder*)handle;
-
- dec->xvid_dec_frame.bitstream = buf;
- dec->xvid_dec_frame.length = sz_in;
- xvid_decore(dec->dec_handle, XVID_DEC_DECODE, &dec->xvid_dec_frame, NULL);
-
- const C_xvid_image *img = dec->xvid_dec_frame.img_out;
- if(!img)
- return 0;
-
- y = img->y;
- u = img->u;
- v = img->v;
- int mb_width = (dec->size_x + 15) / 16;
- pitch = 16 * mb_width + 2 * EDGE_SIZE;
- return 1;
-}
-
-//----------------------------
+++ /dev/null
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.) You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-\f
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-\f
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-\f
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-\f
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-\f
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
- <one line to give the program's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- <signature of Ty Coon>, 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Library General
-Public License instead of this License.
+++ /dev/null
-1) Introduction
----------------
-
-XviD is a high performance and high quality MPEG-4 video de-/encoding
-solution.
-
-The XviD package currently consists of three parts:
-
-- xvidcore: the main MPEG-4 de-/encoding library, and simple example
- programs
-- dshow: windows direct show decoder filter which links against
- xvidcore to allow MPEG-4 playback on Windows based OS.
-- vfw: video for windows GUI
-
-
-2) Documentation
-----------------
-
-- xvidcore/doc/README: some general information.
-- xvidcore/doc/INSTALL: building and installing instructions.
-
-
-3) Licensing:
-------------
-
-- XviD is licensed as a whole under the terms of the XviD license
- described in the file LICENSE This is true for all files belonging
- to XviD except for those which specifically carry a different
- license header.
\ No newline at end of file
+++ /dev/null
-This is a port of the XviD decoder for symbian and PocketPC OS. It was found by luck on the net at http://www.lonelycatgames.com/mobile/smartmovie/
-
-Symbian codec system:
-
-//----------------------------
-General rules:
-- All codecs are located in c:\system\codecs on target device
-- Each codec is single native DLL
-- One codec may support one or more video formats
-- Formats are identified by 32-bit fourcc code
-
-//----------------------------
-Codec API:
-
-Codec DLL need to have following functions exported:
-
-Function Ordinal
-InitCodec 1
-CloseCodec 2
-DecodeFrame 3
-
-Because Symbian DLL doesn't support exporting DLL functions by name, exported functions
-must have ordinals as specified in above table.
-
-//----------------------------
-Detailed API definition:
-
-void *InitCodec(dword sx, dword sy, dword fcc);
-Initialize codec, using provided fcc code and dimensions of video image.
-Parameters:
- [IN] sx, sy - resolution of video image (width, height)
- [IN] fcc - Four-cc code of video stream
-Return value:
- pointer to decoder handle (passed to other functions), or NULL if fourcc code is not supported by codec
-
-//----------------------------
-void CloseCodec(void *handle);
-Close codec, unitinialize memory, etc.
-Parameters:
- [IN] handle - handle value obtained by InitCodec function
-
-//----------------------------
-int DecodeFrame(void *handle, const void *buf, dword sz_in, const byte *&y, const byte *&u, const byte *&v, dword &pitch);
-Decode single frame. The frame data may depend on previous frame data passed in by previous call to this function.
-It is safe to call this function with data of non-contiguous frame, for example when seeking, provided that
-the frame is a keyframe - i.e. contains data for entire image.
-Parameters:
- [IN] handle - handle value obtained by InitCodec function
- [IN] buf - pointer to bitstream buffer
- [IN] sz_in - size of 'buf' buffer data
- [OUT] y, u, v - pointer references filled with YUV to YUV data of decoded frame when the call returns; these
- pointers are valid until next call to DecodeFrame or CloseCodec functions
- [OUT] pitch - size of image line, in bytes (for Y array; U and V arrays have half pitch of Y, because UV is
- coded only for each 4x4 pixel block
-Return value:
- 0 - frame was not decoded (i.e. preroll frame); pointers y, u, v are not filled
- 1 - frame was decoded, contains packed YUV data
- 2 - frame was decoded, contains interleaved RGB data, returned in 'y' pointer
-
-//----------------------------
-
-Note:
-The source project is built in Microsoft Visual C++ 6 environment.
-It is assumed that Symbian Series60 SDK is installed in C:\Symbian\6.1\Series60\Epoc32
-
+++ /dev/null
-#ifndef __RULES_H
-#define __RULES_H
-
-/*----------------------------
- Copyright (c) Lonely Cat Games All rights reserved.
- General types required for compilation of Insanity group of libraries.
-----------------------------*/
- //warning settings for MS compiler
-#ifdef _MSC_VER
-
-#pragma warning(disable: 4786)//trunc symbols to 255 chars
-#pragma warning(disable: 4530)//exception handling
-#pragma warning(disable: 4800)//exception handling
-#pragma warning(disable: 4096)//exception handling
-#pragma warning(disable: 4100)//unreferenced formal parameter
-#pragma warning(disable: 4505)//unreferenced local function has been removed
-#pragma warning(disable: 4514)//unreferenced inline function has been removed
-#pragma warning(disable: 4663)//C++ error in std headers
-#pragma warning(disable: 4710)//function not inlined
-#pragma warning(disable: 4201)//nonstandard extension with unnamed structs
-#pragma warning(disable: 4244)//conversion from ??? to ???, possible loss of data
-#pragma warning(disable: 4146)//unary minus operator applied to unsigned type, result still unsigned
-#pragma warning(disable: 4284)//C++...
-#pragma warning(disable: 4290)//C++ Exception Specification ignored
-#pragma warning(disable: 4127)//conditional expression is constant
-#pragma warning(disable: 4663)//C++ language change...
-#pragma warning(disable: 4702)//unreachable code
-#pragma warning(disable: 4511)//copy constructor could not be generated
-#pragma warning(disable: 4512)//assignment operator could not be generated
-#pragma warning(disable: 4711)//function selected for automatic inline expansion
-
-
-
- //level4 warnings:
-#pragma warning(3: 4189) //local variable is initialized but not referenced
-#pragma warning(3: 4305) //truncation from const double to float
-//#pragma warning(3: 4244) //conversion from ??? to ???, possible loss of data
-#pragma warning(3: 4245) //signed/unsigned mismatch
-#pragma warning(3: 4018) //signed/unsigned mismatch
-#pragma warning(3: 4706) //assignment within conditional expression
-#pragma warning(3: 4701) //local variable may be used without having been initialized
-#pragma warning(3: 4211) //nonstandard extension used : redefined extern to static
-#pragma warning(3: 4310) //cast truncates constant value
-
-#endif
-
-//----------------------------
-
-typedef unsigned char byte;
-typedef signed char schar;
-typedef unsigned short word;
-typedef unsigned long dword;
-typedef unsigned long ulong;
-
-#ifndef _SIZE_T_DEFINED_
-#define _SIZE_T_DEFINED_
-typedef unsigned size_t;
-#endif
-
-#ifndef NULL
- #define NULL 0
-#endif
-
-//----------------------------
-
-#endif
+++ /dev/null
-TODO
-====
-
-This file lists the TODO items stll pending for the 1.0 release.
-
-
-Active Items to work on:
-------------------------
-
-* update vfw & dshow decoder frontends
- - GUI isn't perfect for vfw
-* update/fix CBR plugin
- - misses target bitrate, bitrate burst in static motion/high motion
- transitions
-* bug hunting (ed.gomez/syskin)
- - xvidcore is still a place where bugs feel confortable
-* docbook writing (every developer should contribute)
- - New API has to be documented.
-* two pass code should not introduce quality regressions (every tester)
- - first feedback proved kfthresholding was hurting quality, a
- decision on its behavior has to be settled.
-* MMX MPEG4 quantization is unprecise. This is probably an inherent
- problem in some MMX opcode precision.
-
-
-Already completed items:
-------------------------
-
-* remove divx4 api (ed.gomez)
-* remove VOP_TYPE enumerations (peter)
-* remove HINTed ME stuff (ed.gomez)
-* xvid_image_t/xvid_gbl_convert_t (peter)
-* xvid_global structs (peter)
-* errors codes (peter)
-* xvid_decoder structs (peter)
-* apply encoder api changes "HEAPS" (peter)
-* rawdec (use xvid_decraw instead) (ed.gomez)
-* Support for GMC 3 warp points (christoph)
-* New Qpel code (michael)
-* ME splitting and ME improvements (syskin)
-* New unix build process (ed.gomez)
-* New thread/instance safe sse2 code (p.massimino)
-* INSTALL guide for Unix and Win32 (ed.gomez)
-* dshow static link to libxvidcore.lib (peter)
-* update/fix Lumimasking (syskin)
-* trellis for mpeg and relaxed optimization for big levels (skal)
-* thread safe mpeg quantizing (michael)
-* Interlacing for bvop and svop (syskin)
-* YV12/I420/USER clarification (christoph)
-* vfw and dshow link dynamically to xvidcore.dll (syskin)
-
-Last edited: $Date: 2005-07-13 14:36:16 $
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Bitstream reader/writer -
- *
- * Copyright (C) 2001-2003 Peter Ross <pross@xvid.org>
- * 2003 Cristoph Lampert <gruel@web.de>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: bitstream.cpp,v 1.1.1.1 2005-07-13 14:36:12 jeanlf Exp $
- *
- ****************************************************************************/
-
-#include "bitstream.h"
-#include "quant_matrix.h"
-
-#ifdef WIN32
-#include <stdio.h>
-#endif
-
-//----------------------------
-
-inline dword ByteSwap(dword a){
- return (a<<24) | ((a&0xff00) << 8) | ((a&0xff0000) >> 8) | (a>>24);
-}
-
-//----------------------------
-
-void Bitstream::Init(const void *bitstream, dword _length){
-
- dword adjbitstream = (dword)bitstream;
-
- /*
- * Start the stream on a dword boundary, by rounding down to the
- * previous dword and skipping the intervening bytes.
- */
- long bitpos = ((sizeof(dword)-1) & (long)bitstream);
- adjbitstream = adjbitstream - bitpos;
- start = tail = (dword *) adjbitstream;
-
- if(_length){
- dword tmp = *start;
-#ifndef ARCH_IS_BIG_ENDIAN
- tmp = ByteSwap(tmp);
-#endif
- bufa = tmp;
- if(_length>4){
- tmp = *(start + 1);
-#ifndef ARCH_IS_BIG_ENDIAN
- tmp = ByteSwap(tmp);
-#endif
- bufb = tmp;
- }else
- bufb = 0;
- }else
- bufa = bufb = 0;
-
- buf = 0;
- pos = initpos = bitpos*8;
- length = _length;
-}
-
-//---------------------------
-
-/* reads n bits from bitstream without changing the stream pos */
-
-dword Bitstream::ShowBits(dword bits){
-
- int nbit = (bits + pos) - 32;
- if(nbit > 0)
- return ((bufa & (0xffffffff >> pos)) << nbit) | (bufb >> (32 - nbit));
- return (bufa & (0xffffffff >> pos)) >> (32 - pos - bits);
-}
-
-//---------------------------
-// skip n bits forward in bitstream
-void Bitstream::Skip(dword bits){
-
- pos += bits;
- if(pos >= 32){
- dword tmp;
-
- bufa = bufb;
- tmp = *((dword *) tail + 2);
-#ifndef ARCH_IS_BIG_ENDIAN
- tmp = ByteSwap(tmp);
-#endif
- bufb = tmp;
- tail++;
- pos -= 32;
- }
-}
-
-//---------------------------
-/* show nbits from next byte alignment */
-dword Bitstream::ShowBitsFromByteAlign(int bits){
-
- int bspos = pos + NumBitsToByteAlign();
- int nbit = (bits + bspos) - 32;
-
- if (bspos >= 32) {
- return bufb >> (32 - nbit);
- } else if (nbit > 0) {
- return ((bufa & (0xffffffff >> bspos)) << nbit) | (bufb >> (32 - nbit));
- } else {
- return (bufa & (0xffffffff >> bspos)) >> (32 - bspos - bits);
- }
-
-}
-
-//---------------------------
-/* read n bits from bitstream */
-dword Bitstream::GetBits(dword n){
- dword ret = ShowBits(n);
- Skip(n);
- return ret;
-}
-
-//---------------------------
-
-static const dword intra_dc_threshold_table[] = {
- 32, /* never use */
- 13,
- 15,
- 17,
- 19,
- 21,
- 23,
- 1,
-};
-
-//----------------------------
-
-void Bitstream::get_matrix(byte * matrix){
-
- int i = 0;
- int last, value = 0;
-
- do {
- last = value;
- value = GetBits(8);
- matrix[scan_tables[0][i++]] = value;
- }
- while (value != 0 && i < 64);
- i--; /* fix little bug at coeff not full */
-
- while (i < 64) {
- matrix[scan_tables[0][i++]] = last;
- }
-}
-
-//----------------------------
-/*
- * for PVOP addbits == fcode - 1
- * for BVOP addbits == max(fcode,bcode) - 1
- * returns mbpos
- */
-int S_decoder::read_video_packet_header(Bitstream *bs, const int addbits, int *quant, int *fcode_forward, int *fcode_backward, int *intra_dc_threshold){
-
- int startcode_bits = NUMBITS_VP_RESYNC_MARKER + addbits;
- int mbnum_bits = log2bin(mb_width * mb_height - 1);
- int mbnum;
- int hec = 0;
-
- bs->Skip(bs->NumBitsToByteAlign());
- bs->Skip(startcode_bits);
-
- DPRINTF(XVID_DEBUG_STARTCODE, "<video_packet_header>\n");
-
- if (shape != VIDOBJLAY_SHAPE_RECTANGULAR)
- {
- hec = bs->GetBit(); /* header_extension_code */
- if (hec && !(sprite_enable == SPRITE_STATIC /* && current_coding_type = I_VOP */))
- {
- bs->Skip(13); /* vop_width */
- READ_MARKER();
- bs->Skip(13); /* vop_height */
- READ_MARKER();
- bs->Skip(13); /* vop_horizontal_mc_spatial_ref */
- READ_MARKER();
- bs->Skip(13); /* vop_vertical_mc_spatial_ref */
- READ_MARKER();
- }
- }
-
- mbnum = bs->GetBits(mbnum_bits); /* macroblock_number */
- DPRINTF(XVID_DEBUG_HEADER, "mbnum %i\n", mbnum);
-
- if (shape != VIDOBJLAY_SHAPE_BINARY_ONLY)
- {
- *quant = bs->GetBits(quant_bits); /* quant_scale */
- DPRINTF(XVID_DEBUG_HEADER, "quant %i\n", *quant);
- }
-
- if (shape == VIDOBJLAY_SHAPE_RECTANGULAR)
- hec = bs->GetBit(); /* header_extension_code */
-
-
- DPRINTF(XVID_DEBUG_HEADER, "header_extension_code %i\n", hec);
- if (hec)
- {
- int time_base;
- int time_increment = 0;
- int coding_type;
-
- for (time_base=0; bs->GetBit()!=0; time_base++); /* modulo_time_base */
- READ_MARKER();
- if (time_inc_bits)
- time_increment = (bs->GetBits(time_inc_bits)); /* vop_time_increment */
- READ_MARKER();
- //DPRINTF(XVID_DEBUG_HEADER,"time %i:%i\n", time_base, time_increment);
-
- coding_type = bs->GetBits(2);
- DPRINTF(XVID_DEBUG_HEADER,"coding_type %i\n", coding_type);
-
- if (shape != VIDOBJLAY_SHAPE_RECTANGULAR)
- {
- bs->Skip(1); /* change_conv_ratio_disable */
- if (coding_type != I_VOP)
- bs->Skip(1); /* vop_shape_coding_type */
- }
-
- if (shape != VIDOBJLAY_SHAPE_BINARY_ONLY)
- {
- *intra_dc_threshold = intra_dc_threshold_table[bs->GetBits(3)];
-
- if (sprite_enable == SPRITE_GMC && coding_type == S_VOP &&
- sprite_warping_points > 0)
- {
- /* TODO: sprite trajectory */
- }
- if(reduced_resolution_enable && shape == VIDOBJLAY_SHAPE_RECTANGULAR && (coding_type == P_VOP || coding_type == I_VOP)){
- bs->Skip(1); /* XXX: vop_reduced_resolution */
- }
-
- if (coding_type != I_VOP && fcode_forward)
- {
- *fcode_forward = bs->GetBits(3);
- DPRINTF(XVID_DEBUG_HEADER,"fcode_forward %i\n", *fcode_forward);
- }
-
- if (coding_type == B_VOP && fcode_backward)
- {
- *fcode_backward = bs->GetBits(3);
- DPRINTF(XVID_DEBUG_HEADER,"fcode_backward %i\n", *fcode_backward);
- }
- }
-
- }
-
- if (newpred_enable) {
- int vop_id;
- int vop_id_for_prediction;
-
- vop_id = bs->GetBits(MIN(time_inc_bits + 3, 15));
- DPRINTF(XVID_DEBUG_HEADER, "vop_id %i\n", vop_id);
- if (bs->GetBit()) /* vop_id_for_prediction_indication */
- {
- vop_id_for_prediction = bs->GetBits(MIN(time_inc_bits + 3, 15));
- DPRINTF(XVID_DEBUG_HEADER, "vop_id_for_prediction %i\n", vop_id_for_prediction);
- }
- READ_MARKER();
- }
-
- return mbnum;
-}
-
-//----------------------------
-/* vol estimation header */
-void S_decoder::read_vol_complexity_estimation_header(Bitstream * bs){
-
- ESTIMATION * e = &estimation;
-
- e->method = bs->GetBits(2); /* estimation_method */
- DPRINTF(XVID_DEBUG_HEADER,"+ complexity_estimation_header; method=%i\n", e->method);
-
- if (e->method == 0 || e->method == 1){
- if(!bs->GetBit()){
- //shape_complexity_estimation_disable
- e->opaque = bs->GetBit(); /* opaque */
- e->transparent = bs->GetBit(); /* transparent */
- e->intra_cae = bs->GetBit(); /* intra_cae */
- e->inter_cae = bs->GetBit(); /* inter_cae */
- e->no_update = bs->GetBit(); /* no_update */
- e->upsampling = bs->GetBit(); /* upsampling */
- }
-
- if (!bs->GetBit()) /* texture_complexity_estimation_set_1_disable */
- {
- e->intra_blocks = bs->GetBit(); /* intra_blocks */
- e->inter_blocks = bs->GetBit(); /* inter_blocks */
- e->inter4v_blocks = bs->GetBit(); /* inter4v_blocks */
- e->not_coded_blocks = bs->GetBit(); /* not_coded_blocks */
- }
- }
-
- READ_MARKER();
-
- if (!bs->GetBit()){
- //texture_complexity_estimation_set_2_disable
- e->dct_coefs = bs->GetBit(); /* dct_coefs */
- e->dct_lines = bs->GetBit(); /* dct_lines */
- e->vlc_symbols = bs->GetBit(); /* vlc_symbols */
- e->vlc_bits = bs->GetBit(); /* vlc_bits */
- }
-
- if (!bs->GetBit()){
- //motion_compensation_complexity_disable
- e->apm = bs->GetBit(); /* apm */
- e->npm = bs->GetBit(); /* npm */
- e->interpolate_mc_q = bs->GetBit(); /* interpolate_mc_q */
- e->forw_back_mc_q = bs->GetBit(); /* forw_back_mc_q */
- e->halfpel2 = bs->GetBit(); /* halfpel2 */
- e->halfpel4 = bs->GetBit(); /* halfpel4 */
- }
-
- READ_MARKER();
-
- if (e->method == 1){
- if (!bs->GetBit()){
- //version2_complexity_estimation_disable
- e->sadct = bs->GetBit(); /* sadct */
- e->quarterpel = bs->GetBit(); /* quarterpel */
- }
- }
-}
-
-//----------------------------
-/* vop estimation header */
-void S_decoder::read_vop_complexity_estimation_header(Bitstream * bs, int coding_type){
-
- ESTIMATION * e = &estimation;
-
- if (e->method == 0 || e->method == 1)
- {
- if (coding_type == I_VOP) {
- if (e->opaque) bs->Skip(8); /* dcecs_opaque */
- if (e->transparent) bs->Skip(8); /* */
- if (e->intra_cae) bs->Skip(8); /* */
- if (e->inter_cae) bs->Skip(8); /* */
- if (e->no_update) bs->Skip(8); /* */
- if (e->upsampling) bs->Skip(8); /* */
- if (e->intra_blocks) bs->Skip(8); /* */
- if (e->not_coded_blocks) bs->Skip(8); /* */
- if (e->dct_coefs) bs->Skip(8); /* */
- if (e->dct_lines) bs->Skip(8); /* */
- if (e->vlc_symbols) bs->Skip(8); /* */
- if (e->vlc_bits) bs->Skip(8); /* */
- if (e->sadct) bs->Skip(8); /* */
- }
-
- if (coding_type == P_VOP) {
- if (e->opaque) bs->Skip(8); /* */
- if (e->transparent) bs->Skip(8); /* */
- if (e->intra_cae) bs->Skip(8); /* */
- if (e->inter_cae) bs->Skip(8); /* */
- if (e->no_update) bs->Skip(8); /* */
- if (e->upsampling) bs->Skip(8); /* */
- if (e->intra_blocks) bs->Skip(8); /* */
- if (e->not_coded_blocks) bs->Skip(8); /* */
- if (e->dct_coefs) bs->Skip(8); /* */
- if (e->dct_lines) bs->Skip(8); /* */
- if (e->vlc_symbols) bs->Skip(8); /* */
- if (e->vlc_bits) bs->Skip(8); /* */
- if (e->inter_blocks) bs->Skip(8); /* */
- if (e->inter4v_blocks) bs->Skip(8); /* */
- if (e->apm) bs->Skip(8); /* */
- if (e->npm) bs->Skip(8); /* */
- if (e->forw_back_mc_q) bs->Skip(8); /* */
- if (e->halfpel2) bs->Skip(8); /* */
- if (e->halfpel4) bs->Skip(8); /* */
- if (e->sadct) bs->Skip(8); /* */
- if (e->quarterpel) bs->Skip(8); /* */
- }
- if (coding_type == B_VOP) {
- if (e->opaque) bs->Skip(8); /* */
- if (e->transparent) bs->Skip(8); /* */
- if (e->intra_cae) bs->Skip(8); /* */
- if (e->inter_cae) bs->Skip(8); /* */
- if (e->no_update) bs->Skip(8); /* */
- if (e->upsampling) bs->Skip(8); /* */
- if (e->intra_blocks) bs->Skip(8); /* */
- if (e->not_coded_blocks) bs->Skip(8); /* */
- if (e->dct_coefs) bs->Skip(8); /* */
- if (e->dct_lines) bs->Skip(8); /* */
- if (e->vlc_symbols) bs->Skip(8); /* */
- if (e->vlc_bits) bs->Skip(8); /* */
- if (e->inter_blocks) bs->Skip(8); /* */
- if (e->inter4v_blocks) bs->Skip(8); /* */
- if (e->apm) bs->Skip(8); /* */
- if (e->npm) bs->Skip(8); /* */
- if (e->forw_back_mc_q) bs->Skip(8); /* */
- if (e->halfpel2) bs->Skip(8); /* */
- if (e->halfpel4) bs->Skip(8); /* */
- if (e->interpolate_mc_q) bs->Skip(8); /* */
- if (e->sadct) bs->Skip(8); /* */
- if (e->quarterpel) bs->Skip(8); /* */
- }
-
- if (coding_type == S_VOP && sprite_enable == SPRITE_STATIC) {
- if (e->intra_blocks) bs->Skip(8); /* */
- if (e->not_coded_blocks) bs->Skip(8); /* */
- if (e->dct_coefs) bs->Skip(8); /* */
- if (e->dct_lines) bs->Skip(8); /* */
- if (e->vlc_symbols) bs->Skip(8); /* */
- if (e->vlc_bits) bs->Skip(8); /* */
- if (e->inter_blocks) bs->Skip(8); /* */
- if (e->inter4v_blocks) bs->Skip(8); /* */
- if (e->apm) bs->Skip(8); /* */
- if (e->npm) bs->Skip(8); /* */
- if (e->forw_back_mc_q) bs->Skip(8); /* */
- if (e->halfpel2) bs->Skip(8); /* */
- if (e->halfpel4) bs->Skip(8); /* */
- if (e->interpolate_mc_q) bs->Skip(8); /* */
- }
- }
-}
-
-//----------------------------
-// decode headers
-// returns coding_type, or -1 if error
-
-#define VIDOBJ_START_CODE_MASK 0x0000001f
-#define VIDOBJLAY_START_CODE_MASK 0x0000000f
-
-int S_decoder::BitstreamReadHeaders(Bitstream * bs, bool &rounding, bool *reduced_resolution, dword *quant, dword *fcode_forward,
- dword *fcode_backward, dword *intra_dc_threshold, WARPPOINTS *gmc_warp){
-
- dword vol_ver_id;
- dword coding_type;
- dword start_code;
- dword time_incr = 0;
- int time_increment = 0;
- int resize = 0;
-
- while((bs->Pos() >> 3) < bs->length){
- bs->ByteAlign();
- start_code = bs->ShowBits(32);
-
- switch(start_code){
- case VISOBJSEQ_START_CODE:
- {
- DPRINTF(XVID_DEBUG_STARTCODE, "<visual_object_sequence>\n");
-
- bs->Skip(32); //visual_object_sequence_start_code
- int profile = bs->GetBits(8); //profile_and_level_indication
-
- DPRINTF(XVID_DEBUG_HEADER, "profile_and_level_indication %i\n", profile);
- }
- break;
- case VISOBJSEQ_STOP_CODE:
- {
- //visual_object_sequence_stop_code
- bs->Skip(32);
- DPRINTF(XVID_DEBUG_STARTCODE, "</visual_object_sequence>\n");
-
- }
- break;
- case VISOBJ_START_CODE:
- {
- DPRINTF(XVID_DEBUG_STARTCODE, "<visual_object>\n");
-
- bs->Skip(32); //visual_object_start_code
-
- int visobj_ver_id;
- //is_visual_object_identified
- if(bs->GetBit()){
- visobj_ver_id = bs->GetBits(4); /* visual_object_ver_id */
- DPRINTF(XVID_DEBUG_HEADER,"visobj_ver_id %i\n", visobj_ver_id);
- bs->Skip(3); //visual_object_priority
- }else{
- visobj_ver_id = 1;
- }
-
- if(bs->ShowBits(4) != VISOBJ_TYPE_VIDEO){
- //visual_object_type
- DPRINTF(XVID_DEBUG_ERROR, "visual_object_type != video\n");
- return -1;
- }
- bs->Skip(4);
- //video_signal_type
-
- if(bs->GetBit()){
- DPRINTF(XVID_DEBUG_HEADER,"+ video_signal_type\n");
- bs->Skip(3); /* video_format */
- bs->Skip(1); /* video_range */
- if (bs->GetBit()) /* color_description */
- {
- DPRINTF(XVID_DEBUG_HEADER,"+ color_description");
- bs->Skip(8); /* color_primaries */
- bs->Skip(8); /* transfer_characteristics */
- bs->Skip(8); /* matrix_coefficients */
- }
- }
- }
- break;
- case GRPOFVOP_START_CODE:
- {
- DPRINTF(XVID_DEBUG_STARTCODE, "<group_of_vop>\n");
-
- bs->Skip(32);
- {
- int hours, minutes, seconds;
-
- hours = bs->GetBits(5);
- minutes = bs->GetBits(6);
- READ_MARKER();
- seconds = bs->GetBits(6);
- //DPRINTF(XVID_DEBUG_HEADER, "time %ih%im%is\n", hours,minutes,seconds);
- }
- bs->Skip(1); /* closed_gov */
- bs->Skip(1); /* broken_link */
- }
- break;
- case VOP_START_CODE:
- {
-
- DPRINTF(XVID_DEBUG_STARTCODE, "<vop>\n");
-
- bs->Skip(32); /* vop_start_code */
-
- coding_type = bs->GetBits(2); /* vop_coding_type */
- DPRINTF(XVID_DEBUG_HEADER, "coding_type %i\n", coding_type);
-
- /*********************** for decode B-frame time ***********************/
- while (bs->GetBit() != 0) /* time_base */
- time_incr++;
-
- READ_MARKER();
-
- if (time_inc_bits) {
- time_increment = (bs->GetBits(time_inc_bits)); /* vop_time_increment */
- }
-
- DPRINTF(XVID_DEBUG_HEADER, "time_base %i\n", time_incr);
- DPRINTF(XVID_DEBUG_HEADER, "time_increment %i\n", time_increment);
-
- //DPRINTF(XVID_DEBUG_TIMECODE, "%c %i:%i\n", coding_type == I_VOP ? 'I' : coding_type == P_VOP ? 'P' : coding_type == B_VOP ? 'B' : 'S', time_incr, time_increment);
- if (coding_type != B_VOP) {
- last_time_base = time_base;
- time_base += time_incr;
- time = time_increment;
-
-#if 0
- time_base * time_inc_resolution +
- time_increment;
-#endif
- time_pp = (dword)
- (time_inc_resolution + time - last_non_b_time)%time_inc_resolution;
- last_non_b_time = time;
- } else {
- time = time_increment;
-#if 0
- (last_time_base +
- time_incr) * time_inc_resolution + time_increment;
-#endif
- time_bp = (dword)
- (time_inc_resolution + last_non_b_time - time)%time_inc_resolution;
- }
- DPRINTF(XVID_DEBUG_HEADER,"time_pp=%i\n", time_pp);
- DPRINTF(XVID_DEBUG_HEADER,"time_bp=%i\n", time_bp);
-
- READ_MARKER();
-
- if (!bs->GetBit()) /* vop_coded */
- {
- DPRINTF(XVID_DEBUG_HEADER, "vop_coded==false\n");
- return N_VOP;
- }
-
- if (newpred_enable) {
- int vop_id;
- int vop_id_for_prediction;
-
- vop_id = bs->GetBits(MIN(time_inc_bits + 3, 15));
- DPRINTF(XVID_DEBUG_HEADER, "vop_id %i\n", vop_id);
- if (bs->GetBit()) /* vop_id_for_prediction_indication */
- {
- vop_id_for_prediction = bs->GetBits(MIN(time_inc_bits + 3, 15));
- DPRINTF(XVID_DEBUG_HEADER, "vop_id_for_prediction %i\n", vop_id_for_prediction);
- }
- READ_MARKER();
- }
-
- //fix a little bug by MinChen <chenm002@163.com>
- if((shape != VIDOBJLAY_SHAPE_BINARY_ONLY) &&
- ((coding_type == P_VOP) || (coding_type == S_VOP && sprite_enable == SPRITE_GMC))){
- rounding = !!bs->GetBit(); //rounding_type
- DPRINTF(XVID_DEBUG_HEADER, "rounding %i\n", rounding);
- }
-
- if(reduced_resolution_enable && shape == VIDOBJLAY_SHAPE_RECTANGULAR && (coding_type == P_VOP || coding_type == I_VOP)) {
-
- *reduced_resolution = !!bs->GetBit();
- DPRINTF(XVID_DEBUG_HEADER, "reduced_resolution %i\n", *reduced_resolution);
- }else{
- *reduced_resolution = false;
- }
-
- if (shape != VIDOBJLAY_SHAPE_RECTANGULAR) {
- if(!(sprite_enable == SPRITE_STATIC && coding_type == I_VOP)) {
-
- dword width, height;
- dword horiz_mc_ref, vert_mc_ref;
-
- width = bs->GetBits(13);
- READ_MARKER();
- height = bs->GetBits(13);
- READ_MARKER();
- horiz_mc_ref = bs->GetBits(13);
- READ_MARKER();
- vert_mc_ref = bs->GetBits(13);
- READ_MARKER();
-
- DPRINTF(XVID_DEBUG_HEADER, "width %i\n", width);
- DPRINTF(XVID_DEBUG_HEADER, "height %i\n", height);
- DPRINTF(XVID_DEBUG_HEADER, "horiz_mc_ref %i\n", horiz_mc_ref);
- DPRINTF(XVID_DEBUG_HEADER, "vert_mc_ref %i\n", vert_mc_ref);
- }
-
- bs->Skip(1); /* change_conv_ratio_disable */
- if (bs->GetBit()) /* vop_constant_alpha */
- {
- bs->Skip(8); /* vop_constant_alpha_value */
- }
- }
-
- if (shape != VIDOBJLAY_SHAPE_BINARY_ONLY) {
-
- if (!complexity_estimation_disable)
- {
- read_vop_complexity_estimation_header(bs, coding_type);
- }
-
- /* intra_dc_vlc_threshold */
- *intra_dc_threshold =
- intra_dc_threshold_table[bs->GetBits(3)];
-
- top_field_first = 0;
- alternate_vertical_scan = 0;
-
- if(interlacing){
- top_field_first = bs->GetBit();
- DPRINTF(XVID_DEBUG_HEADER, "interlace top_field_first %i\n", top_field_first);
- alternate_vertical_scan = bs->GetBit();
- DPRINTF(XVID_DEBUG_HEADER, "interlace alternate_vertical_scan %i\n", alternate_vertical_scan);
-
- }
- }
-
- if ((sprite_enable == SPRITE_STATIC || sprite_enable== SPRITE_GMC) && coding_type == S_VOP) {
-
- int i;
-
- for (i = 0 ; i < sprite_warping_points; i++)
- {
- int length;
- int x = 0, y = 0;
-
- /* sprite code borowed from ffmpeg; thx Michael Niedermayer <michaelni@gmx.at> */
- length = bs->bs_get_spritetrajectory();
- if(length){
- x= bs->GetBits(length);
- if ((x >> (length - 1)) == 0) /* if MSB not set it is negative*/
- x = - (x ^ ((1 << length) - 1));
- }
- READ_MARKER();
-
- length = bs->bs_get_spritetrajectory();
- if(length){
- y = bs->GetBits(length);
- if ((y >> (length - 1)) == 0) /* if MSB not set it is negative*/
- y = - (y ^ ((1 << length) - 1));
- }
- READ_MARKER();
-
- gmc_warp->duv[i].x = x;
- gmc_warp->duv[i].y = y;
-
- //DPRINTF(XVID_DEBUG_HEADER,"sprite_warping_point[%i] xy=(%i,%i)\n", i, x, y);
- }
-
- if (sprite_brightness_change)
- {
- /* XXX: brightness_change_factor() */
- }
- if (sprite_enable == SPRITE_STATIC)
- {
- /* XXX: todo */
- }
-
- }
-
- if ((*quant = bs->GetBits(quant_bits)) < 1) /* vop_quant */
- *quant = 1;
- DPRINTF(XVID_DEBUG_HEADER, "quant %i\n", *quant);
-
- if (coding_type != I_VOP) {
- *fcode_forward = bs->GetBits(3); /* fcode_forward */
- DPRINTF(XVID_DEBUG_HEADER, "fcode_forward %i\n", *fcode_forward);
- }
-
- if (coding_type == B_VOP) {
- *fcode_backward = bs->GetBits(3); /* fcode_backward */
- DPRINTF(XVID_DEBUG_HEADER, "fcode_backward %i\n", *fcode_backward);
- }
- if(!scalability){
- if ((shape != VIDOBJLAY_SHAPE_RECTANGULAR) &&
- (coding_type != I_VOP)) {
- bs->Skip(1); /* vop_shape_coding_type */
- }
- }
- return coding_type;
-
- }
- break;
- case USERDATA_START_CODE:
- {
- char tmp[256];
- int i;
-
- bs->Skip(32); /* user_data_start_code */
-
- tmp[0] = bs->ShowBits(8);
-
- for(i = 1; i < 256; i++){
- tmp[i] = (bs->ShowBits(16) & 0xFF);
-
- if(tmp[i] == 0)
- break;
-
- bs->Skip(8);
- }
-
- //DPRINTF(XVID_DEBUG_STARTCODE, "<user_data>: %s\n", tmp);
-
- /* read xvid bitstream version */
-#ifdef WIN32
- {
- char packed;
- int version, build;
- if(MemCmp(tmp, "XviD", 4) == 0) {
- sscanf(tmp, "XviD%d", &bs_version);
- DPRINTF(XVID_DEBUG_HEADER, "xvid bitstream version=%i", bs_version);
- }
-
- /* divx detection */
- i = sscanf(tmp, "DivX%dBuild%d%c", &version, &build, &packed);
- if (i < 2)
- i = sscanf(tmp, "DivX%db%d%c", &version, &build, &packed);
- if (i >= 2){
- packed_mode = (i == 3 && packed == 'p');
- //DPRINTF(XVID_DEBUG_HEADER, "divx version=%i, build=%i packed=%i\n", version, build, packed_mode);
- }
- }
-#endif
- }
- break;
- default:
- switch(start_code & ~VIDOBJ_START_CODE_MASK){
- case VIDOBJ_START_CODE:
- {
-
- DPRINTF(XVID_DEBUG_STARTCODE, "<video_object>\n");
- DPRINTF(XVID_DEBUG_HEADER, "vo id %i\n", start_code & VIDOBJ_START_CODE_MASK);
- //video_object_start_code
- bs->Skip(32);
- }
- break;
- case VIDOBJLAY_START_CODE:
- {
-
- DPRINTF(XVID_DEBUG_STARTCODE, "<video_object_layer>\n");
- DPRINTF(XVID_DEBUG_HEADER, "vol id %i\n", start_code & VIDOBJLAY_START_CODE_MASK);
-
- bs->Skip(32); //video_object_layer_start_code
- bs->Skip(1); //random_accessible_vol
-
- bs->Skip(8); //video_object_type_indication
-
- if(bs->GetBit()){
- //is_object_layer_identifier
- DPRINTF(XVID_DEBUG_HEADER, "+ is_object_layer_identifier\n");
- vol_ver_id = bs->GetBits(4); /* video_object_layer_verid */
- DPRINTF(XVID_DEBUG_HEADER,"ver_id %i\n", vol_ver_id);
- bs->Skip(3); /* video_object_layer_priority */
- }else{
- vol_ver_id = 1;
- }
-
- aspect_ratio = bs->GetBits(4);
-
- if(aspect_ratio == VIDOBJLAY_AR_EXTPAR){
- //aspect_ratio_info
- DPRINTF(XVID_DEBUG_HEADER, "+ aspect_ratio_info\n");
- par_width = bs->GetBits(8); /* par_width */
- par_height = bs->GetBits(8); /* par_height */
- }
-
- if(bs->GetBit()){
- //vol_control_parameters
- DPRINTF(XVID_DEBUG_HEADER, "+ vol_control_parameters\n");
- bs->Skip(2); /* chroma_format */
- low_delay = (bs->GetBit()!=0);
- DPRINTF(XVID_DEBUG_HEADER, "low_delay %i\n", (int)low_delay);
- if (bs->GetBit()) /* vbv_parameters */
- {
- unsigned int bitrate;
- unsigned int buffer_size;
- unsigned int occupancy;
-
- DPRINTF(XVID_DEBUG_HEADER,"+ vbv_parameters\n");
-
- bitrate = bs->GetBits(15) << 15; /* first_half_bit_rate */
- READ_MARKER();
- bitrate |= bs->GetBits(15); /* latter_half_bit_rate */
- READ_MARKER();
-
- buffer_size = bs->GetBits(15) << 3; /* first_half_vbv_buffer_size */
- READ_MARKER();
- buffer_size |= bs->GetBits(3); /* latter_half_vbv_buffer_size */
-
- occupancy = bs->GetBits(11) << 15; /* first_half_vbv_occupancy */
- READ_MARKER();
- occupancy |= bs->GetBits(15); /* latter_half_vbv_occupancy */
- READ_MARKER();
-
- DPRINTF(XVID_DEBUG_HEADER,"bitrate %d (unit=400 bps)\n", bitrate);
- DPRINTF(XVID_DEBUG_HEADER,"buffer_size %d (unit=16384 bits)\n", buffer_size);
- DPRINTF(XVID_DEBUG_HEADER,"occupancy %d (unit=64 bits)\n", occupancy);
- }
- }else{
- low_delay = low_delay_default;
- }
-
- //video_object_layer_shape
- shape = bs->GetBits(2);
-
- DPRINTF(XVID_DEBUG_HEADER, "shape %i\n", shape);
- if(shape != VIDOBJLAY_SHAPE_RECTANGULAR){
- DPRINTF(XVID_DEBUG_ERROR,"non-rectangular shapes are not supported\n");
- }
-
- if(shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1){
- //video_object_layer_shape_extension
- bs->Skip(4);
- }
-
- READ_MARKER();
-
- /********************** for decode B-frame time ***********************/
- time_inc_resolution = bs->GetBits(16); /* vop_time_increment_resolution */
- DPRINTF(XVID_DEBUG_HEADER,"vop_time_increment_resolution %i\n", time_inc_resolution);
-
-#if 0
- time_inc_resolution--;
-#endif
-
- if(time_inc_resolution > 0){
- time_inc_bits = log2bin(time_inc_resolution-1);
- }else{
-#if 0
- time_inc_bits = 0;
-#endif
- /* for "old" xvid compatibility, set time_inc_bits = 1 */
- time_inc_bits = 1;
- }
-
- READ_MARKER();
-
- if(bs->GetBit()){
- //fixed_vop_rate
- DPRINTF(XVID_DEBUG_HEADER, "+ fixed_vop_rate\n");
- bs->Skip(time_inc_bits); //fixed_vop_time_increment
- }
-
- if(shape != VIDOBJLAY_SHAPE_BINARY_ONLY){
-
- if(shape == VIDOBJLAY_SHAPE_RECTANGULAR){
- dword _width, _height;
-
- READ_MARKER();
- _width = bs->GetBits(13); //video_object_layer_width
- READ_MARKER();
- _height = bs->GetBits(13); //video_object_layer_height
- READ_MARKER();
-
- DPRINTF(XVID_DEBUG_HEADER, "width %i\n", _width);
- DPRINTF(XVID_DEBUG_HEADER, "height %i\n", _height);
-
- if(width != _width || height != _height){
- if(fixed_dimensions){
- DPRINTF(XVID_DEBUG_ERROR, "decoder width/height does not match bitstream\n");
- return -1;
- }
- resize = 1;
- width = _width;
- height = _height;
- }
- }
-
- interlacing = !!bs->GetBit();
- DPRINTF(XVID_DEBUG_HEADER, "interlacing %i\n", interlacing);
-
- if(!bs->GetBit()){
- //obmc_disable
- DPRINTF(XVID_DEBUG_ERROR, "obmc_disabled==false not supported\n");
- /* TODO */
- /* fucking divx4.02 has this enabled */
- }
-
- sprite_enable = bs->GetBits((vol_ver_id == 1 ? 1 : 2));
-
- if(sprite_enable == SPRITE_STATIC || sprite_enable == SPRITE_GMC){
- int low_latency_sprite_enable;
-
- if(sprite_enable != SPRITE_GMC){
- int sprite_width;
- int sprite_height;
- int sprite_left_coord;
- int sprite_top_coord;
- sprite_width = bs->GetBits(13); /* sprite_width */
- READ_MARKER();
- sprite_height = bs->GetBits(13); /* sprite_height */
- READ_MARKER();
- sprite_left_coord = bs->GetBits(13); /* sprite_left_coordinate */
- READ_MARKER();
- sprite_top_coord = bs->GetBits(13); /* sprite_top_coordinate */
- READ_MARKER();
- }
- sprite_warping_points = bs->GetBits(6); /* no_of_sprite_warping_points */
- sprite_warping_accuracy = bs->GetBits(2); /* sprite_warping_accuracy */
- sprite_brightness_change = bs->GetBits(1); /* brightness_change */
- if (sprite_enable != SPRITE_GMC)
- {
- low_latency_sprite_enable = bs->GetBits(1); /* low_latency_sprite_enable */
- }
- }
-
- if(vol_ver_id != 1 && shape != VIDOBJLAY_SHAPE_RECTANGULAR){
- //sadct_disable
- bs->Skip(1);
- }
-
- if(bs->GetBit()){
- //not_8_bit
- DPRINTF(XVID_DEBUG_HEADER, "not_8_bit==true (ignored)\n");
- quant_bits = bs->GetBits(4); /* quant_precision */
- bs->Skip(4); /* bits_per_pixel */
- }else{
- quant_bits = 5;
- }
-
- if(shape == VIDOBJLAY_SHAPE_GRAYSCALE){
- bs->Skip(1); /* no_gray_quant_update */
- bs->Skip(1); /* composition_method */
- bs->Skip(1); /* linear_composition */
- }
-
- quant_type = bs->GetBit();
- DPRINTF(XVID_DEBUG_HEADER, "quant_type %i\n", quant_type);
-
- if(quant_type){
- if (bs->GetBit()) //load_intra_quant_mat
- {
- byte matrix[64];
-
- DPRINTF(XVID_DEBUG_HEADER, "load_intra_quant_mat\n");
-
- bs->get_matrix(matrix);
- set_intra_matrix(mpeg_quant_matrices, matrix);
- }else
- set_intra_matrix(mpeg_quant_matrices, get_default_intra_matrix());
-
- if (bs->GetBit()) /* load_inter_quant_mat */
- {
- byte matrix[64];
-
- DPRINTF(XVID_DEBUG_HEADER, "load_inter_quant_mat\n");
-
- bs->get_matrix(matrix);
- set_inter_matrix(mpeg_quant_matrices, matrix);
- }else
- set_inter_matrix(mpeg_quant_matrices, get_default_inter_matrix());
-
- if (shape == VIDOBJLAY_SHAPE_GRAYSCALE) {
- DPRINTF(XVID_DEBUG_ERROR, "greyscale matrix not supported\n");
- return -1;
- }
-
- }
-
- if(vol_ver_id != 1){
- quarterpel = bs->GetBit();
- DPRINTF(XVID_DEBUG_HEADER,"quarterpel %i\n", quarterpel);
- }else
- quarterpel = 0;
-
-
- complexity_estimation_disable = bs->GetBit();
- if(!complexity_estimation_disable){
- read_vol_complexity_estimation_header(bs);
- }
-
- bs->Skip(1); //resync_marker_disable
-
- if(bs->GetBit()){
- //data_partitioned
- DPRINTF(XVID_DEBUG_ERROR, "data_partitioned not supported\n");
- bs->Skip(1); /* reversible_vlc */
- }
-
- if(vol_ver_id != 1){
- newpred_enable = !!bs->GetBit();
- if (newpred_enable) /* newpred_enable */
- {
- DPRINTF(XVID_DEBUG_HEADER, "+ newpred_enable\n");
- bs->Skip(2); /* requested_upstream_message_type */
- bs->Skip(1); /* newpred_segment_type */
- }
- reduced_resolution_enable = !!bs->GetBit(); //reduced_resolution_vop_enable
- DPRINTF(XVID_DEBUG_HEADER, "reduced_resolution_enable %i\n", reduced_resolution_enable);
- }else{
- newpred_enable = false;
- reduced_resolution_enable = false;
- }
-
- scalability = (bs->GetBit()!=0);
- if(scalability){
- DPRINTF(XVID_DEBUG_ERROR, "scalability not supported\n");
- bs->Skip(1); /* hierarchy_type */
- bs->Skip(4); /* ref_layer_id */
- bs->Skip(1); /* ref_layer_sampling_direc */
- bs->Skip(5); /* hor_sampling_factor_n */
- bs->Skip(5); /* hor_sampling_factor_m */
- bs->Skip(5); /* vert_sampling_factor_n */
- bs->Skip(5); /* vert_sampling_factor_m */
- bs->Skip(1); /* enhancement_type */
- if(shape == VIDOBJLAY_SHAPE_BINARY /* && hierarchy_type==0 */) {
- bs->Skip(1); /* use_ref_shape */
- bs->Skip(1); /* use_ref_texture */
- bs->Skip(5); /* shape_hor_sampling_factor_n */
- bs->Skip(5); /* shape_hor_sampling_factor_m */
- bs->Skip(5); /* shape_vert_sampling_factor_n */
- bs->Skip(5); /* shape_vert_sampling_factor_m */
- }
- return -1;
- }
- }else{
- //shape == BINARY_ONLY
- if(vol_ver_id != 1){
- scalability = (bs->GetBit()!=0);
- if(scalability){
- DPRINTF(XVID_DEBUG_ERROR, "scalability not supported\n");
- bs->Skip(4); /* ref_layer_id */
- bs->Skip(5); /* hor_sampling_factor_n */
- bs->Skip(5); /* hor_sampling_factor_m */
- bs->Skip(5); /* vert_sampling_factor_n */
- bs->Skip(5); /* vert_sampling_factor_m */
- return -1;
- }
- }
- bs->Skip(1); /* resync_marker_disable */
-
- }
-
- return (resize ? -3 : -2); //VOL
-
- }
- break;
- default:
- {
- //start_code == ?
- //if(bs->ShowBits(24) == 0x000001)
- if((start_code&0x00ffffff) == 0x000001){
- DPRINTF(XVID_DEBUG_STARTCODE, "<unknown: %x>\n", bs->ShowBits(32));
- }
- bs->Skip(8);
- }
- }
- }
- }
-
-#if 0
- DPRINTF("*** WARNING: no vop_start_code found");
-#endif
- return -1; //ignore it
-}
-
-//----------------------------
-
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Bitstream reader/writer inlined functions and constants-
- *
- * Copyright (C) 2001-2003 Peter Ross <pross@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: bitstream.h,v 1.1.1.1 2005-07-13 14:36:12 jeanlf Exp $
- *
- ****************************************************************************/
-
-#ifndef _BITSTREAM_H_
-#define _BITSTREAM_H_
-
-#include "portab.h"
-#include "decoder.h"
-
-
-/*****************************************************************************
- * Constants
- ****************************************************************************/
-
-/* comment any #defs we dont use */
-
-#define VIDOBJ_START_CODE 0x00000100 /* ..0x0000011f */
-#define VIDOBJLAY_START_CODE 0x00000120 /* ..0x0000012f */
-#define VISOBJSEQ_START_CODE 0x000001b0
-#define VISOBJSEQ_STOP_CODE 0x000001b1 /* ??? */
-#define USERDATA_START_CODE 0x000001b2
-#define GRPOFVOP_START_CODE 0x000001b3
-/*#define VIDSESERR_ERROR_CODE 0x000001b4 */
-#define VISOBJ_START_CODE 0x000001b5
-#define VOP_START_CODE 0x000001b6
-/*#define STUFFING_START_CODE 0x000001c3 */
-
-
-#define VISOBJ_TYPE_VIDEO 1
-/*#define VISOBJ_TYPE_STILLTEXTURE 2 */
-/*#define VISOBJ_TYPE_MESH 3 */
-/*#define VISOBJ_TYPE_FBA 4 */
-/*#define VISOBJ_TYPE_3DMESH 5 */
-
-
-#define VIDOBJLAY_TYPE_SIMPLE 1
-/*#define VIDOBJLAY_TYPE_SIMPLE_SCALABLE 2 */
-/*#define VIDOBJLAY_TYPE_CORE 3 */
-/*#define VIDOBJLAY_TYPE_MAIN 4 */
-/*#define VIDOBJLAY_TYPE_NBIT 5 */
-/*#define VIDOBJLAY_TYPE_ANIM_TEXT 6 */
-/*#define VIDOBJLAY_TYPE_ANIM_MESH 7 */
-/*#define VIDOBJLAY_TYPE_SIMPLE_FACE 8 */
-/*#define VIDOBJLAY_TYPE_STILL_SCALABLE 9 */
-#define VIDOBJLAY_TYPE_ART_SIMPLE 10
-/*#define VIDOBJLAY_TYPE_CORE_SCALABLE 11 */
-/*#define VIDOBJLAY_TYPE_ACE 12 */
-/*#define VIDOBJLAY_TYPE_ADVANCED_SCALABLE_TEXTURE 13 */
-/*#define VIDOBJLAY_TYPE_SIMPLE_FBA 14 */
-/*#define VIDEOJLAY_TYPE_SIMPLE_STUDIO 15*/
-/*#define VIDEOJLAY_TYPE_CORE_STUDIO 16*/
-#define VIDOBJLAY_TYPE_ASP 17
-/*#define VIDOBJLAY_TYPE_FGS 18*/
-
-
-/*#define VIDOBJLAY_AR_SQUARE 1 */
-/*#define VIDOBJLAY_AR_625TYPE_43 2 */
-/*#define VIDOBJLAY_AR_525TYPE_43 3 */
-/*#define VIDOBJLAY_AR_625TYPE_169 8 */
-/*#define VIDOBJLAY_AR_525TYPE_169 9 */
-#define VIDOBJLAY_AR_EXTPAR 15
-
-
-#define VIDOBJLAY_SHAPE_RECTANGULAR 0
-#define VIDOBJLAY_SHAPE_BINARY 1
-#define VIDOBJLAY_SHAPE_BINARY_ONLY 2
-#define VIDOBJLAY_SHAPE_GRAYSCALE 3
-
-
-#define SPRITE_NONE 0
-#define SPRITE_STATIC 1
-#define SPRITE_GMC 2
-
-
-
-#define READ_MARKER() bs->Skip(1)
-//#define WRITE_MARKER() BitstreamPutBit(bs, 1)
-
-/* vop coding types */
-/* intra, prediction, backward, sprite, not_coded */
-#define I_VOP 0
-#define P_VOP 1
-#define B_VOP 2
-#define S_VOP 3
-#define N_VOP 4
-
-/* resync-specific */
-#define NUMBITS_VP_RESYNC_MARKER 17
-#define RESYNC_MARKER 1
-
-extern const dword scan_tables[3][64];
-
-
-#endif /* _BITSTREAM_H_ */
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Decoder Module -
- *
- * Copyright(C) 2002 MinChen <chenm001@163.com>
- * 2002-2003 Peter Ross <pross@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: decoder.cpp,v 1.4 2008-08-20 13:57:54 jeanlf Exp $
- *
- ****************************************************************************/
-
-#include "quant.h"
-#include "quant_matrix.h"
-#include "interpolate8x8.h"
-#include "reduced.h"
-#include "mbprediction.h"
-#include "gmc.h"
-#include "mem_align.h"
-
-#ifdef __SYMBIAN32__
-#include <e32base.h>
-#endif
-
-//----------------------------
-
-# define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
- type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
- type * name = (type *) (((int) name##_storage+(alignment - 1)) & ~((int)(alignment)-1))
-
-//----------------------------
-//----------------------------
-/* K = 4 */
-static const dword roundtab_76[16] = { 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1 };
-
-/* K = 1 */
-const dword roundtab_79[4] = { 0, 1, 0, 0 };
-
-//----------------------------
-
-int S_decoder::Resize(){
- //free existing
- image_destroy(&cur, edged_width, edged_height);
- image_destroy(&refn[0], edged_width, edged_height);
- image_destroy(&refn[1], edged_width, edged_height);
- image_destroy(&tmp, edged_width, edged_height);
- image_destroy(&qtmp, edged_width, edged_height);
-
- image_destroy(&gmc, edged_width, edged_height);
-
- if(last_mbs)
- xvid_free(last_mbs);
- if(mbs)
- xvid_free(mbs);
-
- //realloc
- mb_width = (width + 15) / 16;
- mb_height = (height + 15) / 16;
-
- edged_width = 16 * mb_width + 2 * EDGE_SIZE;
- edged_height = 16 * mb_height + 2 * EDGE_SIZE;
-
- if(image_create(&cur, edged_width, edged_height)){
- xvid_free(this);
- return XVID_ERR_MEMORY;
- }
-
- if(image_create(&refn[0], edged_width, edged_height)){
- image_destroy(&cur, edged_width, edged_height);
- xvid_free(this);
- return XVID_ERR_MEMORY;
- }
-
- //support B-frame to reference last 2 frame
- if(image_create(&refn[1], edged_width, edged_height)){
- image_destroy(&cur, edged_width, edged_height);
- image_destroy(&refn[0], edged_width, edged_height);
- xvid_free(this);
- return XVID_ERR_MEMORY;
- }
- if(image_create(&tmp, edged_width, edged_height)){
- image_destroy(&cur, edged_width, edged_height);
- image_destroy(&refn[0], edged_width, edged_height);
- image_destroy(&refn[1], edged_width, edged_height);
- xvid_free(this);
- return XVID_ERR_MEMORY;
- }
-
- if(image_create(&qtmp, edged_width, edged_height)){
- image_destroy(&cur, edged_width, edged_height);
- image_destroy(&refn[0], edged_width, edged_height);
- image_destroy(&refn[1], edged_width, edged_height);
- image_destroy(&tmp, edged_width, edged_height);
- xvid_free(this);
- return XVID_ERR_MEMORY;
- }
-
- if(image_create(&gmc, edged_width, edged_height)){
- image_destroy(&qtmp, edged_width, edged_height);
- image_destroy(&cur, edged_width, edged_height);
- image_destroy(&refn[0], edged_width, edged_height);
- image_destroy(&refn[1], edged_width, edged_height);
- image_destroy(&tmp, edged_width, edged_height);
- xvid_free(this);
- return XVID_ERR_MEMORY;
- }
-
- mbs = (MACROBLOCK*)xvid_malloc(sizeof(MACROBLOCK) * mb_width * mb_height, CACHE_LINE);
- if(mbs == NULL){
- image_destroy(&cur, edged_width, edged_height);
- image_destroy(&refn[0], edged_width, edged_height);
- image_destroy(&refn[1], edged_width, edged_height);
- image_destroy(&tmp, edged_width, edged_height);
- image_destroy(&qtmp, edged_width, edged_height);
- xvid_free(this);
- return XVID_ERR_MEMORY;
- }
- MemSet(mbs, 0, sizeof(MACROBLOCK) * mb_width * mb_height);
-
- //for skip MB flag
- last_mbs = (MACROBLOCK*)xvid_malloc(sizeof(MACROBLOCK) * mb_width * mb_height, CACHE_LINE);
- if(!last_mbs){
- xvid_free(mbs);
- image_destroy(&cur, edged_width, edged_height);
- image_destroy(&refn[0], edged_width, edged_height);
- image_destroy(&refn[1], edged_width, edged_height);
- image_destroy(&tmp, edged_width, edged_height);
- image_destroy(&qtmp, edged_width, edged_height);
- xvid_free(this);
- return XVID_ERR_MEMORY;
- }
- MemSet(last_mbs, 0, sizeof(MACROBLOCK) * mb_width * mb_height);
-
- return 0;
-}
-
-//----------------------------
-
-int decoder_create(xvid_dec_create_t *create){
-
- if(XVID_VERSION_MAJOR(create->version) != 1) /* v1.x.x */
- return XVID_ERR_VERSION;
-
- S_decoder *dec = (S_decoder*)xvid_malloc(sizeof(S_decoder), CACHE_LINE);
- //S_decoder *dec = new(ELeave) S_decoder(create);
- if(!dec)
- return XVID_ERR_MEMORY;
-
- return dec->Init(create);
-}
-
-//----------------------------
-
-S_decoder::S_decoder(xvid_dec_create_t *create):
-#ifdef PROFILE
- prof(*create->prof),
-#endif
- time_inc_resolution(0),
- fixed_time_inc(0),
- time_inc_bits(0),
- shape(0),
- quant_bits(0),
- quant_type(0),
- mpeg_quant_matrices(0),
- quarterpel(0),
- complexity_estimation_disable(0),
- interlacing(false),
- top_field_first(0),
- alternate_vertical_scan(0),
- aspect_ratio(0),
- par_width(0),
- par_height(0),
- sprite_enable(0),
- sprite_warping_points(0),
- sprite_warping_accuracy(0),
- sprite_brightness_change(0),
- newpred_enable(0),
- reduced_resolution_enable(false),
- bs_version(0),
- width(0),
- height(0),
- edged_width(0),
- edged_height(0),
- mb_width(0),
- mb_height(0),
- mbs(0),
- last_mbs(0),
- last_coding_type(0),
- frames(0),
- time(0),
- time_base(0),
- last_time_base(0),
- last_non_b_time(0),
- time_pp(0),
- time_bp(0),
- fixed_dimensions(false),
- scalability(false),
- low_delay(false),
- low_delay_default(false),
- last_reduced_resolution(false),
- packed_mode(false)
-{
- MemSet(&p_fmv, 0, sizeof(p_fmv));
- MemSet(&p_bmv, 0, sizeof(p_bmv));
-}
-
-//----------------------------
-
-S_decoder::~S_decoder(){
-
- xvid_free(last_mbs);
- xvid_free(mbs);
-
- //image based GMC
- image_destroy(&gmc, edged_width, edged_height);
-
- image_destroy(&refn[0], edged_width, edged_height);
- image_destroy(&refn[1], edged_width, edged_height);
- image_destroy(&tmp, edged_width, edged_height);
- image_destroy(&qtmp, edged_width, edged_height);
- image_destroy(&cur, edged_width, edged_height);
- xvid_free(mpeg_quant_matrices);
-}
-
-//----------------------------
-
-int S_decoder::Init(xvid_dec_create_t *create){
-
- mpeg_quant_matrices = (dword*)xvid_malloc(sizeof(dword) * 64 * 8, CACHE_LINE);
- if(!mpeg_quant_matrices){
- delete this;
- return XVID_ERR_MEMORY;
- }
-
- create->handle = this;
-
- width = create->width;
- height = create->height;
-
- cur.Null();
- refn[0].Null();
- refn[1].Null();
- tmp.Null();
- qtmp.Null();
-
- //image based GMC
- gmc.Null();
-
-
- mbs = NULL;
- last_mbs = NULL;
-
- init_mpeg_matrix(mpeg_quant_matrices);
-
- //For B-frame support (used to save reference frame's time
- frames = 0;
- time = time_base = last_time_base = 0;
- low_delay = false;
- packed_mode = false;
-
- fixed_dimensions = (width > 0 && height > 0);
-
- init_vlc_tables();
- idct_int32_init();
-
- if(fixed_dimensions)
- return Resize();
- return 0;
-}
-
-//----------------------------
-
-static const int dquant_table[4] = {
- -1, -2, 1, 2
-};
-
-//----------------------------
-
-static dword get_dc_scaler(dword quant, dword lum){
-
- if(quant < 5)
- return 8;
- if(quant < 25 && !lum)
- return (quant + 13) / 2;
- if(quant < 9)
- return 2 * quant;
- if(quant < 25)
- return quant + 8;
- if(lum)
- return 2 * quant - 16;
- return quant - 6;
-}
-
-//---------------------------
-
-#ifdef _ARM_
-extern"C"
-void XVID_ClearMatrix(void *dst);
-
-#else
-void XVID_ClearMatrix(void *dst);
-#ifndef USE_ARM_ASM
-inline void XVID_ClearMatrix(void *dst){ MemSet(dst, 0, 64 * sizeof(int)); }
-#endif
-#endif
-
-//--------------------------
-/* decode an intra macroblock */
-void S_decoder::MBIntra(MACROBLOCK *pMB, dword x_pos, dword y_pos, dword acpred_flag, dword cbp, Bitstream *bs,
- dword quant, dword intra_dc_threshold, dword bound, bool reduced_resolution){
-
- DECLARE_ALIGNED_MATRIX(block, 6, 64, int, CACHE_LINE);
- DECLARE_ALIGNED_MATRIX(data, 6, 64, int, CACHE_LINE);
-
- int i;
-
- dword stride = edged_width;
- const dword stride2 = stride / 2;
- byte *pY_Cur, *pU_Cur, *pV_Cur;
-
- if(reduced_resolution) {
- pY_Cur = cur.y + (y_pos << 5) * stride + (x_pos << 5);
- pU_Cur = cur.u + (y_pos << 4) * stride2 + (x_pos << 4);
- pV_Cur = cur.v + (y_pos << 4) * stride2 + (x_pos << 4);
- }else{
- pY_Cur = cur.y + (y_pos << 4) * stride + (x_pos << 4);
- pU_Cur = cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
- pV_Cur = cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
- }
-
- MemSet(block, 0, 6 * 64 * sizeof(int)); //clear
-
- const dword iQuant = pMB->quant;
- for(i = 0; i < 6; i++){
- dword iDcScaler = get_dc_scaler(iQuant, i < 4);
- int predictors[8];
- int start_coeff;
-
- predict_acdc(mbs, x_pos, y_pos, mb_width, i, &block[i * 64], iQuant, iDcScaler, predictors, bound);
- if(!acpred_flag)
- pMB->acpred_directions[i] = 0;
-
- if(quant < intra_dc_threshold){
- PROF_S(PROF_1);
- int dc_size;
- int dc_dif;
-
- dc_size = i < 4 ? bs->get_dc_size_lum() : bs->get_dc_size_chrom();
- dc_dif = dc_size ? bs->get_dc_dif(dc_size) : 0;
-
- if (dc_size > 8) {
- bs->Skip(1); /* marker */
- }
-
- block[i * 64 + 0] = dc_dif;
- start_coeff = 1;
-
- DPRINTF(XVID_DEBUG_COEFF,"block[0] %i\n", dc_dif);
- PROF_E(PROF_1);
- }else{
- start_coeff = 0;
- }
- if(cbp & (1 << (5 - i))){
- //coded
- int direction = alternate_vertical_scan ? 2 : pMB->acpred_directions[i];
- get_intra_block(bs, &block[i * 64], direction, start_coeff);
- }
- add_acdc(pMB, i, &block[i * 64], iDcScaler, predictors);
- if(quant_type == 0){
- dequant_h263_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler, mpeg_quant_matrices);
- }else{
- dequant_mpeg_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler, mpeg_quant_matrices);
- }
- InverseDiscreteCosineTransform(&data[i * 64]);
- }
-
- dword next_block = stride * 8;
- if(interlacing && pMB->field_dct){
- next_block = stride;
- stride *= 2;
- }
- if(reduced_resolution){
- next_block*=2;
- copy_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
- copy_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
- copy_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
- copy_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride);
- copy_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);
- copy_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);
- }else{
- transfer_16to8copy(pY_Cur, &data[0 * 64], stride);
- transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);
- transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);
- transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride);
- transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);
- transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);
- }
-}
-
-//----------------------------
-
-void S_decoder::mb_decode(const dword cbp, Bitstream * bs, byte * pY_Cur, byte * pU_Cur, byte * pV_Cur, bool reduced_resolution, const MACROBLOCK *pMB){
-
- DECLARE_ALIGNED_MATRIX(block, 1, 64, int, CACHE_LINE);
- DECLARE_ALIGNED_MATRIX(data, 6, 64, int, CACHE_LINE);
-
- int i;
- int stride = edged_width;
- const int stride2 = stride/2;
-
- const dword iQuant = pMB->quant;
- const int direction = alternate_vertical_scan ? 2 : 0;
- const quant_interFuncPtr dequant = quant_type == 0 ? dequant_h263_inter : dequant_mpeg_inter;
- for(i = 0; i < 6; i++){
- if(cbp & (1 << (5 - i))){
- //coded
- XVID_ClearMatrix(block);
- get_inter_block(bs, block, direction);
- dequant(&data[i * 64], block, iQuant, mpeg_quant_matrices);
- InverseDiscreteCosineTransform(&data[i * 64]);
- }
- }
-
- int next_block = stride * (reduced_resolution ? 16 : 8);
- if(interlacing && pMB->field_dct){
- next_block = stride;
- stride *= 2;
- }
-
- if(reduced_resolution){
- if(cbp & 32)
- add_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride);
- if(cbp & 16)
- add_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride);
- if(cbp & 8)
- add_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride);
- if(cbp & 4)
- add_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride);
- if(cbp & 2)
- add_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2);
- if(cbp & 1)
- add_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2);
- }else{
- if(cbp & 32)
- transfer_16to8add(pY_Cur, &data[0 * 64], stride);
- if(cbp & 16)
- transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);
- if(cbp & 8)
- transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
- if(cbp & 4)
- transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride);
- if(cbp & 2)
- transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
- if(cbp & 1)
- transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
- }
-}
-
-//----------------------------
-
-void S_decoder::DecodeInterMacroBlock(const MACROBLOCK * pMB, dword x_pos, dword y_pos, dword cbp, Bitstream *bs,
- bool rounding, bool reduced_resolution, int ref){
-
- dword stride = edged_width;
- dword stride2 = stride / 2;
- dword i;
-
- byte *pY_Cur, *pU_Cur, *pV_Cur;
-
- int uv_dx, uv_dy;
- VECTOR mv[4]; //local copy of mvs
-
- if(reduced_resolution){
- pY_Cur = cur.y + (y_pos << 5) * stride + (x_pos << 5);
- pU_Cur = cur.u + (y_pos << 4) * stride2 + (x_pos << 4);
- pV_Cur = cur.v + (y_pos << 4) * stride2 + (x_pos << 4);
- for (i = 0; i < 4; i++) {
- mv[i].x = RRV_MV_SCALEUP(pMB->mvs[i].x);
- mv[i].y = RRV_MV_SCALEUP(pMB->mvs[i].y);
- }
- }else{
- pY_Cur = cur.y + (y_pos << 4) * stride + (x_pos << 4);
- pU_Cur = cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
- pV_Cur = cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
- for(i = 0; i < 4; i++)
- mv[i] = pMB->mvs[i];
- }
-
- if(pMB->mode != MODE_INTER4V){
- //INTER, INTER_Q, NOT_CODED, FORWARD, BACKWARD
-
- uv_dx = mv[0].x;
- uv_dy = mv[0].y;
- if (quarterpel) {
- uv_dx /= 2;
- uv_dy /= 2;
- }
- uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
- uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
-
- if(reduced_resolution)
- interpolate32x32_switch(cur.y, refn[0].y, 32*x_pos, 32*y_pos, mv[0].x, mv[0].y, stride, rounding);
- else
- if(quarterpel)
- interpolate16x16_quarterpel(cur.y, refn[ref].y, qtmp.y, qtmp.y + 64, qtmp.y + 128, 16*x_pos, 16*y_pos, mv[0].x, mv[0].y, stride, rounding);
- else
- interpolate16x16_switch(cur.y, refn[ref].y, 16*x_pos, 16*y_pos, mv[0].x, mv[0].y, stride, rounding);
- }else{
- //MODE_INTER4V
-
- if(quarterpel) {
- uv_dx = (mv[0].x / 2) + (mv[1].x / 2) + (mv[2].x / 2) + (mv[3].x / 2);
- uv_dy = (mv[0].y / 2) + (mv[1].y / 2) + (mv[2].y / 2) + (mv[3].y / 2);
- }else{
- uv_dx = mv[0].x + mv[1].x + mv[2].x + mv[3].x;
- uv_dy = mv[0].y + mv[1].y + mv[2].y + mv[3].y;
- }
-
- uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf];
- uv_dy = (uv_dy >> 3) + roundtab_76[uv_dy & 0xf];
-
- if(reduced_resolution){
- interpolate16x16_switch(cur.y, refn[0].y, 32*x_pos, 32*y_pos, mv[0].x, mv[0].y, stride, rounding);
- interpolate16x16_switch(cur.y, refn[0].y, 32*x_pos + 16, 32*y_pos, mv[1].x, mv[1].y, stride, rounding);
- interpolate16x16_switch(cur.y, refn[0].y, 32*x_pos, 32*y_pos + 16, mv[2].x, mv[2].y, stride, rounding);
- interpolate16x16_switch(cur.y, refn[0].y, 32*x_pos + 16, 32*y_pos + 16, mv[3].x, mv[3].y, stride, rounding);
- interpolate16x16_switch(cur.u, refn[0].u, 16*x_pos, 16*y_pos, uv_dx, uv_dy, stride2, rounding);
- interpolate16x16_switch(cur.v, refn[0].v, 16*x_pos, 16*y_pos, uv_dx, uv_dy, stride2, rounding);
- }else
- if(quarterpel){
- interpolate8x8_quarterpel(cur.y, refn[0].y , qtmp.y, qtmp.y + 64, qtmp.y + 128, 16*x_pos, 16*y_pos, mv[0].x, mv[0].y, stride, rounding);
- interpolate8x8_quarterpel(cur.y, refn[0].y , qtmp.y, qtmp.y + 64, qtmp.y + 128, 16*x_pos + 8, 16*y_pos, mv[1].x, mv[1].y, stride, rounding);
- interpolate8x8_quarterpel(cur.y, refn[0].y , qtmp.y, qtmp.y + 64, qtmp.y + 128, 16*x_pos, 16*y_pos + 8, mv[2].x, mv[2].y, stride, rounding);
- interpolate8x8_quarterpel(cur.y, refn[0].y , qtmp.y, qtmp.y + 64, qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, mv[3].x, mv[3].y, stride, rounding);
- } else {
- interpolate8x8_switch(cur.y, refn[0].y , 16*x_pos, 16*y_pos, mv[0].x, mv[0].y, stride, rounding);
- interpolate8x8_switch(cur.y, refn[0].y , 16*x_pos + 8, 16*y_pos, mv[1].x, mv[1].y, stride, rounding);
- interpolate8x8_switch(cur.y, refn[0].y , 16*x_pos, 16*y_pos + 8, mv[2].x, mv[2].y, stride, rounding);
- interpolate8x8_switch(cur.y, refn[0].y , 16*x_pos + 8, 16*y_pos + 8, mv[3].x, mv[3].y, stride, rounding);
- }
- }
- //chroma
- if(reduced_resolution){
- interpolate16x16_switch(cur.u, refn[0].u, 16*x_pos, 16*y_pos, uv_dx, uv_dy, stride2, rounding);
- interpolate16x16_switch(cur.v, refn[0].v, 16*x_pos, 16*y_pos, uv_dx, uv_dy, stride2, rounding);
- }else{
- interpolate8x8_switch(cur.u, refn[ref].u, 8*x_pos, 8*y_pos, uv_dx, uv_dy, stride2, rounding);
- interpolate8x8_switch(cur.v, refn[ref].v, 8*x_pos, 8*y_pos, uv_dx, uv_dy, stride2, rounding);
- }
- if(cbp)
- mb_decode(cbp, bs, pY_Cur, pU_Cur, pV_Cur, reduced_resolution, pMB);
-}
-
-//----------------------------
-
-inline int gmc_sanitize(int value, int quarterpel, int fcode){
-
- int length = 1 << (fcode+4);
-
-#if 0
- if (quarterpel) value *= 2;
-#endif
-
- if (value < -length)
- return -length;
- else if (value >= length)
- return length-1;
- else return value;
-}
-
-//----------------------------
-
-void S_decoder::mbgmc(MACROBLOCK *pMB, dword x_pos, dword y_pos, dword fcode, dword cbp, Bitstream * bs, bool rounding){
-
- const dword stride = edged_width;
- const dword stride2 = stride / 2;
-
- byte *const pY_Cur=cur.y + (y_pos << 4) * stride + (x_pos << 4);
- byte *const pU_Cur=cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
- byte *const pV_Cur=cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
-
- NEW_GMC_DATA *gmc_data = &new_gmc_data;
-
- pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
-
- //this is where the calculations are done
- gmc_data->predict_16x16(gmc_data, cur.y + y_pos*16*stride + x_pos*16, refn[0].y, stride, stride, x_pos, y_pos, rounding);
- gmc_data->predict_8x8(gmc_data, cur.u + y_pos*8*stride2 + x_pos*8, refn[0].u, cur.v + y_pos*8*stride2 + x_pos*8, refn[0].v, stride2, stride2, x_pos, y_pos, rounding);
- gmc_data->get_average_mv(gmc_data, &pMB->amv, x_pos, y_pos, quarterpel);
-
- pMB->amv.x = gmc_sanitize(pMB->amv.x, quarterpel, fcode);
- pMB->amv.y = gmc_sanitize(pMB->amv.y, quarterpel, fcode);
-
- pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;
-
- if(cbp)
- mb_decode(cbp, bs, pY_Cur, pU_Cur, pV_Cur, 0, pMB);
-}
-
-//----------------------------
-
-void S_decoder::I_Frame(Bitstream * bs, bool reduced_resolution, int quant, int intra_dc_threshold){
-
- dword bound;
- dword x, y;
- //dword mb_width = mb_width;
- //dword mb_height = mb_height;
-
- if (reduced_resolution) {
- mb_width = (width + 31) / 32;
- mb_height = (height + 31) / 32;
- }
-
- bound = 0;
-
- for (y = 0; y < mb_height; y++) {
- for (x = 0; x < mb_width; x++) {
- dword mcbpc;
- dword cbpc;
- dword acpred_flag;
- dword cbpy;
- dword cbp;
-
- while(bs->ShowBits(9) == 1)
- bs->Skip(9);
-
- if(bs->check_resync_marker(0)){
- bound = read_video_packet_header(bs, 0, &quant, NULL, NULL, &intra_dc_threshold);
- x = bound % mb_width;
- y = bound / mb_width;
- }
- MACROBLOCK *mb = &mbs[y * mb_width + x];
-
- //DPRINTF(XVID_DEBUG_MB, "macroblock (%i,%i) %08x\n", x, y, bs->ShowBits(32));
-
- mcbpc = bs->get_mcbpc_intra();
- mb->mode = mcbpc & 7;
- cbpc = (mcbpc >> 4);
-
- acpred_flag = bs->GetBit();
-
- cbpy = bs->GetCbpy(1);
- cbp = (cbpy << 2) | cbpc;
-
- if (mb->mode == MODE_INTRA_Q) {
- quant += dquant_table[bs->GetBits(2)];
- if (quant > 31) {
- quant = 31;
- } else if (quant < 1) {
- quant = 1;
- }
- }
- mb->quant = quant;
- mb->mvs[0].x = mb->mvs[0].y =
- mb->mvs[1].x = mb->mvs[1].y =
- mb->mvs[2].x = mb->mvs[2].y =
- mb->mvs[3].x = mb->mvs[3].y =0;
-
- if(interlacing){
- mb->field_dct = bs->GetBit();
- DPRINTF(XVID_DEBUG_MB,"deci: field_dct: %i\n", mb->field_dct);
- }
- MBIntra(mb, x, y, acpred_flag, cbp, bs, quant, intra_dc_threshold, bound, reduced_resolution);
- }
- /*
-#ifdef XVID_CSP_SLICE
- if(out_frm)
- output_slice(&cur, edged_width,width,out_frm,0,y,mb_width);
-#endif
- */
- }
-}
-
-//----------------------------
-
-void S_decoder::GetMotionVector(Bitstream * bs, int x, int y, int k, VECTOR *ret_mv, int fcode, int bound){
-
- const int scale_fac = 1 << (fcode - 1);
- const int high = (32 * scale_fac) - 1;
- const int low = ((-32) * scale_fac);
- const int range = (64 * scale_fac);
-
- const VECTOR pmv = get_pmv2(mbs, mb_width, bound, x, y, k);
- VECTOR mv;
-
- mv.x = bs->GetMoveVector(fcode);
- mv.y = bs->GetMoveVector(fcode);
-
- //DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", mv.x, mv.y, pmv.x, pmv.y, mv.x+pmv.x, mv.y+pmv.y);
-
- mv.x += pmv.x;
- mv.y += pmv.y;
-
- if(mv.x < low){
- mv.x += range;
- }else
- if(mv.x > high){
- mv.x -= range;
- }
-
- if(mv.y < low){
- mv.y += range;
- }else
- if(mv.y > high){
- mv.y -= range;
- }
-
- ret_mv->x = mv.x;
- ret_mv->y = mv.y;
-}
-
-//----------------------------
-// for P_VOP set gmc_warp to NULL
-void S_decoder::P_Frame(Bitstream *bs, int rounding, bool reduced_resolution, int quant, int fcode,
- int intra_dc_threshold, const WARPPOINTS *gmc_warp){
-
- //dword mb_width = mb_width;
- //dword mb_height = mb_height;
-
- if(reduced_resolution){
- mb_width = (width + 31) / 32;
- mb_height = (height + 31) / 32;
- }
-
- SetEdges(refn[0]);
-
- if(gmc_warp){
- //accuracy: 0==1/2, 1=1/4, 2=1/8, 3=1/16
- generate_GMCparameters(sprite_warping_points, sprite_warping_accuracy, gmc_warp, width, height, &new_gmc_data);
- //image warping is done block-based in decoder_mbgmc(), now
- }
-
- PROF_S(PROF_FRM_P);
- dword bound = 0;
-
- for(dword y = 0; y < mb_height; y++){
- //int cp_mb = 0, st_mb = 0;
- for(dword x = 0; x < mb_width; x++){
- //skip stuffing
- while(bs->ShowBits(10) == 1)
- bs->Skip(10);
-
- if(bs->check_resync_marker(fcode - 1)){
- bound = read_video_packet_header(bs, fcode - 1, &quant, &fcode, NULL, &intra_dc_threshold);
- x = bound % mb_width;
- y = bound / mb_width;
- }
- MACROBLOCK *mb = &mbs[y * mb_width + x];
-
- //DPRINTF(XVID_DEBUG_MB, "macroblock (%i,%i) %08x\n", x, y, bs->ShowBits(32));
-
- if(!(bs->GetBit())){
- //block _is_ coded
- int mcsel = 0; //mcsel: '0'=local motion, '1'=GMC
-
- //cp_mb++;
- dword mcbpc = bs->GetMcbpcInter();
- mb->mode = mcbpc & 7;
- dword cbpc = (mcbpc >> 4);
-
- DPRINTF(XVID_DEBUG_MB, "mode %i\n", mb->mode);
- DPRINTF(XVID_DEBUG_MB, "cbpc %i\n", cbpc);
-
- dword intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q);
-
- dword acpred_flag = 0;
- if(gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q))
- mcsel = bs->GetBit();
- else
- if(intra)
- acpred_flag = bs->GetBit();
-
- dword cbpy = bs->GetCbpy(intra);
- //DPRINTF(XVID_DEBUG_MB, "cbpy %i mcsel %i \n", cbpy,mcsel);
-
- dword cbp = (cbpy << 2) | cbpc;
-
- if(mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q){
- int dquant = dquant_table[bs->GetBits(2)];
- DPRINTF(XVID_DEBUG_MB, "dquant %i\n", dquant);
- quant += dquant;
- if (quant > 31) {
- quant = 31;
- } else if (quant < 1) {
- quant = 1;
- }
- DPRINTF(XVID_DEBUG_MB, "quant %i\n", quant);
- }
- mb->quant = quant;
-
- if(interlacing){
- if((cbp || intra) && !mcsel){
- mb->field_dct = bs->GetBit();
- DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct);
- }
-
- if(mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q){
- mb->field_pred = bs->GetBit();
- DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred);
-
- if(mb->field_pred){
- mb->field_for_top = bs->GetBit();
- DPRINTF(XVID_DEBUG_MB,"decp: field_for_top: %i\n", mb->field_for_top);
- mb->field_for_bot = bs->GetBit();
- DPRINTF(XVID_DEBUG_MB,"decp: field_for_bot: %i\n", mb->field_for_bot);
- }
- }
- }
- if(mcsel){
- mbgmc(mb, x, y, fcode, cbp, bs, rounding);
- PROF_E(PROF_0);
- continue;
-
- }else
- if(mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q){
- if(interlacing && mb->field_pred){
- GetMotionVector(bs, x, y, 0, &mb->mvs[0], fcode, bound);
- GetMotionVector(bs, x, y, 0, &mb->mvs[1], fcode, bound);
- }else{
- GetMotionVector(bs, x, y, 0, &mb->mvs[0], fcode, bound);
- mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0];
- }
- }else
- if(mb->mode == MODE_INTER4V){
- GetMotionVector(bs, x, y, 0, &mb->mvs[0], fcode, bound);
- GetMotionVector(bs, x, y, 1, &mb->mvs[1], fcode, bound);
- GetMotionVector(bs, x, y, 2, &mb->mvs[2], fcode, bound);
- GetMotionVector(bs, x, y, 3, &mb->mvs[3], fcode, bound);
- }else{ /* MODE_INTRA, MODE_INTRA_Q */
- mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0;
- mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0;
- MBIntra(mb, x, y, acpred_flag, cbp, bs, quant, intra_dc_threshold, bound, reduced_resolution);
- continue;
- }
- PROF_S(PROF_5);
- DecodeInterMacroBlock(mb, x, y, cbp, bs, rounding, reduced_resolution, 0);
- PROF_E(PROF_5);
- }else
- if(gmc_warp){
- //a not coded S(GMC)-VOP macroblock
- mb->mode = MODE_NOT_CODED_GMC;
- mbgmc(mb, x, y, fcode, 0x00, bs, rounding);
-
- /*
-#ifdef XVID_CSP_SLICE
- if(out_frm && cp_mb > 0) {
- output_slice(&cur, edged_width,width,out_frm,st_mb,y,cp_mb);
- cp_mb = 0;
- }
- st_mb = x+1;
-#endif
- */
- }else{
- //not coded P_VOP macroblock
- mb->mode = MODE_NOT_CODED;
-
- mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0;
- mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0;
-
- DecodeInterMacroBlock(mb, x, y, 0, bs, rounding, reduced_resolution, 0);
- /*
-#ifdef XVID_CSP_SLICE
- if(out_frm && cp_mb > 0) {
- output_slice(&cur, edged_width,width,out_frm,st_mb,y,cp_mb);
- cp_mb = 0;
- }
- st_mb = x+1;
-#endif
- */
- }
- }
- /*
-#ifdef XVID_CSP_SLICE
- if(out_frm && cp_mb > 0)
- output_slice(&cur, edged_width,width,out_frm,st_mb,y,cp_mb);
-#endif
- */
- }
- PROF_E(PROF_FRM_P);
-}
-
-//----------------------------
-/* decode B-frame motion vector */
-static void get_b_motion_vector(Bitstream * bs, VECTOR * mv, int fcode, const VECTOR pmv){
-
- const int scale_fac = 1 << (fcode - 1);
- const int high = (32 * scale_fac) - 1;
- const int low = ((-32) * scale_fac);
- const int range = (64 * scale_fac);
-
- int mv_x = bs->GetMoveVector(fcode);
- int mv_y = bs->GetMoveVector(fcode);
-
- mv_x += pmv.x;
- mv_y += pmv.y;
-
- if (mv_x < low)
- mv_x += range;
- else if (mv_x > high)
- mv_x -= range;
-
- if (mv_y < low)
- mv_y += range;
- else if (mv_y > high)
- mv_y -= range;
-
- mv->x = mv_x;
- mv->y = mv_y;
-}
-
-//----------------------------
-/* decode an B-frame direct & interpolate macroblock */
-void S_decoder::BFrameInterpolateMBInter(const IMAGE &forward, const IMAGE &backward, const MACROBLOCK *pMB, dword x_pos, dword y_pos, Bitstream *bs, int direct){
-
- PROF_S(PROF_BINT_MBI);
- dword stride = edged_width;
- dword stride2 = stride / 2;
- int uv_dx, uv_dy;
- int b_uv_dx, b_uv_dy;
- byte *pY_Cur, *pU_Cur, *pV_Cur;
- const dword cbp = pMB->cbp;
-
- pY_Cur = cur.y + (y_pos << 4) * stride + (x_pos << 4);
- pU_Cur = cur.u + (y_pos << 3) * stride2 + (x_pos << 3);
- pV_Cur = cur.v + (y_pos << 3) * stride2 + (x_pos << 3);
-
- if(!direct){
- uv_dx = pMB->mvs[0].x;
- uv_dy = pMB->mvs[0].y;
-
- b_uv_dx = pMB->b_mvs[0].x;
- b_uv_dy = pMB->b_mvs[0].y;
-
- if(quarterpel){
- uv_dx /= 2;
- uv_dy /= 2;
- b_uv_dx /= 2;
- b_uv_dy /= 2;
- }
- uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3];
- uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3];
-
- b_uv_dx = (b_uv_dx >> 1) + roundtab_79[b_uv_dx & 0x3];
- b_uv_dy = (b_uv_dy >> 1) + roundtab_79[b_uv_dy & 0x3];
- }else{
- if(quarterpel) {
- uv_dx = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2);
- uv_dy = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2);
- b_uv_dx = (pMB->b_mvs[0].x / 2) + (pMB->b_mvs[1].x / 2) + (pMB->b_mvs[2].x / 2) + (pMB->b_mvs[3].x / 2);
- b_uv_dy = (pMB->b_mvs[0].y / 2) + (pMB->b_mvs[1].y / 2) + (pMB->b_mvs[2].y / 2) + (pMB->b_mvs[3].y / 2);
- } else {
- uv_dx = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;
- uv_dy = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
- b_uv_dx = pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x + pMB->b_mvs[3].x;
- b_uv_dy = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y;
- }
-
- uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf];
- uv_dy = (uv_dy >> 3) + roundtab_76[uv_dy & 0xf];
- b_uv_dx = (b_uv_dx >> 3) + roundtab_76[b_uv_dx & 0xf];
- b_uv_dy = (b_uv_dy >> 3) + roundtab_76[b_uv_dy & 0xf];
- }
-
- if(quarterpel){
- if(!direct){
- interpolate16x16_quarterpel(cur.y, forward.y, qtmp.y, qtmp.y + 64, qtmp.y + 128, 16*x_pos, 16*y_pos, pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
- }else{
- interpolate8x8_quarterpel(cur.y, forward.y, qtmp.y, qtmp.y + 64, qtmp.y + 128, 16*x_pos, 16*y_pos, pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
- interpolate8x8_quarterpel(cur.y, forward.y, qtmp.y, qtmp.y + 64, qtmp.y + 128, 16*x_pos + 8, 16*y_pos, pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);
- interpolate8x8_quarterpel(cur.y, forward.y, qtmp.y, qtmp.y + 64, qtmp.y + 128, 16*x_pos, 16*y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);
- interpolate8x8_quarterpel(cur.y, forward.y, qtmp.y, qtmp.y + 64, qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);
- }
- }else{
- interpolate8x8_switch(cur.y, forward.y, 16 * x_pos, 16 * y_pos, pMB->mvs[0].x, pMB->mvs[0].y, stride, 0);
- interpolate8x8_switch(cur.y, forward.y, 16 * x_pos + 8, 16 * y_pos, pMB->mvs[1].x, pMB->mvs[1].y, stride, 0);
- interpolate8x8_switch(cur.y, forward.y, 16 * x_pos, 16 * y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride, 0);
- interpolate8x8_switch(cur.y, forward.y, 16 * x_pos + 8, 16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride, 0);
- }
-
- interpolate8x8_switch(cur.u, forward.u, 8 * x_pos, 8 * y_pos, uv_dx, uv_dy, stride2, 0);
- interpolate8x8_switch(cur.v, forward.v, 8 * x_pos, 8 * y_pos, uv_dx, uv_dy, stride2, 0);
-
- if(quarterpel){
- if(!direct){
- interpolate16x16_quarterpel(tmp.y, backward.y, qtmp.y, qtmp.y + 64, qtmp.y + 128, 16*x_pos, 16*y_pos, pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
- }else{
- interpolate8x8_quarterpel(tmp.y, backward.y, qtmp.y, qtmp.y + 64, qtmp.y + 128, 16*x_pos, 16*y_pos, pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
- interpolate8x8_quarterpel(tmp.y, backward.y, qtmp.y, qtmp.y + 64, qtmp.y + 128, 16*x_pos + 8, 16*y_pos, pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0);
- interpolate8x8_quarterpel(tmp.y, backward.y, qtmp.y, qtmp.y + 64, qtmp.y + 128, 16*x_pos, 16*y_pos + 8, pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0);
- interpolate8x8_quarterpel(tmp.y, backward.y, qtmp.y, qtmp.y + 64, qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0);
- }
- }else{
- interpolate8x8_switch(tmp.y, backward.y, 16 * x_pos, 16 * y_pos, pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0);
- interpolate8x8_switch(tmp.y, backward.y, 16 * x_pos + 8, 16 * y_pos, pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0);
- interpolate8x8_switch(tmp.y, backward.y, 16 * x_pos, 16 * y_pos + 8, pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0);
- interpolate8x8_switch(tmp.y, backward.y, 16 * x_pos + 8, 16 * y_pos + 8, pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0);
- }
-
- interpolate8x8_switch(tmp.u, backward.u, 8 * x_pos, 8 * y_pos, b_uv_dx, b_uv_dy, stride2, 0);
- interpolate8x8_switch(tmp.v, backward.v, 8 * x_pos, 8 * y_pos, b_uv_dx, b_uv_dy, stride2, 0);
-
- interpolate8x8_avg2(cur.y + (16 * y_pos * stride) + 16 * x_pos, cur.y + (16 * y_pos * stride) + 16 * x_pos,
- tmp.y + (16 * y_pos * stride) + 16 * x_pos, stride, 1, 8);
-
- interpolate8x8_avg2(cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, cur.y + (16 * y_pos * stride) + 16 * x_pos + 8,
- tmp.y + (16 * y_pos * stride) + 16 * x_pos + 8, stride, 1, 8);
-
- interpolate8x8_avg2(cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos,
- tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, stride, 1, 8);
-
- interpolate8x8_avg2(cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8,
- tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, stride, 1, 8);
-
- interpolate8x8_avg2(cur.u + (8 * y_pos * stride2) + 8 * x_pos, cur.u + (8 * y_pos * stride2) + 8 * x_pos,
- tmp.u + (8 * y_pos * stride2) + 8 * x_pos, stride2, 1, 8);
-
- interpolate8x8_avg2(cur.v + (8 * y_pos * stride2) + 8 * x_pos, cur.v + (8 * y_pos * stride2) + 8 * x_pos,
- tmp.v + (8 * y_pos * stride2) + 8 * x_pos, stride2, 1, 8);
-
- if(cbp)
- mb_decode(cbp, bs, pY_Cur, pU_Cur, pV_Cur, 0, pMB);
- PROF_E(PROF_BINT_MBI);
-}
-
-//----------------------------
-/* for decode B-frame dbquant */
-static int get_dbquant(Bitstream * bs){
- if (!bs->GetBit()) /* '0' */
- return (0);
- else if (!bs->GetBit()) /* '10' */
- return (-2);
- else /* '11' */
- return (2);
-}
-
-//----------------------------
-/*
- * decode B-frame mb_type
- * bit ret_value
- * 1 0
- * 01 1
- * 001 2
- * 0001 3
- */
-static int get_mbtype(Bitstream * bs){
- int mb_type;
-
- for (mb_type = 0; mb_type <= 3; mb_type++)
- if (bs->GetBit())
- return (mb_type);
-
- return -1;
-}
-
-//----------------------------
-
-void S_decoder::B_Frame(Bitstream *bs, int quant, int fcode_forward, int fcode_backward){
-
- dword x, y;
- VECTOR mv;
- const VECTOR zeromv = {0,0};
- const int64_t TRB = time_pp - time_bp, TRD = time_pp;
- int i;
-
- PROF_S(PROF_FRM_B);
- SetEdges(refn[0]);
- SetEdges(refn[1]);
-
- for(y = 0; y < mb_height; y++){
- //initialize Pred Motion Vector
- p_fmv = p_bmv = zeromv;
- for(x = 0; x < mb_width; x++){
- MACROBLOCK *mb = &mbs[y * mb_width + x];
- MACROBLOCK *last_mb = &last_mbs[y * mb_width + x];
- const int fcode_max = (fcode_forward>fcode_backward) ? fcode_forward : fcode_backward;
-
- if(bs->check_resync_marker(fcode_max - 1)){
- dword intra_dc_threshold; /* fake variable */
- int bound = read_video_packet_header(bs, fcode_max - 1, &quant, &fcode_forward, &fcode_backward, (int*)&intra_dc_threshold);
- x = bound % mb_width;
- y = bound / mb_width;
- //reset predicted macroblocks
- p_fmv = p_bmv = zeromv;
- }
-
- mv = mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv;
- mb->quant = quant;
-
- /*
- * skip if the co-located P_VOP macroblock is not coded
- * if not codec in co-located S_VOP macroblock is _not_
- * automatically skipped
- */
-
- if(last_mb->mode == MODE_NOT_CODED){
- mb->cbp = 0;
- mb->mode = MODE_FORWARD;
- DecodeInterMacroBlock(mb, x, y, mb->cbp, bs, 0, 0, 1);
- continue;
- }
-
- if(!bs->GetBit()){
- //modb=='0'
- const byte modb2 = bs->GetBit();
-
- mb->mode = get_mbtype(bs);
-
- if (!modb2) /* modb=='00' */
- mb->cbp = bs->GetBits(6);
- else
- mb->cbp = 0;
-
- if (mb->mode && mb->cbp) {
- quant += get_dbquant(bs);
- if (quant > 31)
- quant = 31;
- else if (quant < 1)
- quant = 1;
- }
- mb->quant = quant;
-
- if(interlacing){
- if (mb->cbp) {
- mb->field_dct = bs->GetBit();
- DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct);
- }
-
- if (mb->mode) {
- mb->field_pred = bs->GetBit();
- DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred);
-
- if (mb->field_pred) {
- mb->field_for_top = bs->GetBit();
- DPRINTF(XVID_DEBUG_MB,"decp: field_for_top: %i\n", mb->field_for_top);
- mb->field_for_bot = bs->GetBit();
- DPRINTF(XVID_DEBUG_MB,"decp: field_for_bot: %i\n", mb->field_for_bot);
- }
- }
- }
-
- }else{
- mb->mode = MODE_DIRECT_NONE_MV;
- mb->cbp = 0;
- }
-
- switch(mb->mode){
- case MODE_DIRECT:
- get_b_motion_vector(bs, &mv, 1, zeromv);
- //flow...
- case MODE_DIRECT_NONE_MV:
- for(i=0; i<4; i++){
- mb->mvs[i].x = (int)((int(TRB) * last_mb->mvs[i].x) / (int)TRD + mv.x);
- mb->b_mvs[i].x = (int) ((mv.x == 0) ?
- (int(TRB - TRD) * last_mb->mvs[i].x) / (int)TRD :
- mb->mvs[i].x - last_mb->mvs[i].x);
- mb->mvs[i].y = (int) ((int(TRB) * last_mb->mvs[i].y) / (int)TRD + mv.y);
- mb->b_mvs[i].y = (int) ((mv.y == 0) ?
- (int(TRB - TRD) * last_mb->mvs[i].y) / int(TRD) :
- int(mb->mvs[i].y - last_mb->mvs[i].y));
- }
- BFrameInterpolateMBInter(refn[1], refn[0], mb, x, y, bs, 1);
- break;
-
- case MODE_INTERPOLATE:
- get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, p_fmv);
- p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0];
-
- get_b_motion_vector(bs, &mb->b_mvs[0], fcode_backward, p_bmv);
- p_bmv = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = mb->b_mvs[0];
-
- BFrameInterpolateMBInter(refn[1], refn[0], mb, x, y, bs, 0);
- break;
-
- case MODE_BACKWARD:
- get_b_motion_vector(bs, &mb->mvs[0], fcode_backward, p_bmv);
- p_bmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0];
-
- DecodeInterMacroBlock(mb, x, y, mb->cbp, bs, 0, 0, 0);
- break;
-
- case MODE_FORWARD:
- get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, p_fmv);
- p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0];
-
- DecodeInterMacroBlock(mb, x, y, mb->cbp, bs, 0, 0, 1);
- break;
-
- default:
- DPRINTF(XVID_DEBUG_ERROR,"Not supported B-frame mb_type = %i\n", mb->mode);
- }
- }
- }
- PROF_E(PROF_FRM_B);
-}
-
-//----------------------------
-/* perform post processing if necessary, and output the image */
-/*
-void S_decoder::Output(IMAGE *img, xvid_dec_frame_t *frame, xvid_dec_stats_t *stats, int coding_type){
-
- //image_output(img, width, height, edged_width, (byte**)frame->output.plane, (unsigned int*)frame->output.stride, frame->output.csp, interlacing);
- yv12_to_bgr((byte*)frame->output.plane, frame->output.stride, img->y, img->u, img->v, edged_width, edged_width/2, width, height, false);
-
- if(stats){
- stats->type = coding2type(coding_type);
- stats->data.vop.time_base = (int)time_base;
- stats->data.vop.time_increment = 0; //XXX: todo
- }
-}
-*/
-
-//----------------------------
-
-int S_decoder::Decode(xvid_dec_frame_t *frame, xvid_dec_stats_t *stats){
-
- PROF_S(PROF_DECODE);
-
- Bitstream bs;
- bool rounding;
- bool reduced_resolution;
- dword quant;
- dword fcode_forward;
- dword fcode_backward;
- dword intra_dc_threshold;
- WARPPOINTS gmc_warp;
- int coding_type;
-
- frame->img_out = NULL;
-
- if(XVID_VERSION_MAJOR(frame->version) != 1 || (stats && XVID_VERSION_MAJOR(stats->version) != 1)){ //v1.x.x
- PROF_E(PROF_DECODE);
- return XVID_ERR_VERSION;
- }
-
- //start_global_timer();
-
- low_delay_default = (frame->general & XVID_LOWDELAY);
- if((frame->general & XVID_DISCONTINUITY))
- frames = 0;
- /*
-#ifdef XVID_CSP_SLICE
- out_frm = (frame->output.csp == XVID_CSP_SLICE) ? &frame->output : NULL;
-#endif
- */
-
- if(frame->length < 0){
- //decoder flush
- int ret;
- //if not decoding "low_delay/packed", and this isn't low_delay and
- // we have a reference frame, then outout the reference frame
- if(!(low_delay_default && packed_mode) && !low_delay && frames>0){
- //Output(&refn[0], frame, stats, last_coding_type);
- frame->img_out = &refn[0];
- frames = 0;
- ret = 0;
- } else {
- if (stats) stats->type = XVID_TYPE_NOTHING;
- ret = XVID_ERR_END;
- }
- //stop_global_timer();
- PROF_E(PROF_DECODE);
- return ret;
- }
-
- bs.Init(frame->bitstream, frame->length);
-
- //XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's
- if(low_delay_default && frame->length == 1 && bs.ShowBits(8) == 0x7f){
- //image_output(&refn[0], width, height, edged_width, (byte**)frame->output.plane, (unsigned int*)frame->output.stride, frame->output.csp, interlacing);
- if(stats)
- stats->type = XVID_TYPE_NOTHING;
- PROF_E(PROF_DECODE);
- return 1; //one byte consumed
- }
-
- bool success = false;
- bool output = false;
- bool seen_something = false;
-
- /*
- cur.Clear(width, height, edged_width, 0, 0, 0);
- refn[0].Clear(width, height, edged_width, 0, 0, 0);
- refn[1].Clear(width, height, edged_width, 0, 0, 0);
- */
-
-repeat:
-
- coding_type = BitstreamReadHeaders(&bs, rounding, &reduced_resolution, &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp);
-
- //DPRINTF(XVID_DEBUG_HEADER, "coding_type=%i, packed=%i, time=%lli, time_pp=%i, time_bp=%i\n", coding_type, packed_mode, time, time_pp, time_bp);
-
- if(coding_type == -1){
- //nothing
- if(success)
- goto done;
- if(stats)
- stats->type = XVID_TYPE_NOTHING;
- PROF_E(PROF_DECODE);
- return bs.Pos()/8;
- }
-
- if(coding_type == -2 || coding_type == -3){
- //vol and/or resize
-
- if(coding_type == -3)
- Resize();
- /*
- if(stats){
- stats->type = XVID_TYPE_VOL;
- stats->data.vol.general = 0;
- //XXX: if (interlacing) stats->data.vol.general |= ++INTERLACING;
- stats->data.vol.width = width;
- stats->data.vol.height = height;
- stats->data.vol.par = aspect_ratio;
- stats->data.vol.par_width = par_width;
- stats->data.vol.par_height = par_height;
- return bs.Pos()/8; //number of bytes consumed
- }
- */
- goto repeat;
- }
- p_bmv.x = p_bmv.y = p_fmv.y = p_fmv.y = 0;
-
- //packed_mode: special-N_VOP treament
- if(packed_mode && coding_type == N_VOP){
- if(low_delay_default && frames > 0){
- //Output(&refn[0], frame, stats, last_coding_type);
- frame->img_out = &refn[0];
- output = true;
- }
- //ignore otherwise
- }else
- if(coding_type != B_VOP){
- switch(coding_type){
- case I_VOP:
- PROF_S(PROF_FRM_I);
- I_Frame(&bs, reduced_resolution, quant, intra_dc_threshold);
- PROF_E(PROF_FRM_I);
- break;
- case P_VOP:
- P_Frame(&bs, rounding, reduced_resolution, quant, fcode_forward, intra_dc_threshold, NULL);
- break;
- case S_VOP:
- //not called (or very rare)
- P_Frame(&bs, rounding, reduced_resolution, quant, fcode_forward, intra_dc_threshold, &gmc_warp);
- break;
- case N_VOP:
- //XXX: not_coded vops are not used for forward prediction we should not swap(last_mbs,mbs)
- cur.Copy(&refn[0], edged_width, height);
- break;
- }
- if(reduced_resolution)
- cur.deblock_rrv(edged_width, mbs, (width + 31) / 32, (height + 31) / 32, mb_width, 16, 0);
-
- //note: for packed_mode, output is performed when the special-N_VOP is decoded
- if(!(low_delay_default && packed_mode)){
- if(low_delay){
- //Output(&cur, frame, stats, coding_type);
- frame->img_out = &cur;
- output = true;
- }else
- if(frames > 0){
- //is the reference frame valid?
- // output the reference frame
- //Output(&refn[0], frame, stats, last_coding_type);
- frame->img_out = &refn[1];
- output = true;
- }
- }
- refn[0].Swap(&refn[1]);
- cur.Swap(&refn[0]);
- Swap(mbs, last_mbs);
- last_reduced_resolution = reduced_resolution;
- last_coding_type = coding_type;
-
- frames++;
- seen_something = true;
- }else{
- //B_VOP
- if(low_delay){
- DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n");
- low_delay = true;
- }
-
- if(frames < 2){
- /* attemping to decode a bvop without atleast 2 reference frames */
- cur.Print(edged_width, height, 16, 16, "broken b-frame, mising ref frames");
- }else
- if(time_pp <= time_bp){
- //this occurs when dx50_bvop_compatibility==0 sequences are decoded in vfw
- cur.Print(edged_width, height, 16, 16, "broken b-frame");
- }else{
- B_Frame(&bs, quant, fcode_forward, fcode_backward);
- }
- //Output(&cur, frame, stats, coding_type);
- frame->img_out = &cur;
- output = true;
- frames++;
- }
-
- bs.ByteAlign();
-
- //low_delay_default mode: repeat in packed_mode
- if(low_delay_default && packed_mode && !output && !success){
- success = true;
- goto repeat;
- }
-done:
- //low_delay_default mode: if we've gotten here without outputting anything,
- // then output the recently decoded frame, or print an error message
- if(low_delay_default && !output){
- if(packed_mode && seen_something){
- //output the recently decoded frame
- //Output(&refn[0], frame, stats, last_coding_type);
- frame->img_out = &refn[0];
- }else{
- cur.Clear(width, height, edged_width, 0, 128, 128);
- cur.Print(edged_width, height, 16, 16, "warning: nothing to output");
- cur.Print(edged_width, height, 16, 64, "bframe decoder lag");
-
- //Output(&cur, frame, stats, P_VOP);
- frame->img_out = &cur;
- if(stats)
- stats->type = XVID_TYPE_NOTHING;
- }
- }
-
- PROF_E(PROF_DECODE);
- //number of bytes consumed
- return bs.Pos() / 8;
-}
-
-//----------------------------
-
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Decoder related header -
- *
- * Copyright(C) 2002-2003 Peter Ross <pross@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: decoder.h,v 1.1.1.1 2005-07-13 14:36:13 jeanlf Exp $
- *
- ****************************************************************************/
-
-#ifndef _DECODER_H_
-#define _DECODER_H_
-
-#include "xvid.h"
-#include "portab.h"
-#include "global.h"
-#include "image.h"
-#include "vlc_codes.h"
-#include "Interpolate8x8.h"
-
-/*****************************************************************************
- * Structures
- ****************************************************************************/
-
-/* complexity estimation toggles */
-struct ESTIMATION{
- int method;
-
- int opaque;
- int transparent;
- int intra_cae;
- int inter_cae;
- int no_update;
- int upsampling;
-
- int intra_blocks;
- int inter_blocks;
- int inter4v_blocks;
- int gmc_blocks;
- int not_coded_blocks;
-
- int dct_coefs;
- int dct_lines;
- int vlc_symbols;
- int vlc_bits;
-
- int apm;
- int npm;
- int interpolate_mc_q;
- int forw_back_mc_q;
- int halfpel2;
- int halfpel4;
-
- int sadct;
- int quarterpel;
-
- ESTIMATION(){
- MemSet(this, 0, sizeof(ESTIMATION));
- }
-};
-
-//----------------------------
-
-struct S_decoder{
-private:
-#ifdef PROFILE
- mutable C_profiler &prof;
-#endif
-
- int Resize();
-
-//----------------------------
- void SetEdges(IMAGE &img) const;
-
-//----------------------------
- void I_Frame(Bitstream * bs, bool reduced_resolution, int quant, int intra_dc_threshold);
- void P_Frame(Bitstream * bs, int rounding, bool reduced_resolution, int quant, int fcode, int intra_dc_threshold, const WARPPOINTS *const gmc_warp);
- void MBIntra(MACROBLOCK *pMB, dword x_pos, dword y_pos, dword acpred_flag, dword cbp,
- Bitstream *bs, dword quant, dword intra_dc_threshold, dword bound, bool reduced_resolution);
-
- void mb_decode(const dword cbp, Bitstream * bs, byte * pY_Cur, byte * pU_Cur, byte * pV_Cur, bool reduced_resolution, const MACROBLOCK * pMB);
-
- void DecodeInterMacroBlock(const MACROBLOCK *pMB, dword x_pos, dword y_pos, dword cbp, Bitstream *bs,
- bool rounding, bool reduced_resolution, int ref);
-
- void mbgmc(MACROBLOCK *pMB, dword x_pos, dword y_pos, dword fcode, dword cbp, Bitstream *bs, bool rounding);
-
- void BFrameInterpolateMBInter(const IMAGE &forward, const IMAGE &backward, const MACROBLOCK *pMB, dword x_pos, dword y_pos, Bitstream *bs, int direct);
-
- void B_Frame(Bitstream * bs, int quant, int fcode_forward, int fcode_backward);
- void GetMotionVector(Bitstream *bs, int x, int y, int k, VECTOR *ret_mv, int fcode, int bound);
- //void Output(IMAGE *img, xvid_dec_frame_t *frame, xvid_dec_stats_t *stats, int coding_type);
-
- int read_video_packet_header(Bitstream *bs, const int addbits, int *quant, int *fcode_forward, int *fcode_backward, int *intra_dc_threshold);
- void read_vol_complexity_estimation_header(Bitstream * bs);
- int BitstreamReadHeaders(Bitstream * bs, bool &rounding, bool *reduced_resolution, dword *quant, dword *fcode_forward,
- dword *fcode_backward, dword *intra_dc_threshold, WARPPOINTS *gmc_warp);
- void read_vop_complexity_estimation_header(Bitstream * bs, int coding_type);
-
- int get_coeff(Bitstream *bs, int *run, int *last, int intra, int short_video_header);
- void get_intra_block(Bitstream * bs, int *block, int direction, int coeff);
- void get_inter_block(Bitstream * bs, int *block, int direction);
-
- void idct_int32_init();
- void InverseDiscreteCosineTransform(int *block) const;
-
- friend int decoder_create(xvid_dec_create_t *create);
-
- int Init(xvid_dec_create_t *create);
-
-#ifdef PROFILE
- void interpolate8x8_quarterpel(byte *cur, byte *refn, byte *refh, byte *refv, byte *refhv, dword x, dword y, int dx, int dy, dword stride, bool rounding){
- ::interpolate8x8_quarterpel(cur, refn, refh, refv, refhv, x, y, dx, dy, stride, rounding);
- }
- void interpolate16x16_switch(byte *cur, const byte *refn, dword x, dword y, int dx, int dy, dword stride, bool rounding){
- interpolate8x8_switch(cur, refn, x, y, dx, dy, stride, rounding);
- interpolate8x8_switch(cur, refn, x+8, y, dx, dy, stride, rounding);
- interpolate8x8_switch(cur, refn, x, y+8, dx, dy, stride, rounding);
- interpolate8x8_switch(cur, refn, x+8, y+8, dx, dy, stride, rounding);
- }
- void interpolate8x8_switch(byte *cur, const byte *refn, dword x, dword y, int dx, int dy, dword stride, bool rounding){
- const byte *src = refn + ((y + (dy>>1)) * stride + x + (dx>>1));
- byte *dst = cur + (y * stride + x);
-
- int code = ((dx & 1) << 1) + (dy & 1);
- //PROF_S(PROF_4+MIN(3, code));
- switch(code){
- case 0:
- transfer8x8_copy(dst, src, stride);
- break;
- case 1:
- interpolate8x8_halfpel_v(dst, src, stride, rounding);
- break;
- case 2:
- interpolate8x8_halfpel_h(dst, src, stride, rounding);
- break;
- default:
- interpolate8x8_halfpel_hv(dst, src, stride, rounding);
- break;
- }
- //PROF_E(PROF_4+MIN(3, code));
- }
-#endif
-public:
- S_decoder(xvid_dec_create_t *create);
- ~S_decoder();
- //vol bitstream
- int time_inc_resolution;
- int fixed_time_inc;
- dword time_inc_bits;
-
- dword shape;
- dword quant_bits;
- dword quant_type;
- dword *mpeg_quant_matrices;
- int quarterpel;
- int complexity_estimation_disable;
- ESTIMATION estimation;
-
- dword top_field_first;
- dword alternate_vertical_scan;
-
- int aspect_ratio;
- int par_width;
- int par_height;
-
- int sprite_enable;
- int sprite_warping_points;
- int sprite_warping_accuracy;
- int sprite_brightness_change;
-
- bool interlacing;
- bool newpred_enable;
- bool reduced_resolution_enable;
-
- /* The bitstream version if it's a XviD stream */
- int bs_version;
-
- /* image */
-
- dword width;
- dword height;
- dword edged_width;
- dword edged_height;
-
- IMAGE cur;
- IMAGE refn[2]; /* 0 -- last I or P VOP */
-
- /* 1 -- first I or P */
- IMAGE tmp; /* bframe interpolation, and post processing tmp buffer */
- IMAGE qtmp; /* quarter pel tmp buffer */
-
- /* macroblock */
-
- dword mb_width;
- dword mb_height;
- MACROBLOCK *mbs;
-
- //for B-frame & low_delay==0
- // XXX: should move frame based stuff into a DECODER_FRAMEINFO struct
- MACROBLOCK *last_mbs; /* last MB */
- int last_coding_type; /* last coding type value */
- int frames; /* total frame number */
- VECTOR p_fmv, p_bmv; /* pred forward & backward motion vector */
- int64_t time; /* for record time */
- int64_t time_base;
- int64_t last_time_base;
- int64_t last_non_b_time;
- dword time_pp;
- dword time_bp;
- bool fixed_dimensions;
- bool scalability;
- bool low_delay; //low_delay flage (1 means no B_VOP)
- bool low_delay_default; //default value for low_delay flag
- bool last_reduced_resolution; //last reduced_resolution value
- bool packed_mode; //bframes packed bitstream? (1 = yes)
-
- //for GMC: central place for all parameters
-
- IMAGE gmc; /* gmc tmp buffer, remove for blockbased compensation */
- GMC_DATA gmc_data;
- NEW_GMC_DATA new_gmc_data;
-
- /*
-#ifdef XVID_CSP_SLICE
- xvid_image_t* out_frm; //This is used for slice rendering
-#endif
- */
-
- struct REVERSE_EVENT{
- byte len;
- EVENT event;
- };
- //decoding tables
- REVERSE_EVENT DCT3D[2][4096];
- VLC coeff_VLC[2][2][64][64];
-
- typedef int t_clip_val;
- t_clip_val iclip[1024]; //clipping table
-
- void init_vlc_tables();
- int Decode(xvid_dec_frame_t * frame, xvid_dec_stats_t * stats);
-};
-
-/*****************************************************************************
- * Decoder prototypes
- ****************************************************************************/
-
-void init_decoder(dword cpu_flags);
-
-int decoder_create(xvid_dec_create_t * param);
-
-
-#endif
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Font rendering to frame buffer functions -
- *
- * Copyright(C) 2002-2003 Peter Ross <pross@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: font.cpp,v 1.1.1.1 2005-07-13 14:36:13 jeanlf Exp $
- *
- ****************************************************************************/
-
-#include "image.h"
-
-#define FONT_WIDTH 4
-#define FONT_HEIGHT 6
-
-//----------------------------
-
-static const char ascii33[33][FONT_WIDTH*FONT_HEIGHT] = {
-
- /* ! */
- {0,0,1,0,
- 0,0,1,0,
- 0,0,1,0,
- 0,0,1,0,
- 0,0,0,0,
- 0,0,1,0},
-
- /* " */
- {0,1,0,1,
- 0,1,0,1,
- 0,0,0,0,
- 0,0,0,0,
- 0,0,0,0,
- 0,0,0,0},
-
- /* # */
- {0,1,1,0,
- 1,1,1,1,
- 0,1,1,0,
- 0,1,1,0,
- 1,1,1,1,
- 0,1,1,0},
-
- /* $ */
- {0,1,1,0,
- 1,0,1,1,
- 1,1,1,0,
- 0,1,1,1,
- 1,1,0,1,
- 0,1,1,0},
-
- /* % */
- {1,1,0,1,
- 1,0,0,1,
- 0,0,1,0,
- 0,1,0,0,
- 1,0,0,1,
- 1,0,1,1},
-
- /* & */
- {0,1,1,0,
- 1,0,0,0,
- 0,1,0,1,
- 1,0,1,0,
- 1,0,1,0,
- 0,1,0,1},
-
- /* ' */
- {0,0,1,0,
- 0,0,1,0,
- 0,0,0,0,
- 0,0,0,0,
- 0,0,0,0,
- 0,0,0,0},
-
- /* ( */
- {0,0,1,0,
- 0,1,0,0,
- 0,1,0,0,
- 0,1,0,0,
- 0,1,0,0,
- 0,0,1,0},
-
- /* ) */
- {0,1,0,0,
- 0,0,1,0,
- 0,0,1,0,
- 0,0,1,0,
- 0,0,1,0,
- 0,1,0,0},
-
- /* * */
- {0,0,0,0,
- 1,0,0,1,
- 0,1,1,0,
- 1,1,1,1,
- 0,1,1,0,
- 1,0,0,1},
-
- /* + */
- {0,0,0,0,
- 0,0,1,0,
- 0,0,1,0,
- 0,1,1,1,
- 0,0,1,0,
- 0,0,1,0},
-
- /* , */
- {0,0,0,0,
- 0,0,0,0,
- 0,0,0,0,
- 0,0,0,0,
- 0,1,1,0,
- 0,0,1,0},
-
- /* - */
- {0,0,0,0,
- 0,0,0,0,
- 0,0,0,0,
- 1,1,1,1,
- 0,0,0,0,
- 0,0,0,0},
-
- /* . */
- {0,0,0,0,
- 0,0,0,0,
- 0,0,0,0,
- 0,0,0,0,
- 0,1,1,0,
- 0,1,1,0},
-
- /* / */
- {0,0,0,1,
- 0,0,0,1,
- 0,0,1,0,
- 0,1,0,0,
- 1,0,0,0,
- 1,0,0,0},
-
- /* 0 */
- {0,1,1,0,
- 1,0,0,1,
- 1,0,1,1,
- 1,1,0,1,
- 1,0,0,1,
- 0,1,1,0},
-
- /* 1 */
- {0,0,1,0,
- 0,0,1,0,
- 0,0,1,0,
- 0,0,1,0,
- 0,0,1,0,
- 0,0,1,0},
-
- /* 2 */
- {0,1,1,0,
- 1,0,0,1,
- 0,0,1,0,
- 0,1,0,0,
- 1,0,0,0,
- 1,1,1,1},
-
- /* 3 */
- {0,1,1,0,
- 1,0,0,1,
- 0,0,1,0,
- 0,0,0,1,
- 1,0,0,1,
- 0,1,1,0},
-
- /* 4 */
- {0,0,1,0,
- 0,1,1,0,
- 1,0,1,0,
- 1,1,1,1,
- 0,0,1,0,
- 0,0,1,0},
-
- /* 5 */
- {1,1,1,1,
- 1,0,0,0,
- 1,1,1,0,
- 0,0,0,1,
- 1,0,0,1,
- 0,1,1,0},
-
- /* 6 */
- {0,1,1,1,
- 1,0,0,0,
- 1,1,1,0,
- 1,0,0,1,
- 1,0,0,1,
- 0,1,1,0},
-
- /* 7 */
- {1,1,1,0,
- 0,0,0,1,
- 0,0,0,1,
- 0,0,1,0,
- 0,0,1,0,
- 0,0,1,0},
-
- /* 8 */
- {0,1,1,0,
- 1,0,0,1,
- 0,1,1,0,
- 1,0,0,1,
- 1,0,0,1,
- 0,1,1,0},
-
- /* 9 */
- {0,1,1,0,
- 1,0,0,1,
- 1,0,0,1,
- 0,1,1,1,
- 0,0,0,1,
- 1,1,1,0},
-
- /* : */
- {0,0,0,0,
- 0,0,0,0,
- 0,0,1,0,
- 0,0,0,0,
- 0,0,1,0,
- 0,0,0,0},
-
- /* ; */
- {0,0,0,0,
- 0,0,1,0,
- 0,0,0,0,
- 0,0,0,0,
- 0,1,1,0,
- 0,0,1,0},
-
- /* < */
- {0,0,0,1,
- 0,0,1,0,
- 0,1,0,0,
- 0,1,0,0,
- 0,0,1,0,
- 0,0,0,1},
-
- /* = */
- {0,0,0,0,
- 1,1,1,1,
- 0,0,0,0,
- 0,0,0,0,
- 1,1,1,1,
- 0,0,0,0},
-
- /* > */
- {0,1,0,0,
- 0,0,1,0,
- 0,0,0,1,
- 0,0,0,1,
- 0,0,1,0,
- 0,1,0,0},
-
- /* ? */
- {0,1,1,0,
- 1,0,0,1,
- 0,0,1,0,
- 0,0,1,0,
- 0,0,0,0,
- 0,0,1,0},
-
- /* @ */
- {0,1,1,0,
- 1,0,0,1,
- 1,0,1,1,
- 1,0,1,1,
- 1,0,0,0,
- 0,1,1,0},
-
-};
-
-
-static const char ascii65[26][FONT_WIDTH*FONT_HEIGHT] = {
- /* A */
- {0,1,1,0,
- 1,0,0,1,
- 1,0,0,1,
- 1,1,1,1,
- 1,0,0,1,
- 1,0,0,1},
-
- /* B */
- {1,1,1,0,
- 1,0,0,1,
- 1,1,1,0,
- 1,0,0,1,
- 1,0,0,1,
- 1,1,1,0},
-
- /* C */
- {0,1,1,0,
- 1,0,0,1,
- 1,0,0,0,
- 1,0,0,0,
- 1,0,0,1,
- 0,1,1,0},
-
- /* D */
- {1,1,0,0,
- 1,0,1,0,
- 1,0,0,1,
- 1,0,0,1,
- 1,0,1,0,
- 1,1,0,0},
-
- /* E */
- {1,1,1,1,
- 1,0,0,0,
- 1,1,1,0,
- 1,0,0,0,
- 1,0,0,0,
- 1,1,1,1},
-
- /* F */
- {1,1,1,1,
- 1,0,0,0,
- 1,1,1,0,
- 1,0,0,0,
- 1,0,0,0,
- 1,0,0,0},
-
- /* G */
- {0,1,1,1,
- 1,0,0,0,
- 1,0,1,1,
- 1,0,0,1,
- 1,0,0,1,
- 0,1,1,0},
-
- /* H */
- {1,0,0,1,
- 1,0,0,1,
- 1,1,1,1,
- 1,0,0,1,
- 1,0,0,1,
- 1,0,0,1},
-
- /* I */
- {0,1,1,1,
- 0,0,1,0,
- 0,0,1,0,
- 0,0,1,0,
- 0,0,1,0,
- 0,1,1,1},
-
- /* J */
- {0,1,1,1,
- 0,0,1,0,
- 0,0,1,0,
- 0,0,1,0,
- 1,0,1,0,
- 0,1,0,0},
-
- /* K */
- {1,0,0,1,
- 1,0,0,1,
- 1,1,1,0,
- 1,0,0,1,
- 1,0,0,1,
- 1,0,0,1},
-
- /* L */
- {1,0,0,0,
- 1,0,0,0,
- 1,0,0,0,
- 1,0,0,0,
- 1,0,0,0,
- 1,1,1,1},
-
- /* M */
- {1,0,0,1,
- 1,1,1,1,
- 1,1,1,1,
- 1,0,0,1,
- 1,0,0,1,
- 1,0,0,1},
-
- /* N */
- {1,0,0,1,
- 1,1,0,1,
- 1,1,0,1,
- 1,0,1,1,
- 1,0,1,1,
- 1,0,0,1},
-
- /* 0 */
- {0,1,1,0,
- 1,0,0,1,
- 1,0,0,1,
- 1,0,0,1,
- 1,0,0,1,
- 0,1,1,0},
-
- /* P */
- {1,1,1,0,
- 1,0,0,1,
- 1,1,1,0,
- 1,0,0,0,
- 1,0,0,0,
- 1,0,0,0},
-
- /* Q */
- {0,1,1,0,
- 1,0,0,1,
- 1,0,0,1,
- 1,0,0,1,
- 1,0,1,0,
- 0,1,0,1},
-
-
- /* R */
- {1,1,1,0,
- 1,0,0,1,
- 1,1,1,0,
- 1,0,0,1,
- 1,0,0,1,
- 1,0,0,1},
-
- /* S */
- {0,1,1,0,
- 1,0,0,1,
- 0,1,0,0,
- 0,0,1,0,
- 1,0,0,1,
- 0,1,1,0},
-
- /* T */
- {0,1,1,1,
- 0,0,1,0,
- 0,0,1,0,
- 0,0,1,0,
- 0,0,1,0,
- 0,0,1,0},
-
- /* U */
- {1,0,0,1,
- 1,0,0,1,
- 1,0,0,1,
- 1,0,0,1,
- 1,0,0,1,
- 1,1,1,1},
-
- /* V */
- {1,0,0,1,
- 1,0,0,1,
- 1,0,0,1,
- 0,1,1,0,
- 0,1,1,0,
- 0,1,1,0},
-
- /* W */
- {1,0,0,1,
- 1,0,0,1,
- 1,0,0,1,
- 1,1,1,1,
- 1,1,1,1,
- 1,0,0,1},
-
- /* X */
- {1,0,0,1,
- 1,0,0,1,
- 0,1,1,0,
- 1,0,0,1,
- 1,0,0,1,
- 1,0,0,1},
-
- /* Y */
- {1,0,0,1,
- 1,0,0,1,
- 0,1,0,0,
- 0,0,1,0,
- 0,1,0,0,
- 1,0,0,0},
-
- /* Z */
- {1,1,1,1,
- 0,0,0,1,
- 0,0,1,0,
- 0,1,0,0,
- 1,0,0,0,
- 1,1,1,1},
-
-};
-
-
-
-static const char ascii91[6][FONT_WIDTH*FONT_HEIGHT] = {
- /* [ */
- {0,1,1,0,
- 0,1,0,0,
- 0,1,0,0,
- 0,1,0,0,
- 0,1,0,0,
- 0,1,1,0},
-
- /* '\' */
- {1,0,0,0,
- 1,0,0,0,
- 0,1,0,0,
- 0,0,1,0,
- 0,0,0,1,
- 0,0,0,1},
-
- /* ] */
- {0,1,1,0,
- 0,0,1,0,
- 0,0,1,0,
- 0,0,1,0,
- 0,0,1,0,
- 0,1,1,0},
-
- /* ^ */
- {0,1,0,1,
- 0,0,0,0,
- 0,0,0,0,
- 0,0,0,0,
- 0,0,0,0,
- 0,0,0,0},
-
- /* _ */
- {0,0,0,0,
- 0,0,0,0,
- 0,0,0,0,
- 0,0,0,0,
- 0,0,0,0,
- 1,1,1,1},
-
- /* ` */
- {0,1,0,0,
- 0,0,1,0,
- 0,0,0,0,
- 0,0,0,0,
- 0,0,0,0,
- 0,0,0,0}
-};
-
-//----------------------------
-
-#define FONT_ZOOM 2
-
-void IMAGE::draw_num(const int stride, const int height, const char * font, const int x, const int y){
-
- for(int j = 0; j < FONT_ZOOM * FONT_HEIGHT && y+j < height; j++){
- for(int i = 0; i < FONT_ZOOM * FONT_WIDTH && x+i < stride; i++){
- if(font[(j/FONT_ZOOM)*FONT_WIDTH + (i/FONT_ZOOM)]){
- int offset = (y+j)*stride + (x+i);
- int offset2 =((y+j)/2)*(stride/2) + ((x+i)/2);
- IMAGE::y[offset] = 255;
- IMAGE::u[offset2] = 127;
- IMAGE::v[offset2] = 127;
- }
- }
- }
-}
-
-//----------------------------
-
-void IMAGE::Print(int edged_width, int height, int x, int y, const char *buf){
-
- int i;
-
- for(i = 0; buf[i]; i++) {
- const char * font;
-
- if (buf[i] >= '!' && buf[i] <= '@')
- font = ascii33[buf[i]-'!'];
- else if (buf[i] >= 'A' && buf[i] <= 'Z')
- font = ascii65[buf[i]-'A'];
- else if (buf[i] >= '[' && buf[i] <= '`')
- font = ascii91[buf[i]-'['];
- else if (buf[i] >= 'a' && buf[i] <= 'z')
- font = ascii65[buf[i]-'a'];
- else
- continue;
- draw_num(edged_width, height, font, x + i*FONT_ZOOM*(FONT_WIDTH+1), y);
- }
-}
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Global definitions -
- *
- * Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: global.h,v 1.1.1.1 2005-07-13 14:36:14 jeanlf Exp $
- *
- ****************************************************************************/
-
-#ifndef _GLOBAL_H_
-#define _GLOBAL_H_
-
-#include "xvid.h"
-#include "portab.h"
-
-//----------------------------
-
-void MemSet(void *dst, byte c, dword len);
-int MemCmp(const void *mem1, const void *mem2, dword len);
-void MemCpy(void *dst, const void *src, dword len);
-
-template<class T>
-inline void Swap(T &l, T &r){ T tmp = r; r = l; l = tmp; }
-
-#ifndef __SYMBIAN32__
-
-enum TLeave{ ELeave };
-void *operator new(size_t sz, TLeave);
-inline void operator delete(void *vp, TLeave){ operator delete(vp); }
-
-#endif
-
-//----------------------------
-// Fatal error - display message, and exit program immediately.
-void Fatal(const char *msg, dword code = 0);
-
-//----------------------------
-#ifndef assert
-
-#ifdef NDEBUG
-#define assert(exp) ((void)0)
-#else
-
-#define assert(exp) if(!(exp)){\
- Fatal(#exp, __LINE__); }
-
-#endif
-#endif
-
-//----------------------------
-/* --- macroblock modes --- */
-
-#define MODE_INTER 0
-#define MODE_INTER_Q 1
-#define MODE_INTER4V 2
-#define MODE_INTRA 3
-#define MODE_INTRA_Q 4
-#define MODE_NOT_CODED 16
-#define MODE_NOT_CODED_GMC 17
-
-/* --- bframe specific --- */
-
-#define MODE_DIRECT 0
-#define MODE_INTERPOLATE 1
-#define MODE_BACKWARD 2
-#define MODE_FORWARD 3
-#define MODE_DIRECT_NONE_MV 4
-#define MODE_DIRECT_NO4V 5
-
-
-/*
- * vop coding types
- * intra, prediction, backward, sprite, not_coded
- */
-#define I_VOP 0
-#define P_VOP 1
-#define B_VOP 2
-#define S_VOP 3
-#define N_VOP 4
-
-//----------------------------
-// convert mpeg-4 coding type i/p/b/s_VOP to XVID_TYPE_xxx
-inline int coding2type(int coding_type){
- return coding_type + 1;
-}
-
-//----------------------------
-// convert XVID_TYPE_xxx to bitstream coding type i/p/b/s_VOP
-inline int type2coding(int xvid_type){
- return xvid_type - 1;
-}
-
-
-typedef struct
-{
- int x;
- int y;
-}
-VECTOR;
-
-
-
-typedef struct
-{
- VECTOR duv[3];
-}
-WARPPOINTS;
-
-/* save all warping parameters for GMC once and for all, instead of
- recalculating for every block. This is needed for encoding&decoding
- When switching to incremental calculations, this will get much shorter
-*/
-
-/* we don't include WARPPOINTS wp here, but in FRAMEINFO itself */
-
-struct GMC_DATA{
- int num_wp; /* [input]: 0=none, 1=translation, 2,3 = warping */
- /* a value of -1 means: "structure not initialized!" */
- int s; /* [input]: calc is done with 1/s pel resolution */
-
- int W;
- int H;
-
- int ss;
- int smask;
- int sigma;
-
- int r;
- int rho;
-
- int i0s;
- int j0s;
- int i1s;
- int j1s;
- int i2s;
- int j2s;
-
- int i1ss;
- int j1ss;
- int i2ss;
- int j2ss;
-
- int alpha;
- int beta;
- int Ws;
- int Hs;
-
- int dxF, dyF, dxG, dyG;
- int Fo, Go;
- int cFo, cGo;
-
- GMC_DATA(){
- MemSet(this, 0, sizeof(GMC_DATA));
- }
-};
-
-struct NEW_GMC_DATA{
- /* 0=none, 1=translation, 2,3 = warping
- * a value of -1 means: "structure not initialized!" */
- int num_wp;
-
- /* {0,1,2,3} => {1/2,1/4,1/8,1/16} pel */
- int accuracy;
-
- /* sprite size * 16 */
- int sW, sH;
-
- /* gradient, calculated from warp points */
- int dU[2], dV[2], Uo, Vo, Uco, Vco;
-
- void (*predict_16x16)(const NEW_GMC_DATA * const This,
- byte *dst, const byte *src,
- int dststride, int srcstride, int x, int y, int rounding);
- void (*predict_8x8) (const NEW_GMC_DATA * const This,
- byte *uDst, const byte *uSrc,
- byte *vDst, const byte *vSrc,
- int dststride, int srcstride, int x, int y, int rounding);
- void (*get_average_mv)(const NEW_GMC_DATA * const Dsp, VECTOR * const mv,
- int x, int y, int qpel);
-
- NEW_GMC_DATA(){
- MemSet(this, 0, sizeof(NEW_GMC_DATA));
- }
-};
-
-//----------------------------
-
-struct IMAGE: public C_xvid_image{
-private:
- void draw_num(const int stride, const int height, const char * font, const int x, const int y);
-public:
- void Print(int edged_width, int height, int x, int y, const char *fmt);
- void Swap(IMAGE *image2);
- void Copy(const IMAGE * image2, dword edged_width, dword height);
- void Clear(int width, int height, int edged_width, int y, int u, int v);
- void deblock_rrv(int edged_width, const struct MACROBLOCK * mbs, int mb_width, int mb_height, int mb_stride, int block, int flags);
-
- inline void Null(){
- y = u = v = 0;
- }
-};
-
-//----------------------------
-
-struct Bitstream{
- dword bufa;
- dword bufb;
- dword buf;
- dword pos; //bit position in currently cached 2 dwords (0-31)
- dword *tail;
- dword *start;
- dword length;
- dword initpos;
-
- void Init(const void *bitstream, dword length);
- dword ShowBits(dword bits);
- void get_matrix(byte *matrix);
- void Skip(dword bits);
-
-//----------------------------
-// number of bits to next byte alignment
- inline dword NumBitsToByteAlign() const{
- dword n = (32 - pos) & 7;
- return n == 0 ? 8 : n;
- }
- dword ShowBitsFromByteAlign(int bits);
-
-//----------------------------
-// move forward to the next byte boundary
- void ByteAlign(){
- dword remainder = pos & 7;
- if (remainder) {
- Skip(8 - remainder);
- }
- }
-
-//----------------------------
-// bitstream length (unit bits)
- inline dword Pos() const{
- return((dword)(8*((dword)tail - (dword)start) + pos - initpos));
- }
-
- dword GetBits(const dword n);
-
-//----------------------------
-// read single bit from bitstream
- inline dword GetBit(){
- return GetBits(1);
- }
-
-//----------------------------
-
- int GetMcbpcInter();
- int GetCbpy(int intra);
- int GetMoveVector(int fcode);
-
-//----------------------------
-
- int check_resync_marker(int addbits);
- int bs_get_spritetrajectory();
- int get_mcbpc_intra();
- int get_dc_dif(dword dc_size);
- int get_dc_size_lum();
- int get_dc_size_chrom();
-};
-
-
-#define MBPRED_SIZE 15
-
-
-struct MACROBLOCK{
- /* decoder/encoder */
- VECTOR mvs[4];
-
- int pred_values[6][MBPRED_SIZE];
- int acpred_directions[6];
-
- int mode;
- int quant; /* absolute quant */
-
- int field_dct;
- int field_pred;
- int field_for_top;
- int field_for_bot;
-
- /* encoder specific */
-
- VECTOR mv16;
- VECTOR pmvs[4];
- VECTOR qmvs[4]; /* mvs in quarter pixel resolution */
-
- int sad8[4]; /* SAD values for inter4v-VECTORs */
- int sad16; /* SAD value for inter-VECTOR */
-
- int dquant;
- int cbp;
-
- /* bframe stuff */
-
- VECTOR b_mvs[4];
- VECTOR b_qmvs[4];
-
- int mb_type;
-
- /*
- * stuff for block based ME (needed for Qpel ME)
- * backup of last integer ME vectors/sad
- */
-
- VECTOR amv; /* average motion vectors from GMC */
- int mcsel;
-
-/* This structure has become way to big! What to do? Split it up? */
-
-};
-
-//----------------------------
-
-inline dword log2bin(dword value){
- int n = 0;
-
- while (value) {
- value >>= 1;
- n++;
- }
- return n;
-}
-
-//----------------------------
-
-/* useful macros */
-
-#define MIN(X, Y) ((X)<(Y)?(X):(Y))
-#define MAX(X, Y) ((X)>(Y)?(X):(Y))
-#define ABS(X) (((X)>0)?(X):-(X))
-#define SIGN(X) (((X)>0)?1:-1)
-#define CLIP(X,AMIN,AMAX) (((X)<(AMIN)) ? (AMIN) : ((X)>(AMAX)) ? (AMAX) : (X))
-
-#endif /* _GLOBAL_H_ */
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - GMC interpolation module -
- *
- * Copyright(C) 2002-2003 Pascal Massimino <skal@planet-d.net>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: gmc.cpp,v 1.1.1.1 2005-07-13 14:36:14 jeanlf Exp $
- *
- ****************************************************************************/
-
-#include "portab.h"
-#include "global.h"
-#include "gmc.h"
-
-/* ************************************************************
- * Pts = 2 or 3
- *
- * Warning! *src is the global frame pointer (that is: adress
- * of pixel 0,0), not the macroblock one.
- * Conversely, *dst is the macroblock top-left adress.
- */
-static void Predict_16x16_C(const NEW_GMC_DATA * const This, byte *dst, const byte *src, int dststride, int srcstride, int x, int y, int rounding){
-
- const int W = This->sW;
- const int H = This->sH;
- const int rho = 3 - This->accuracy;
- const int Rounder = ( (1<<7) - (rounding<<(2*rho)) ) << 16;
-
- const int dUx = This->dU[0];
- const int dVx = This->dV[0];
- const int dUy = This->dU[1];
- const int dVy = This->dV[1];
-
- int Uo = This->Uo + 16*(dUy*y + dUx*x);
- int Vo = This->Vo + 16*(dVy*y + dVx*x);
-
- int i, j;
-
- dst += 16;
- for (j=16; j>0; --j) {
- int U = Uo, V = Vo;
- Uo += dUy; Vo += dVy;
- for (i=-16; i<0; ++i) {
- unsigned int f0, f1, ri = 16, rj = 16;
- int Offset;
- int u = ( U >> 16 ) << rho;
- int v = ( V >> 16 ) << rho;
-
- U += dUx; V += dVx;
-
- if (u > 0 && u <= W) { ri = MTab[u&15]; Offset = u>>4; }
- else if (u > W) Offset = W>>4;
- else Offset = -1;
-
- if (v > 0 && v <= H) { rj = MTab[v&15]; Offset += (v>>4)*srcstride; }
- else if (v > H) Offset += (H>>4)*srcstride;
- else Offset -= srcstride;
-
- f0 = src[Offset + 0];
- f0 |= src[Offset + 1] << 16;
- f1 = src[Offset + srcstride + 0];
- f1 |= src[Offset + srcstride + 1] << 16;
- f0 = (ri*f0)>>16;
- f1 = (ri*f1) & 0x0fff0000;
- f0 |= f1;
- f0 = (rj*f0 + Rounder) >> 24;
-
- dst[i] = (byte)f0;
- }
- dst += dststride;
- }
-}
-
-//----------------------------
-
-static void Predict_8x8_C(const NEW_GMC_DATA * const This, byte *uDst, const byte *uSrc,
- byte *vDst, const byte *vSrc, int dststride, int srcstride, int x, int y, int rounding){
-
- const int W = This->sW >> 1;
- const int H = This->sH >> 1;
- const int rho = 3-This->accuracy;
- const int Rounder = ( 128 - (rounding<<(2*rho)) ) << 16;
-
- const int dUx = This->dU[0];
- const int dVx = This->dV[0];
- const int dUy = This->dU[1];
- const int dVy = This->dV[1];
-
- int Uo = This->Uco + 8*(dUy*y + dUx*x);
- int Vo = This->Vco + 8*(dVy*y + dVx*x);
-
- int i, j;
-
- uDst += 8;
- vDst += 8;
- for (j=8; j>0; --j) {
- int U = Uo, V = Vo;
- Uo += dUy; Vo += dVy;
-
- for (i=-8; i<0; ++i) {
- int Offset;
- dword f0, f1, ri, rj;
- int u, v;
-
- u = ( U >> 16 ) << rho;
- v = ( V >> 16 ) << rho;
- U += dUx; V += dVx;
-
- if (u > 0 && u <= W) {
- ri = MTab[u&15];
- Offset = u>>4;
- } else {
- ri = 16;
- if (u>W) Offset = W>>4;
- else Offset = -1;
- }
-
- if (v > 0 && v <= H) {
- rj = MTab[v&15];
- Offset += (v>>4)*srcstride;
- } else {
- rj = 16;
- if (v>H) Offset += (H>>4)*srcstride;
- else Offset -= srcstride;
- }
-
- f0 = uSrc[Offset + 0];
- f0 |= uSrc[Offset + 1] << 16;
- f1 = uSrc[Offset + srcstride + 0];
- f1 |= uSrc[Offset + srcstride + 1] << 16;
- f0 = (ri*f0)>>16;
- f1 = (ri*f1) & 0x0fff0000;
- f0 |= f1;
- f0 = (rj*f0 + Rounder) >> 24;
-
- uDst[i] = (byte)f0;
-
- f0 = vSrc[Offset + 0];
- f0 |= vSrc[Offset + 1] << 16;
- f1 = vSrc[Offset + srcstride + 0];
- f1 |= vSrc[Offset + srcstride + 1] << 16;
- f0 = (ri*f0)>>16;
- f1 = (ri*f1) & 0x0fff0000;
- f0 |= f1;
- f0 = (rj*f0 + Rounder) >> 24;
-
- vDst[i] = (byte)f0;
- }
- uDst += dststride;
- vDst += dststride;
- }
-}
-
-//----------------------------
-
-static void get_average_mv_C(const NEW_GMC_DATA * const Dsp, VECTOR * const mv, int x, int y, int qpel){
-
- int i, j;
- int vx = 0, vy = 0;
- int uo = Dsp->Uo + 16*(Dsp->dU[1]*y + Dsp->dU[0]*x);
- int vo = Dsp->Vo + 16*(Dsp->dV[1]*y + Dsp->dV[0]*x);
- for (j=16; j>0; --j)
- {
- int U, V;
- U = uo; uo += Dsp->dU[1];
- V = vo; vo += Dsp->dV[1];
- for (i=16; i>0; --i)
- {
- int u,v;
- u = U >> 16; U += Dsp->dU[0]; vx += u;
- v = V >> 16; V += Dsp->dV[0]; vy += v;
- }
- }
- vx -= (256*x+120) << (5+Dsp->accuracy); /* 120 = 15*16/2 */
- vy -= (256*y+120) << (5+Dsp->accuracy);
-
- mv->x = RSHIFT( vx, 8+Dsp->accuracy - qpel );
- mv->y = RSHIFT( vy, 8+Dsp->accuracy - qpel );
-}
-
-//----------------------------
-/* ************************************************************
- * simplified version for 1 warp point
- */
-static void Predict_1pt_16x16_C(const NEW_GMC_DATA * const This, byte *Dst, const byte *Src, int dststride, int srcstride, int x, int y, int rounding){
-
- const int W = This->sW;
- const int H = This->sH;
- const int rho = 3-This->accuracy;
- const int Rounder = ( 128 - (rounding<<(2*rho)) ) << 16;
-
-
- int uo = This->Uo + (x<<8); /* ((16*x)<<4) */
- int vo = This->Vo + (y<<8);
- const dword ri = MTab[uo & 15];
- const dword rj = MTab[vo & 15];
- int i, j;
-
- int Offset;
- if ((dword)vo<=(dword)H) Offset = (vo>>4)*srcstride;
- else if (vo>H) Offset = ( H>>4)*srcstride;
- else Offset =-16*srcstride;
- if ((dword)uo<=(dword)W) Offset += (uo>>4);
- else if (uo>W) Offset += ( W>>4);
- else Offset -= 16;
-
- Dst += 16;
-
- for(j=16; j>0; --j, Offset+=srcstride-16)
- {
- for(i=-16; i<0; ++i, ++Offset)
- {
- dword f0, f1;
- f0 = Src[ Offset +0 ];
- f0 |= Src[ Offset +1 ] << 16;
- f1 = Src[ Offset+srcstride +0 ];
- f1 |= Src[ Offset+srcstride +1 ] << 16;
- f0 = (ri*f0)>>16;
- f1 = (ri*f1) & 0x0fff0000;
- f0 |= f1;
- f0 = ( rj*f0 + Rounder ) >> 24;
- Dst[i] = (byte)f0;
- }
- Dst += dststride;
- }
-}
-
-//----------------------------
-
-static void Predict_1pt_8x8_C(const NEW_GMC_DATA * const This, byte *uDst, const byte *uSrc,
- byte *vDst, const byte *vSrc, int dststride, int srcstride, int x, int y, int rounding){
-
- const int W = This->sW >> 1;
- const int H = This->sH >> 1;
- const int rho = 3-This->accuracy;
- const int Rounder = ( 128 - (rounding<<(2*rho)) ) << 16;
-
- int uo = This->Uco + (x<<7);
- int vo = This->Vco + (y<<7);
- const dword rri = MTab[uo & 15];
- const dword rrj = MTab[vo & 15];
- int i, j;
-
- int Offset;
- if ((dword)vo<=(dword)H) Offset = (vo>>4)*srcstride;
- else if (vo>H) Offset = ( H>>4)*srcstride;
- else Offset =-8*srcstride;
- if ((dword)uo<=(dword)W) Offset += (uo>>4);
- else if (uo>W) Offset += (W>>4);
- else Offset -= 8;
-
- uDst += 8;
- vDst += 8;
- for(j=8; j>0; --j, Offset+=srcstride-8)
- {
- for(i=-8; i<0; ++i, Offset++)
- {
- dword f0, f1;
- f0 = uSrc[ Offset + 0 ];
- f0 |= uSrc[ Offset + 1 ] << 16;
- f1 = uSrc[ Offset + srcstride + 0 ];
- f1 |= uSrc[ Offset + srcstride + 1 ] << 16;
- f0 = (rri*f0)>>16;
- f1 = (rri*f1) & 0x0fff0000;
- f0 |= f1;
- f0 = ( rrj*f0 + Rounder ) >> 24;
- uDst[i] = (byte)f0;
-
- f0 = vSrc[ Offset + 0 ];
- f0 |= vSrc[ Offset + 1 ] << 16;
- f1 = vSrc[ Offset + srcstride + 0 ];
- f1 |= vSrc[ Offset + srcstride + 1 ] << 16;
- f0 = (rri*f0)>>16;
- f1 = (rri*f1) & 0x0fff0000;
- f0 |= f1;
- f0 = ( rrj*f0 + Rounder ) >> 24;
- vDst[i] = (byte)f0;
- }
- uDst += dststride;
- vDst += dststride;
- }
-}
-
-//----------------------------
-
-static void get_average_mv_1pt_C(const NEW_GMC_DATA *const Dsp, VECTOR * const mv, int x, int y, int qpel){
-
- mv->x = RSHIFT(Dsp->Uo<<qpel, 3);
- mv->y = RSHIFT(Dsp->Vo<<qpel, 3);
-}
-
-//----------------------------
-
-void generate_GMCparameters(int nb_pts, int accuracy, const WARPPOINTS *pts, int width, int height, NEW_GMC_DATA *gmc){
-
- gmc->sW = width << 4;
- gmc->sH = height << 4;
- gmc->accuracy = accuracy;
- gmc->num_wp = nb_pts;
-
- //reduce the number of points, if possible
- if(nb_pts<3 || (pts->duv[2].x==-pts->duv[1].y && pts->duv[2].y==pts->duv[1].x)){
- if(nb_pts<2 || (pts->duv[1].x==0 && pts->duv[1].y==0)){
- if(nb_pts<1 || (pts->duv[0].x==0 && pts->duv[0].y==0)){
- nb_pts = 0;
- }else
- nb_pts = 1;
- }else
- nb_pts = 2;
- }else
- nb_pts = 3;
-
- //now, nb_pts stores the actual number of points required for interpolation
- if(nb_pts<=1){
- if(nb_pts==1){
- /* store as 4b fixed point */
- gmc->Uo = pts->duv[0].x << accuracy;
- gmc->Vo = pts->duv[0].y << accuracy;
- gmc->Uco = ((pts->duv[0].x>>1) | (pts->duv[0].x&1)) << accuracy; /* DIV2RND() */
- gmc->Vco = ((pts->duv[0].y>>1) | (pts->duv[0].y&1)) << accuracy; /* DIV2RND() */
- }else{ /* zero points?! */
- gmc->Uo = gmc->Vo = 0;
- gmc->Uco = gmc->Vco = 0;
- }
-
- gmc->predict_16x16 = Predict_1pt_16x16_C;
- gmc->predict_8x8 = Predict_1pt_8x8_C;
- gmc->get_average_mv = get_average_mv_1pt_C;
- }else{ /* 2 or 3 points */
- const int rho = 3 - accuracy; /* = {3,2,1,0} for Acc={0,1,2,3} */
- int Alpha = log2bin(width-1);
- int Ws = 1 << Alpha;
-
- gmc->dU[0] = 16*Ws + RDIV( 8*Ws*pts->duv[1].x, width ); /* dU/dx */
- gmc->dV[0] = RDIV( 8*Ws*pts->duv[1].y, width ); /* dV/dx */
-
- /* disabled, because possibly buggy? */
-
-#if 0
- if (nb_pts==2) {
- gmc->dU[1] = -gmc->dV[0]; /* -Sin */
- gmc->dV[1] = gmc->dU[0] ; /* Cos */
- }
- else
-#endif
- {
- const int Beta = log2bin(height-1);
- const int Hs = 1<<Beta;
- gmc->dU[1] = RDIV( 8*Hs*pts->duv[2].x, height ); /* dU/dy */
- gmc->dV[1] = 16*Hs + RDIV( 8*Hs*pts->duv[2].y, height ); /* dV/dy */
- if (Beta>Alpha) {
- gmc->dU[0] <<= (Beta-Alpha);
- gmc->dV[0] <<= (Beta-Alpha);
- Alpha = Beta;
- Ws = Hs;
- }
- else {
- gmc->dU[1] <<= Alpha - Beta;
- gmc->dV[1] <<= Alpha - Beta;
- }
- }
- /* upscale to 16b fixed-point */
- gmc->dU[0] <<= (16-Alpha - rho);
- gmc->dU[1] <<= (16-Alpha - rho);
- gmc->dV[0] <<= (16-Alpha - rho);
- gmc->dV[1] <<= (16-Alpha - rho);
-
- gmc->Uo = ( pts->duv[0].x <<(16+ accuracy)) + (1<<15);
- gmc->Vo = ( pts->duv[0].y <<(16+ accuracy)) + (1<<15);
- gmc->Uco = ((pts->duv[0].x-1)<<(17+ accuracy)) + (1<<17);
- gmc->Vco = ((pts->duv[0].y-1)<<(17+ accuracy)) + (1<<17);
- gmc->Uco = (gmc->Uco + gmc->dU[0] + gmc->dU[1])>>2;
- gmc->Vco = (gmc->Vco + gmc->dV[0] + gmc->dV[1])>>2;
-
- gmc->predict_16x16 = Predict_16x16_C;
- gmc->predict_8x8 = Predict_8x8_C;
- gmc->get_average_mv = get_average_mv_C;
- }
-}
-
-//----------------------------
\ No newline at end of file
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - GMC interpolation module header -
- *
- * Copyright(C) 2002-2003 Pascal Massimino <skal@planet-d.net>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: gmc.h,v 1.1.1.1 2005-07-13 14:36:14 jeanlf Exp $
- *
- ****************************************************************************/
-
-#include "portab.h"
-#include "global.h"
-
-
-#define RDIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
-#define RSHIFT(a,b) ( (a)>0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b))
-
-#define MLT(i) (((16-(i))<<16) + (i))
-static const dword MTab[16] = {
- MLT( 0), MLT( 1), MLT( 2), MLT( 3), MLT( 4), MLT( 5), MLT( 6), MLT( 7),
- MLT( 8), MLT( 9), MLT(10), MLT(11), MLT(12), MLT(13), MLT(14), MLT(15)
-};
-#undef MLT
-
-
-/* *************************************************************
- * Warning! It's Accuracy being passed, not 'resolution'!
- */
-void generate_GMCparameters(int nb_pts, int accuracy, const WARPPOINTS *pts, int width, int height, NEW_GMC_DATA *gmc);
-
+++ /dev/null
-/**************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Image management functions -
- *
- * Copyright(C) 2001-2003 Peter Ross <pross@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: image.cpp,v 1.1.1.1 2005-07-13 14:36:14 jeanlf Exp $
- *
- ****************************************************************************/
-//#include <math.h>
-
-#include "portab.h"
-#include "global.h" /* XVID_CSP_XXX's */
-#include "xvid.h" /* XVID_CSP_XXX's */
-#include "image.h"
-#include "interpolate8x8.h"
-#include "reduced.h"
-#include "decoder.h"
-#include "mem_align.h"
-
-#define SAFETY 64
-#define EDGE_SIZE2 (EDGE_SIZE/2)
-
-//----------------------------
-
-int image_create(IMAGE * image, dword edged_width, dword edged_height){
-
- const dword edged_width2 = edged_width / 2;
- const dword edged_height2 = edged_height / 2;
-
- image->y = (unsigned char*)xvid_malloc(edged_width * (edged_height + 1) + SAFETY, CACHE_LINE);
- if (image->y == NULL) {
- return -1;
- }
- MemSet(image->y, 0, edged_width * (edged_height + 1) + SAFETY);
-
- image->u = (unsigned char*)xvid_malloc(edged_width2 * edged_height2 + SAFETY, CACHE_LINE);
- if (image->u == NULL) {
- xvid_free(image->y);
- image->y = NULL;
- return -1;
- }
- MemSet(image->u, 0, edged_width2 * edged_height2 + SAFETY);
-
- image->v = (unsigned char*)xvid_malloc(edged_width2 * edged_height2 + SAFETY, CACHE_LINE);
- if (image->v == NULL) {
- xvid_free(image->u);
- image->u = NULL;
- xvid_free(image->y);
- image->y = NULL;
- return -1;
- }
- MemSet(image->v, 0, edged_width2 * edged_height2 + SAFETY);
-
- image->y += EDGE_SIZE * edged_width + EDGE_SIZE;
- image->u += EDGE_SIZE2 * edged_width2 + EDGE_SIZE2;
- image->v += EDGE_SIZE2 * edged_width2 + EDGE_SIZE2;
-
- return 0;
-}
-
-//----------------------------
-
-void image_destroy(IMAGE * image, dword edged_width, dword edged_height){
-
- const dword edged_width2 = edged_width / 2;
-
- if(image->y){
- xvid_free(image->y - (EDGE_SIZE * edged_width + EDGE_SIZE));
- image->y = NULL;
- }
- if(image->u){
- xvid_free(image->u - (EDGE_SIZE2 * edged_width2 + EDGE_SIZE2));
- image->u = NULL;
- }
- if(image->v){
- xvid_free(image->v - (EDGE_SIZE2 * edged_width2 + EDGE_SIZE2));
- image->v = NULL;
- }
-}
-
-//----------------------------
-
-void IMAGE::Swap(IMAGE *image2){
- ::Swap(y, image2->y);
- ::Swap(u, image2->u);
- ::Swap(v, image2->v);
-}
-
-//----------------------------
-
-#ifdef _ARM_
-
-extern"C"
-void XVID_MemCpy(void *dst, const void *src, dword count);
-
-#else
-
-void XVID_MemCpy(void *dst, const void *src, dword count){
- assert(!(dword(dst)&3));
- assert(!(dword(count)&3));
-#ifdef USE_ARM_ASM
- int t0, t1, t2, t3;
- asm volatile(
- "subs %2, %2, #16\n blt .mc_no16\n\t"
- "\n.mc_loop16:\n\t"
- //the order of regs in {} is not important, now it's ordered as to avoid compiler warnings
- "ldmia %1!, {%6, %3, %5, %4}\n\t"
- "stmia %0!, {%6, %3, %5, %4}\n\t"
- "subs %2, %2, #16\n bge .mc_loop16\n\t"
- "\n.mc_no16:\n\t"
- "adds %2, %2, #16\n\t"
- "beq .mc_end\n\t"
- "\n.mc_loop4:\n\t"
- "ldr %3, [%1], #4\n\t"
- "str %3, [%0], #4\n\t"
- "subs %2, %2, #4\n bne .mc_loop4\n\t"
- "\n.mc_end:\n\t"
- : "+r"(dst), "+r"(src), "+r"(count), "&=r"(t0), "&=r"(t1), "&=r"(t2), "&=r"(t3)
- :
- );
-#else
- MemCpy(dst, src, count);
-#endif
-}
-
-#endif
-
-//---------------------------
-
-void IMAGE::Copy(const IMAGE * image2, dword edged_width, dword height){
- XVID_MemCpy(y, image2->y, edged_width * height);
- XVID_MemCpy(u, image2->u, edged_width * height / 4);
- XVID_MemCpy(v, image2->v, edged_width * height / 4);
-}
-
-//----------------------------
-
-inline void XVID_Set16bytes(void *dst, dword val){
- assert(!(dword(dst)&3));
- val |= val<<8;
- val |= val<<16;
- ((dword*)dst)[0] = val;
- ((dword*)dst)[1] = val;
- ((dword*)dst)[2] = val;
- ((dword*)dst)[3] = val;
-}
-
-//---------------------------
-
-inline void XVID_Set8bytes(void *dst, dword val){
- assert(!(dword(dst)&3));
- val |= val<<8;
- val |= val<<16;
- ((dword*)dst)[0] = val;
- ((dword*)dst)[1] = val;
-}
-
-//--------------------------
-
-void S_decoder::SetEdges(IMAGE &img) const{
-
- const dword edged_width2 = edged_width / 2;
-
- assert(EDGE_SIZE==16);
-
- byte *dst = img.y - (EDGE_SIZE + EDGE_SIZE * edged_width);
- const byte *src = img.y;
-
- //according to the Standard Clause 7.6.4, padding is done starting at 16
- // * pixel width and height multiples
- dword width = (S_decoder::width+15)&~15;
- dword height = (S_decoder::height+15)&~15;
- dword width2 = width/2;
-
- dword i;
- for(i = 0; i < EDGE_SIZE; i++){
- XVID_Set16bytes(dst, *src);
- XVID_MemCpy(dst + EDGE_SIZE, src, width);
- XVID_Set16bytes(dst + edged_width - EDGE_SIZE, *(src + width - 1));
- dst += edged_width;
- }
- for(i = 0; i < height; i++){
- XVID_Set16bytes(dst, *src);
- XVID_Set16bytes(dst + edged_width - EDGE_SIZE, src[width - 1]);
- dst += edged_width;
- src += edged_width;
- }
-
- src -= edged_width;
- for(i = 0; i < EDGE_SIZE; i++){
- XVID_Set16bytes(dst, *src);
- XVID_MemCpy(dst + EDGE_SIZE, src, width);
- XVID_Set16bytes(dst + edged_width - EDGE_SIZE, *(src + width - 1));
- dst += edged_width;
- }
-
- //U
- dst = img.u - (EDGE_SIZE2 + EDGE_SIZE2 * edged_width2);
- src = img.u;
-
- for (i = 0; i < EDGE_SIZE2; i++) {
- XVID_Set8bytes(dst, *src);
- XVID_MemCpy(dst + EDGE_SIZE2, src, width2);
- XVID_Set8bytes(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1));
- dst += edged_width2;
- }
-
- for (i = 0; i < height / 2; i++) {
- XVID_Set8bytes(dst, *src);
- XVID_Set8bytes(dst + edged_width2 - EDGE_SIZE2, src[width2 - 1]);
- dst += edged_width2;
- src += edged_width2;
- }
- src -= edged_width2;
- for (i = 0; i < EDGE_SIZE2; i++) {
- XVID_Set8bytes(dst, *src);
- XVID_MemCpy(dst + EDGE_SIZE2, src, width2);
- XVID_Set8bytes(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1));
- dst += edged_width2;
- }
-
- //V
- dst = img.v - (EDGE_SIZE2 + EDGE_SIZE2 * edged_width2);
- src = img.v;
-
- for(i = 0; i < EDGE_SIZE2; i++){
- XVID_Set8bytes(dst, *src);
- XVID_MemCpy(dst + EDGE_SIZE2, src, width2);
- XVID_Set8bytes(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1));
- dst += edged_width2;
- }
-
- for(i = 0; i < height / 2; i++){
- XVID_Set8bytes(dst, *src);
- XVID_Set8bytes(dst + edged_width2 - EDGE_SIZE2, src[width2 - 1]);
- dst += edged_width2;
- src += edged_width2;
- }
- src -= edged_width2;
- for(i = 0; i < EDGE_SIZE2; i++){
- XVID_Set8bytes(dst, *src);
- XVID_MemCpy(dst + EDGE_SIZE2, src, width2);
- XVID_Set8bytes(dst + edged_width2 - EDGE_SIZE2, *(src + width2 - 1));
- dst += edged_width2;
- }
-}
-
-//----------------------------
-
-void IMAGE::Clear(int width, int height, int edged_width, int y, int u, int v){
-
- byte * p;
- int i;
-
- p = IMAGE::y;
- for(i = 0; i < height; i++){
- MemSet(p, y, width);
- p += edged_width;
- }
-
- p = IMAGE::u;
- for(i = 0; i < height/2; i++){
- MemSet(p, u, width/2);
- p += edged_width/2;
- }
-
- p = IMAGE::v;
- for(i = 0; i < height/2; i++){
- MemSet(p, v, width/2);
- p += edged_width/2;
- }
-}
-
-//----------------------------
-/* reduced resolution deblocking filter
- block = block size (16=rrv, 8=full resolution)
- flags = XVID_DEC_YDEBLOCK|XVID_DEC_UVDEBLOCK
-*/
-void IMAGE::deblock_rrv(int edged_width, const MACROBLOCK * mbs, int mb_width, int mb_height, int mb_stride, int block, int flags){
-
- const int edged_width2 = edged_width /2;
- const int nblocks = block / 8; //skals code uses 8pixel block uints
- int i,j;
-
- for (j = 1; j < mb_height*2; j++) //horizontal deblocking
- for (i = 0; i < mb_width*2; i++)
- {
- if(mbs[(j-1)/2*mb_stride + (i/2)].mode != MODE_NOT_CODED ||
- mbs[(j+0)/2*mb_stride + (i/2)].mode != MODE_NOT_CODED)
- {
- hfilter_31(IMAGE::y + (j*block - 1)*edged_width + i*block,
- IMAGE::y + (j*block + 0)*edged_width + i*block, nblocks);
- }
- }
-
- for (j = 0; j < mb_height*2; j++) // vertical deblocking
- for (i = 1; i < mb_width*2; i++)
- {
- if (mbs[(j/2)*mb_stride + (i-1)/2].mode != MODE_NOT_CODED ||
- mbs[(j/2)*mb_stride + (i+0)/2].mode != MODE_NOT_CODED)
- {
- vfilter_31(IMAGE::y + (j*block)*edged_width + i*block - 1,
- IMAGE::y + (j*block)*edged_width + i*block + 0,
- edged_width, nblocks);
- }
- }
-
-
- //chroma
-
- for (j = 1; j < mb_height; j++) //orizontal deblocking
- for (i = 0; i < mb_width; i++)
- {
- if (mbs[(j-1)*mb_stride + i].mode != MODE_NOT_CODED ||
- mbs[(j+0)*mb_stride + i].mode != MODE_NOT_CODED)
- {
- hfilter_31(IMAGE::u + (j*block - 1)*edged_width2 + i*block,
- IMAGE::u + (j*block + 0)*edged_width2 + i*block, nblocks);
- hfilter_31(IMAGE::v + (j*block - 1)*edged_width2 + i*block,
- IMAGE::v + (j*block + 0)*edged_width2 + i*block, nblocks);
- }
- }
-
- for (j = 0; j < mb_height; j++) //ertical deblocking
- for (i = 1; i < mb_width; i++)
- {
- if (mbs[j*mb_stride + i - 1].mode != MODE_NOT_CODED ||
- mbs[j*mb_stride + i + 0].mode != MODE_NOT_CODED)
- {
- vfilter_31(IMAGE::u + (j*block)*edged_width2 + i*block - 1,
- IMAGE::u + (j*block)*edged_width2 + i*block + 0,
- edged_width2, nblocks);
- vfilter_31(IMAGE::v + (j*block)*edged_width2 + i*block - 1,
- IMAGE::v + (j*block)*edged_width2 + i*block + 0,
- edged_width2, nblocks);
- }
- }
-}
-
-//----------------------------
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Image related header -
- *
- * Copyright(C) 2001-2003 Peter Ross <pross@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: image.h,v 1.1.1.1 2005-07-13 14:36:14 jeanlf Exp $
- *
- ****************************************************************************/
-
-#ifndef _IMAGE_H_
-#define _IMAGE_H_
-
-#include "portab.h"
-#include "global.h"
-#include "xvid.h"
-
-int image_create(IMAGE * image, dword edged_width, dword edged_height);
-void image_destroy(IMAGE * image, dword edged_width, dword edged_height);
-
-
-#endif /* _IMAGE_H_ */
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - 8x8 block-based halfpel interpolation -
- *
- * Copyright(C) 2001-2003 Peter Ross <pross@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: interpolate8x8.cpp,v 1.1.1.1 2005-07-13 14:36:15 jeanlf Exp $
- *
- ****************************************************************************/
-
-#include "portab.h"
-#include "global.h"
-#include "interpolate8x8.h"
-
-//----------------------------
-
-void interpolate8x8_switch(byte *cur, const byte *refn, dword x, dword y, int dx, int dy, dword stride, bool rounding){
-
- const byte *src = refn + ((y + (dy>>1)) * stride + x + (dx>>1));
- byte *dst = cur + (y * stride + x);
-
- switch(((dx & 1) << 1) + (dy & 1)){
- case 0:
- transfer8x8_copy(dst, src, stride);
- break;
- case 1:
- interpolate8x8_halfpel_v(dst, src, stride, rounding);
- break;
- case 2:
- interpolate8x8_halfpel_h(dst, src, stride, rounding);
- break;
- default:
- interpolate8x8_halfpel_hv(dst, src, stride, rounding);
- break;
- }
-}
-
-//----------------------------
-
-void interpolate8x8_quarterpel(byte *cur, byte *refn, byte *refh, byte *refv, byte *refhv, dword x, dword y, int dx, int dy, dword stride, bool rounding){
-
- const int xRef = x*4 + dx;
- const int yRef = y*4 + dy;
-
- byte *src, *dst;
- byte *halfpel_h, *halfpel_v, *halfpel_hv;
- int x_int, y_int, x_frac, y_frac;
-
- x_int = xRef/4;
- if(xRef < 0 && xRef % 4)
- x_int--;
-
- x_frac = xRef - (4*x_int);
-
- y_int = yRef/4;
- if (yRef < 0 && yRef % 4)
- y_int--;
-
- y_frac = yRef - (4*y_int);
-
- src = refn + y_int * stride + x_int;
- halfpel_h = refh;
- halfpel_v = refv;
- halfpel_hv = refhv;
-
- dst = cur + y * stride + x;
-
- switch((y_frac << 2) | (x_frac)) {
-
- case 0:
- transfer8x8_copy(dst, src, stride);
- break;
-
- case 1:
- interpolate8x8_lowpass_h(halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(dst, src, halfpel_h, stride, rounding, 8);
- break;
-
- case 2:
- interpolate8x8_lowpass_h(dst, src, stride, rounding);
- break;
-
- case 3:
- interpolate8x8_lowpass_h(halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(dst, src + 1, halfpel_h, stride, rounding, 8);
- break;
-
- case 4:
- interpolate8x8_lowpass_v(halfpel_v, src, stride, rounding);
- interpolate8x8_avg2(dst, src, halfpel_v, stride, rounding, 8);
- break;
-
- case 5:
- interpolate8x8_lowpass_h(halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(halfpel_v, src, halfpel_h, stride, rounding, 9);
- interpolate8x8_lowpass_v(halfpel_hv, halfpel_v, stride, rounding);
- interpolate8x8_avg2(dst, halfpel_v, halfpel_hv, stride, rounding, 8);
- break;
-
- case 6:
- interpolate8x8_lowpass_hv(halfpel_hv, halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(dst, halfpel_h, halfpel_hv, stride, rounding, 8);
- break;
-
- case 7:
- interpolate8x8_lowpass_h(halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(halfpel_v, src + 1, halfpel_h, stride, rounding, 9);
- interpolate8x8_lowpass_v(halfpel_hv, halfpel_v, stride, rounding);
- interpolate8x8_avg2(dst, halfpel_v, halfpel_hv, stride, rounding, 8);
- break;
-
- case 8:
- interpolate8x8_lowpass_v(dst, src, stride, rounding);
- break;
-
- case 9:
- interpolate8x8_lowpass_h(halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(halfpel_v, src, halfpel_h, stride, rounding, 9);
- interpolate8x8_lowpass_v(dst, halfpel_v, stride, rounding);
- break;
-
- case 10:
- interpolate8x8_lowpass_hv(dst, halfpel_h, src, stride, rounding);
- break;
-
- case 11:
- interpolate8x8_lowpass_h(halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(halfpel_v, src + 1, halfpel_h, stride, rounding, 9);
- interpolate8x8_lowpass_v(dst, halfpel_v, stride, rounding);
- break;
-
- case 12:
- interpolate8x8_lowpass_v(halfpel_v, src, stride, rounding);
- interpolate8x8_avg2(dst, src+stride, halfpel_v, stride, rounding, 8);
- break;
-
- case 13:
- interpolate8x8_lowpass_h(halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(halfpel_v, src, halfpel_h, stride, rounding, 9);
- interpolate8x8_lowpass_v(halfpel_hv, halfpel_v, stride, rounding);
- interpolate8x8_avg2(dst, halfpel_v+stride, halfpel_hv, stride, rounding, 8);
- break;
-
- case 14:
- interpolate8x8_lowpass_hv(halfpel_hv, halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(dst, halfpel_h+stride, halfpel_hv, stride, rounding, 8);
- break;
-
- case 15:
- interpolate8x8_lowpass_h(halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(halfpel_v, src + 1, halfpel_h, stride, rounding, 9);
- interpolate8x8_lowpass_v(halfpel_hv, halfpel_v, stride, rounding);
- interpolate8x8_avg2(dst, halfpel_hv, halfpel_v + stride, stride, rounding, 8);
- break;
- }
-}
-
-//----------------------------
-
-void interpolate16x16_quarterpel(byte *cur, byte *refn, byte *refh, byte *refv, byte *refhv, dword x, dword y, int dx, int dy, dword stride, bool rounding){
-
- const int xRef = x*4 + dx;
- const int yRef = y*4 + dy;
-
- byte *src, *dst;
- byte *halfpel_h, *halfpel_v, *halfpel_hv;
- int x_int, y_int, x_frac, y_frac;
-
- x_int = xRef/4;
- if (xRef < 0 && xRef % 4)
- x_int--;
-
- x_frac = xRef - (4*x_int);
-
- y_int = yRef/4;
- if (yRef < 0 && yRef % 4)
- y_int--;
-
- y_frac = yRef - (4*y_int);
-
- src = refn + y_int * stride + x_int;
- halfpel_h = refh;
- halfpel_v = refv;
- halfpel_hv = refhv;
-
- dst = cur + y * stride + x;
-
- switch((y_frac << 2) | (x_frac)){
- case 0:
- transfer16x16_copy(dst, src, stride);
- break;
-
- case 1:
- interpolate16x16_lowpass_h(halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(dst, src, halfpel_h, stride, rounding, 8);
- interpolate8x8_avg2(dst+8, src+8, halfpel_h+8, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride, src+8*stride, halfpel_h+8*stride, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride+8, src+8*stride+8, halfpel_h+8*stride+8, stride, rounding, 8);
- break;
-
- case 2:
- interpolate16x16_lowpass_h(dst, src, stride, rounding);
- break;
-
- case 3:
- interpolate16x16_lowpass_h(halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(dst, src + 1, halfpel_h, stride, rounding, 8);
- interpolate8x8_avg2(dst+8, src + 8 + 1, halfpel_h+8, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride, src + 8*stride + 1, halfpel_h+8*stride, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride+8, src+8*stride+8 + 1, halfpel_h+8*stride+8, stride, rounding, 8);
- break;
-
- case 4:
- interpolate16x16_lowpass_v(halfpel_v, src, stride, rounding);
- interpolate8x8_avg2(dst, src, halfpel_v, stride, rounding, 8);
- interpolate8x8_avg2(dst+8, src+8, halfpel_v+8, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride, src+8*stride, halfpel_v+8*stride, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride+8, src+8*stride+8, halfpel_v+8*stride+8, stride, rounding, 8);
- break;
-
- case 5:
- interpolate16x16_lowpass_h(halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(halfpel_v, src, halfpel_h, stride, rounding, 9);
- interpolate8x8_avg2(halfpel_v+8, src + 8, halfpel_h+8, stride, rounding, 9);
- interpolate8x8_avg2(halfpel_v+8*stride, src + 8*stride, halfpel_h+8*stride, stride, rounding, 9);
- interpolate8x8_avg2(halfpel_v+8*stride+8, src+8*stride+8, halfpel_h+8*stride+8, stride, rounding, 9);
-
- interpolate16x16_lowpass_v(halfpel_hv, halfpel_v, stride, rounding);
- interpolate8x8_avg2(dst, halfpel_hv, halfpel_v, stride, rounding, 8);
- interpolate8x8_avg2(dst+8, halfpel_hv+8, halfpel_v+8, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride, halfpel_hv+8*stride, halfpel_v+8*stride, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride+8, halfpel_hv+8*stride+8, halfpel_v+8*stride+8, stride, rounding, 8);
- break;
-
- case 6:
- interpolate16x16_lowpass_hv(halfpel_hv, halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(dst, halfpel_h, halfpel_hv, stride, rounding, 8);
- interpolate8x8_avg2(dst+8, halfpel_h+8, halfpel_hv+8, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride, halfpel_h+8*stride, halfpel_hv+8*stride, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride+8, halfpel_h+8*stride+8, halfpel_hv+8*stride+8, stride, rounding, 8);
- break;
-
- case 7:
- interpolate16x16_lowpass_h(halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(halfpel_v, src+1, halfpel_h, stride, rounding, 9);
- interpolate8x8_avg2(halfpel_v+8, src+1 + 8, halfpel_h+8, stride, rounding, 9);
- interpolate8x8_avg2(halfpel_v+8*stride, src+1 + 8*stride, halfpel_h+8*stride, stride, rounding, 9);
- interpolate8x8_avg2(halfpel_v+8*stride+8, src+1+8*stride+8, halfpel_h+8*stride+8, stride, rounding, 9);
-
- interpolate16x16_lowpass_v(halfpel_hv, halfpel_v, stride, rounding);
- interpolate8x8_avg2(dst, halfpel_hv, halfpel_v, stride, rounding, 8);
- interpolate8x8_avg2(dst+8, halfpel_hv+8, halfpel_v+8, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride, halfpel_hv+8*stride, halfpel_v+8*stride, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride+8, halfpel_hv+8*stride+8, halfpel_v+8*stride+8, stride, rounding, 8);
- break;
-
- case 8:
- interpolate16x16_lowpass_v(dst, src, stride, rounding);
- break;
-
- case 9:
- interpolate16x16_lowpass_h(halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(halfpel_v, src, halfpel_h, stride, rounding, 9);
- interpolate8x8_avg2(halfpel_v+8, src + 8, halfpel_h+8, stride, rounding, 9);
- interpolate8x8_avg2(halfpel_v+8*stride, src + 8*stride, halfpel_h+8*stride, stride, rounding, 9);
- interpolate8x8_avg2(halfpel_v+8*stride+8, src+8*stride+8, halfpel_h+8*stride+8, stride, rounding, 9);
- interpolate16x16_lowpass_v(dst, halfpel_v, stride, rounding);
- break;
-
- case 10:
- interpolate16x16_lowpass_hv(dst, halfpel_h, src, stride, rounding);
- break;
-
- case 11:
- interpolate16x16_lowpass_h(halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(halfpel_v, src+1, halfpel_h, stride, rounding, 9);
- interpolate8x8_avg2(halfpel_v+8, src+1 + 8, halfpel_h+8, stride, rounding, 9);
- interpolate8x8_avg2(halfpel_v+8*stride, src+1 + 8*stride, halfpel_h+8*stride, stride, rounding, 9);
- interpolate8x8_avg2(halfpel_v+8*stride+8, src+1+8*stride+8, halfpel_h+8*stride+8, stride, rounding, 9);
- interpolate16x16_lowpass_v(dst, halfpel_v, stride, rounding);
- break;
-
- case 12:
- interpolate16x16_lowpass_v(halfpel_v, src, stride, rounding);
- interpolate8x8_avg2(dst, src+stride, halfpel_v, stride, rounding, 8);
- interpolate8x8_avg2(dst+8, src+stride+8, halfpel_v+8, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride, src+stride+8*stride, halfpel_v+8*stride, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride+8, src+stride+8*stride+8, halfpel_v+8*stride+8, stride, rounding, 8);
- break;
-
- case 13:
- interpolate16x16_lowpass_h(halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(halfpel_v, src, halfpel_h, stride, rounding, 9);
- interpolate8x8_avg2(halfpel_v+8, src + 8, halfpel_h+8, stride, rounding, 9);
- interpolate8x8_avg2(halfpel_v+8*stride, src + 8*stride, halfpel_h+8*stride, stride, rounding, 9);
- interpolate8x8_avg2(halfpel_v+8*stride+8, src+8*stride+8, halfpel_h+8*stride+8, stride, rounding, 9);
-
- interpolate16x16_lowpass_v(halfpel_hv, halfpel_v, stride, rounding);
- interpolate8x8_avg2(dst, halfpel_hv, halfpel_v+stride, stride, rounding, 8);
- interpolate8x8_avg2(dst+8, halfpel_hv+8, halfpel_v+stride+8, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride, halfpel_hv+8*stride, halfpel_v+stride+8*stride, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride+8, halfpel_hv+8*stride+8, halfpel_v+stride+8*stride+8, stride, rounding, 8);
- break;
-
- case 14:
- interpolate16x16_lowpass_hv(halfpel_hv, halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(dst, halfpel_h+stride, halfpel_hv, stride, rounding, 8);
- interpolate8x8_avg2(dst+8, halfpel_h+stride+8, halfpel_hv+8, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride, halfpel_h+stride+8*stride, halfpel_hv+8*stride, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride+8, halfpel_h+stride+8*stride+8, halfpel_hv+8*stride+8, stride, rounding, 8);
- break;
-
- case 15:
- interpolate16x16_lowpass_h(halfpel_h, src, stride, rounding);
- interpolate8x8_avg2(halfpel_v, src+1, halfpel_h, stride, rounding, 9);
- interpolate8x8_avg2(halfpel_v+8, src+1 + 8, halfpel_h+8, stride, rounding, 9);
- interpolate8x8_avg2(halfpel_v+8*stride, src+1 + 8*stride, halfpel_h+8*stride, stride, rounding, 9);
- interpolate8x8_avg2(halfpel_v+8*stride+8, src+1+8*stride+8, halfpel_h+8*stride+8, stride, rounding, 9);
-
- interpolate16x16_lowpass_v(halfpel_hv, halfpel_v, stride, rounding);
- interpolate8x8_avg2(dst, halfpel_hv, halfpel_v+stride, stride, rounding, 8);
- interpolate8x8_avg2(dst+8, halfpel_hv+8, halfpel_v+stride+8, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride, halfpel_hv+8*stride, halfpel_v+stride+8*stride, stride, rounding, 8);
- interpolate8x8_avg2(dst+8*stride+8, halfpel_hv+8*stride+8, halfpel_v+stride+8*stride+8, stride, rounding, 8);
- break;
- }
-}
-
-//----------------------------
-
-void interpolate8x8_avg2(byte *dst, const byte *src1, const byte *src2, dword stride, bool rounding, dword height){
-
- const int round = 1 - rounding;
- for(dword i = 0; i < height; i++){
- dst[0] = (src1[0] + src2[0] + round) >> 1;
- dst[1] = (src1[1] + src2[1] + round) >> 1;
- dst[2] = (src1[2] + src2[2] + round) >> 1;
- dst[3] = (src1[3] + src2[3] + round) >> 1;
- dst[4] = (src1[4] + src2[4] + round) >> 1;
- dst[5] = (src1[5] + src2[5] + round) >> 1;
- dst[6] = (src1[6] + src2[6] + round) >> 1;
- dst[7] = (src1[7] + src2[7] + round) >> 1;
-
- dst += stride;
- src1 += stride;
- src2 += stride;
- }
-}
-
-//----------------------------
-
-#ifndef _ARM_
-
-void interpolate8x8_halfpel_h(byte *dst, const byte *src, dword stride, bool rounding){
-
-#if defined USE_ARM_ASM && 1
- int y, tmp, tmp1, tmp2, tmp3;
- if(rounding){
- asm volatile(
- "mov %7, #8\n\t"
- "\n.ihh_loop:\n\t"
- "ldrb %2, [%1, #8]\n\t"
- //7+8
- "ldrb %3, [%1, #7]\n\t"
- "add %4, %2, %3\n\t"
- "mov %4, %4, asr #1\n\t"
- //6+7
- "ldrb %2, [%1, #6]\n\t"
- "add %5, %2, %3\n\t"
- "mov %5, %5, asr #1\n\t"
- "orr %4, %5, %4, asl #8\n\t"
- //5+6
- "ldrb %3, [%1, #5]\n\t"
- "add %5, %2, %3\n\t"
- "mov %5, %5, asr #1\n\t"
- "orr %4, %5, %4, asl #8\n\t"
- //4+5
- "ldrb %2, [%1, #4]\n\t"
- "add %5, %2, %3\n\t"
- "mov %5, %5, asr #1\n\t"
- "orr %4, %5, %4, asl #8\n\t"
-
- "str %4, [%0, #4]\n\t"
-
- //3+4
- "ldrb %3, [%1, #3]\n\t"
- "add %4, %2, %3\n\t"
- "mov %4, %4, asr #1\n\t"
- //2+3
- "ldrb %2, [%1, #2]\n\t"
- "add %5, %2, %3\n\t"
- "mov %5, %5, asr #1\n\t"
- "orr %4, %5, %4, asl #8\n\t"
- //1+2
- "ldrb %3, [%1, #1]\n\t"
- "add %5, %2, %3\n\t"
- "mov %5, %5, asr #1\n\t"
- "orr %4, %5, %4, asl #8\n\t"
- //0+1
- "ldrb %2, [%1, #0]\n\t"
- "add %5, %2, %3\n\t"
- "mov %5, %5, asr #1\n\t"
- "orr %4, %5, %4, asl #8\n\t"
-
- "str %4, [%0, #0]\n\t"
-
- "add %0, %0, %6\n add %1, %1, %6\n\t"
- "subs %7, %7, #1\n bne .ihh_loop\n\t"
- : "+r"(dst), "+r"(src), "&=r"(tmp), "&=r"(tmp1), "&=r"(tmp2), "&=r"(tmp3)
- : "r"(stride), "%r"(y)
- );
- }else{
- asm volatile(
- "mov %7, #8\n\t"
- "\n.ihh_loop1:\n\t"
- "ldrb %2, [%1, #8]\n\t"
- //7+8
- "ldrb %3, [%1, #7]\n\t"
- "add %4, %2, %3\n\t"
- "add %4, %4, #1\n\t"
- "mov %4, %4, asr #1\n\t"
- //6+7
- "ldrb %2, [%1, #6]\n\t"
- "add %5, %2, %3\n\t"
- "add %5, %5, #1\n\t"
- "mov %5, %5, asr #1\n\t"
- "orr %4, %5, %4, asl #8\n\t"
- //5+6
- "ldrb %3, [%1, #5]\n\t"
- "add %5, %2, %3\n\t"
- "add %5, %5, #1\n\t"
- "mov %5, %5, asr #1\n\t"
- "orr %4, %5, %4, asl #8\n\t"
- //4+5
- "ldrb %2, [%1, #4]\n\t"
- "add %5, %2, %3\n\t"
- "add %5, %5, #1\n\t"
- "mov %5, %5, asr #1\n\t"
- "orr %4, %5, %4, asl #8\n\t"
-
- "str %4, [%0, #4]\n\t"
-
- //3+4
- "ldrb %3, [%1, #3]\n\t"
- "add %4, %2, %3\n\t"
- "add %4, %4, #1\n\t"
- "mov %4, %4, asr #1\n\t"
- //2+3
- "ldrb %2, [%1, #2]\n\t"
- "add %5, %2, %3\n\t"
- "add %5, %5, #1\n\t"
- "mov %5, %5, asr #1\n\t"
- "orr %4, %5, %4, asl #8\n\t"
- //1+2
- "ldrb %3, [%1, #1]\n\t"
- "add %5, %2, %3\n\t"
- "add %5, %5, #1\n\t"
- "mov %5, %5, asr #1\n\t"
- "orr %4, %5, %4, asl #8\n\t"
- //0+1
- "ldrb %2, [%1, #0]\n\t"
- "add %5, %2, %3\n\t"
- "add %5, %5, #1\n\t"
- "mov %5, %5, asr #1\n\t"
- "orr %4, %5, %4, asl #8\n\t"
-
- "str %4, [%0, #0]\n\t"
-
- "add %0, %0, %6\n add %1, %1, %6\n\t"
- "subs %7, %7, #1\n bne .ihh_loop1\n\t"
- : "+r"(dst), "+r"(src), "&=r"(tmp), "&=r"(tmp1), "&=r"(tmp2), "&=r"(tmp3)
- : "r"(stride), "%r"(y)
- );
- }
-#else
- if(rounding){
- for(dword j = 0; j < 8*stride; j+=stride){
- dst[j + 0] = byte((src[j + 0] + src[j + 1] )>>1);
- dst[j + 1] = byte((src[j + 1] + src[j + 2] )>>1);
- dst[j + 2] = byte((src[j + 2] + src[j + 3] )>>1);
- dst[j + 3] = byte((src[j + 3] + src[j + 4] )>>1);
- dst[j + 4] = byte((src[j + 4] + src[j + 5] )>>1);
- dst[j + 5] = byte((src[j + 5] + src[j + 6] )>>1);
- dst[j + 6] = byte((src[j + 6] + src[j + 7] )>>1);
- dst[j + 7] = byte((src[j + 7] + src[j + 8] )>>1);
- }
- }else{
- for(dword j = 0; j < 8*stride; j+=stride){
- //forward or backwards? Who knows ...
- dst[j + 0] = byte((src[j + 0] + src[j + 1] + 1)>>1);
- dst[j + 1] = byte((src[j + 1] + src[j + 2] + 1)>>1);
- dst[j + 2] = byte((src[j + 2] + src[j + 3] + 1)>>1);
- dst[j + 3] = byte((src[j + 3] + src[j + 4] + 1)>>1);
- dst[j + 4] = byte((src[j + 4] + src[j + 5] + 1)>>1);
- dst[j + 5] = byte((src[j + 5] + src[j + 6] + 1)>>1);
- dst[j + 6] = byte((src[j + 6] + src[j + 7] + 1)>>1);
- dst[j + 7] = byte((src[j + 7] + src[j + 8] + 1)>>1);
- }
- }
-#endif
-}
-
-#endif
-
-//----------------------------
-
-#ifndef _ARM_
-
-void interpolate8x8_halfpel_v(byte *dst, const byte *src, dword stride, bool rounding){
-
-#if defined USE_ARM_ASM && 1
- int y, tmp, tmp1, tmp2, tmp3, tmp4;
- if(rounding){
- asm volatile(
- "mov %7, #8\n\t"
- "\n.ihv_loop:\n\t"
- "add %5, %1, %6\n\t"
- //3
- "ldrb %2, [%1, #3]\n ldrb %3, [%5, #3]\n\t"
- "add %4, %2, %3\n mov %4, %4, asr #1\n\t"
- //2
- "ldrb %2, [%1, #2]\n ldrb %3, [%5, #2]\n\t"
- "add %2, %2, %3\n mov %2, %2, asr #1\n\t"
- "orr %4, %2, %4, asl #8\n\t"
- //1
- "ldrb %2, [%1, #1]\n ldrb %3, [%5, #1]\n\t"
- "add %2, %2, %3\n mov %2, %2, asr #1\n\t"
- "orr %4, %2, %4, asl #8\n\t"
- //0
- "ldrb %2, [%1, #0]\n ldrb %3, [%5, #0]\n\t"
- "add %2, %2, %3\n mov %2, %2, asr #1\n\t"
- "orr %4, %2, %4, asl #8\n\t"
-
- "str %4, [%0, #0]\n\t"
-
- //7
- "ldrb %2, [%1, #7]\n ldrb %3, [%5, #7]\n\t"
- "add %4, %2, %3\n mov %4, %4, asr #1\n\t"
- //6
- "ldrb %2, [%1, #6]\n ldrb %3, [%5, #6]\n\t"
- "add %2, %2, %3\n mov %2, %2, asr #1\n\t"
- "orr %4, %2, %4, asl #8\n\t"
- //5
- "ldrb %2, [%1, #5]\n ldrb %3, [%5, #5]\n\t"
- "add %2, %2, %3\n mov %2, %2, asr #1\n\t"
- "orr %4, %2, %4, asl #8\n\t"
- //4
- "ldrb %2, [%1, #4]\n ldrb %3, [%5, #4]\n\t"
- "add %2, %2, %3\n mov %2, %2, asr #1\n\t"
- "orr %4, %2, %4, asl #8\n\t"
-
- "str %4, [%0, #4]\n\t"
-
- "add %0, %0, %6\n add %1, %1, %6\n\t"
- "subs %7, %7, #1\n bne .ihv_loop\n\t"
- : "+r"(dst), "+r"(src), "&=r"(tmp), "&=r"(tmp1), "&=r"(tmp2), "&=r"(tmp3)
- : "r"(stride), "%r"(y)
- );
- }else{
- asm volatile(
- "mov %7, #8\n\t"
- "\n.ihv_loop1:\n\t"
- "add %5, %1, %6\n\t"
- //3
- "ldrb %2, [%1, #3]\n ldrb %3, [%5, #3]\n\t"
- "add %4, %2, %3\n add %4, %4, #1\n mov %4, %4, asr #1\n\t"
- //2
- "ldrb %2, [%1, #2]\n ldrb %3, [%5, #2]\n\t"
- "add %2, %2, %3\n add %2, %2, #1\n mov %2, %2, asr #1\n\t"
- "orr %4, %2, %4, asl #8\n\t"
- //1
- "ldrb %2, [%1, #1]\n ldrb %3, [%5, #1]\n\t"
- "add %2, %2, %3\n add %2, %2, #1\n mov %2, %2, asr #1\n\t"
- "orr %4, %2, %4, asl #8\n\t"
- //0
- "ldrb %2, [%1, #0]\n ldrb %3, [%5, #0]\n\t"
- "add %2, %2, %3\n add %2, %2, #1\n mov %2, %2, asr #1\n\t"
- "orr %4, %2, %4, asl #8\n\t"
-
- "str %4, [%0, #0]\n\t"
-
- //7
- "ldrb %2, [%1, #7]\n ldrb %3, [%5, #7]\n\t"
- "add %4, %2, %3\n add %4, %4, #1\n mov %4, %4, asr #1\n\t"
- //6
- "ldrb %2, [%1, #6]\n ldrb %3, [%5, #6]\n\t"
- "add %2, %2, %3\n add %2, %2, #1\n mov %2, %2, asr #1\n\t"
- "orr %4, %2, %4, asl #8\n\t"
- //5
- "ldrb %2, [%1, #5]\n ldrb %3, [%5, #5]\n\t"
- "add %2, %2, %3\n add %2, %2, #1\n mov %2, %2, asr #1\n\t"
- "orr %4, %2, %4, asl #8\n\t"
- //4
- "ldrb %2, [%1, #4]\n ldrb %3, [%5, #4]\n\t"
- "add %2, %2, %3\n add %2, %2, #1\n mov %2, %2, asr #1\n\t"
- "orr %4, %2, %4, asl #8\n\t"
-
- "str %4, [%0, #4]\n\t"
-
- "add %0, %0, %6\n add %1, %1, %6\n\t"
- "subs %7, %7, #1\n bne .ihv_loop1\n\t"
- : "+r"(dst), "+r"(src), "&=r"(tmp), "&=r"(tmp1), "&=r"(tmp2), "&=r"(tmp3)
- : "r"(stride), "%r"(y)
- );
- }
-#else
- if(rounding){
- for(dword j = 0; j < 8*stride; j+=stride){ /* forward is better. Some automatic prefetch perhaps. */
- dst[j + 0] = byte((src[j + 0] + src[j + stride + 0] )>>1);
- dst[j + 1] = byte((src[j + 1] + src[j + stride + 1] )>>1);
- dst[j + 2] = byte((src[j + 2] + src[j + stride + 2] )>>1);
- dst[j + 3] = byte((src[j + 3] + src[j + stride + 3] )>>1);
- dst[j + 4] = byte((src[j + 4] + src[j + stride + 4] )>>1);
- dst[j + 5] = byte((src[j + 5] + src[j + stride + 5] )>>1);
- dst[j + 6] = byte((src[j + 6] + src[j + stride + 6] )>>1);
- dst[j + 7] = byte((src[j + 7] + src[j + stride + 7] )>>1);
- }
- }else{
- for(dword j = 0; j < 8*stride; j+=stride){
- dst[j + 0] = byte((src[j + 0] + src[j + stride + 0] + 1)>>1);
- dst[j + 1] = byte((src[j + 1] + src[j + stride + 1] + 1)>>1);
- dst[j + 2] = byte((src[j + 2] + src[j + stride + 2] + 1)>>1);
- dst[j + 3] = byte((src[j + 3] + src[j + stride + 3] + 1)>>1);
- dst[j + 4] = byte((src[j + 4] + src[j + stride + 4] + 1)>>1);
- dst[j + 5] = byte((src[j + 5] + src[j + stride + 5] + 1)>>1);
- dst[j + 6] = byte((src[j + 6] + src[j + stride + 6] + 1)>>1);
- dst[j + 7] = byte((src[j + 7] + src[j + stride + 7] + 1)>>1);
- }
- }
-#endif
-}
-#endif
-
-//----------------------------
-
-#ifndef _ARM_ //PPC
-
-#ifndef USE_ARM_ASM //implemented in asm for ARM
-
-void interpolate8x8_halfpel_hv(byte *dst, const byte *src, dword stride, bool rounding){
-
- if(rounding){
- for(dword j = 0; j < 8*stride; j+=stride){
- dst[j + 0] = (byte)((src[j+0] + src[j+1] + src[j+stride+0] + src[j+stride+1] +1)>>2);
- dst[j + 1] = (byte)((src[j+1] + src[j+2] + src[j+stride+1] + src[j+stride+2] +1)>>2);
- dst[j + 2] = (byte)((src[j+2] + src[j+3] + src[j+stride+2] + src[j+stride+3] +1)>>2);
- dst[j + 3] = (byte)((src[j+3] + src[j+4] + src[j+stride+3] + src[j+stride+4] +1)>>2);
- dst[j + 4] = (byte)((src[j+4] + src[j+5] + src[j+stride+4] + src[j+stride+5] +1)>>2);
- dst[j + 5] = (byte)((src[j+5] + src[j+6] + src[j+stride+5] + src[j+stride+6] +1)>>2);
- dst[j + 6] = (byte)((src[j+6] + src[j+7] + src[j+stride+6] + src[j+stride+7] +1)>>2);
- dst[j + 7] = (byte)((src[j+7] + src[j+8] + src[j+stride+7] + src[j+stride+8] +1)>>2);
- }
- }else{
- for(dword j = 0; j < 8*stride; j+=stride){
- dst[j + 0] = (byte)((src[j+0] + src[j+1] + src[j+stride+0] + src[j+stride+1] +2)>>2);
- dst[j + 1] = (byte)((src[j+1] + src[j+2] + src[j+stride+1] + src[j+stride+2] +2)>>2);
- dst[j + 2] = (byte)((src[j+2] + src[j+3] + src[j+stride+2] + src[j+stride+3] +2)>>2);
- dst[j + 3] = (byte)((src[j+3] + src[j+4] + src[j+stride+3] + src[j+stride+4] +2)>>2);
- dst[j + 4] = (byte)((src[j+4] + src[j+5] + src[j+stride+4] + src[j+stride+5] +2)>>2);
- dst[j + 5] = (byte)((src[j+5] + src[j+6] + src[j+stride+5] + src[j+stride+6] +2)>>2);
- dst[j + 6] = (byte)((src[j+6] + src[j+7] + src[j+stride+6] + src[j+stride+7] +2)>>2);
- dst[j + 7] = (byte)((src[j+7] + src[j+8] + src[j+stride+7] + src[j+stride+8] +2)>>2);
- }
- }
-}
-#endif
-#endif
-
-//----------------------------
-
-void interpolate16x16_lowpass_h(byte *dst, byte *src, int stride, int rounding){
-
- int round_add = 16 - rounding;
- for(int i = 0; i < 17; i++){
-
- dst[0] = CLIP(((7 * ((src[0]<<1) - src[2]) + 23 * src[1] + 3 * src[3] - src[4] + round_add) >> 5), 0, 255);
- dst[1] = CLIP(((19 * src[1] + 20 * src[2] - src[5] + 3 * (src[4] - src[0] - (src[3]<<1)) + round_add) >> 5), 0, 255);
- dst[2] = CLIP(((20 * (src[2] + src[3]) + (src[0]<<1) + 3 * (src[5] - ((src[1] + src[4])<<1)) - src[6] + round_add) >> 5), 0, 255);
-
- dst[3] = CLIP(((20 * (src[3] + src[4]) + 3 * ((src[6] + src[1]) - ((src[2] + src[5])<<1)) - (src[0] + src[7]) + round_add) >> 5), 0, 255);
- dst[4] = CLIP(((20 * (src[4] + src[5]) - 3 * (((src[3] + src[6])<<1) - (src[2] + src[7])) - (src[1] + src[8]) + round_add) >> 5), 0, 255);
- dst[5] = CLIP(((20 * (src[5] + src[6]) - 3 * (((src[4] + src[7])<<1) - (src[3] + src[8])) - (src[2] + src[9]) + round_add) >> 5), 0, 255);
- dst[6] = CLIP(((20 * (src[6] + src[7]) - 3 * (((src[5] + src[8])<<1) - (src[4] + src[9])) - (src[3] + src[10]) + round_add) >> 5), 0, 255);
- dst[7] = CLIP(((20 * (src[7] + src[8]) - 3 * (((src[6] + src[9])<<1) - (src[5] + src[10])) - (src[4] + src[11]) + round_add) >> 5), 0, 255);
- dst[8] = CLIP(((20 * (src[8] + src[9]) - 3 * (((src[7] + src[10])<<1) - (src[6] + src[11])) - (src[5] + src[12]) + round_add) >> 5), 0, 255);
- dst[9] = CLIP(((20 * (src[9] + src[10]) - 3 * (((src[8] + src[11])<<1) - (src[7] + src[12])) - (src[6] + src[13]) + round_add) >> 5), 0, 255);
- dst[10] = CLIP(((20 * (src[10] + src[11]) - 3 * (((src[9] + src[12])<<1) - (src[8] + src[13])) - (src[7] + src[14]) + round_add) >> 5), 0, 255);
- dst[11] = CLIP(((20 * (src[11] + src[12]) - 3 * (((src[10] + src[13])<<1) - (src[9] + src[14])) - (src[8] + src[15]) + round_add) >> 5), 0, 255);
- dst[12] = CLIP(((20 * (src[12] + src[13]) - 3 * (((src[11] + src[14])<<1) - (src[10] + src[15])) - (src[9] + src[16]) + round_add) >> 5), 0, 255);
-
- dst[13] = CLIP(((20 * (src[13] + src[14]) + (src[16]<<1) + 3 * (src[11] - ((src[12] + src[15]) << 1)) - src[10] + round_add) >> 5), 0, 255);
- dst[14] = CLIP(((19 * src[15] + 20 * src[14] + 3 * (src[12] - src[16] - (src[13] << 1)) - src[11] + round_add) >> 5), 0, 255);
- dst[15] = CLIP(((23 * src[15] + 7 * ((src[16]<<1) - src[14]) + 3 * src[13] - src[12] + round_add) >> 5), 0, 255);
-
- dst += stride;
- src += stride;
- }
-}
-
-//----------------------------
-
-void interpolate8x8_lowpass_h(byte *dst, byte *src, int stride, int rounding){
-
- int round_add = 16 - rounding;
- for(int i = 0; i < 9; i++){
-
- dst[0] = CLIP(((7 * ((src[0]<<1) - src[2]) + 23 * src[1] + 3 * src[3] - src[4] + round_add) >> 5), 0, 255);
- dst[1] = CLIP(((19 * src[1] + 20 * src[2] - src[5] + 3 * (src[4] - src[0] - (src[3]<<1)) + round_add) >> 5), 0, 255);
- dst[2] = CLIP(((20 * (src[2] + src[3]) + (src[0]<<1) + 3 * (src[5] - ((src[1] + src[4])<<1)) - src[6] + round_add) >> 5), 0, 255);
- dst[3] = CLIP(((20 * (src[3] + src[4]) + 3 * ((src[6] + src[1]) - ((src[2] + src[5])<<1)) - (src[0] + src[7]) + round_add) >> 5), 0, 255);
- dst[4] = CLIP(((20 * (src[4] + src[5]) - 3 * (((src[3] + src[6])<<1) - (src[2] + src[7])) - (src[1] + src[8]) + round_add) >> 5), 0, 255);
- dst[5] = CLIP(((20 * (src[5] + src[6]) + (src[8]<<1) + 3 * (src[3] - ((src[4] + src[7]) << 1)) - src[2] + round_add) >> 5), 0, 255);
- dst[6] = CLIP(((19 * src[7] + 20 * src[6] + 3 * (src[4] - src[8] - (src[5] << 1)) - src[3] + round_add) >> 5), 0, 255);
- dst[7] = CLIP(((23 * src[7] + 7 * ((src[8]<<1) - src[6]) + 3 * src[5] - src[4] + round_add) >> 5), 0, 255);
-
- dst += stride;
- src += stride;
- }
-}
-
-//----------------------------
-
-void interpolate16x16_lowpass_v(byte *dst, byte *src, int stride, int rounding){
-
- int round_add = 16 - rounding;
- for(int i = 0; i < 17; i++){
- int src0 = src[0];
- int src1 = src[stride];
- int src2 = src[2 * stride];
- int src3 = src[3 * stride];
- int src4 = src[4 * stride];
- int src5 = src[5 * stride];
- int src6 = src[6 * stride];
- int src7 = src[7 * stride];
- int src8 = src[8 * stride];
- int src9 = src[9 * stride];
- int src10 = src[10 * stride];
- int src11 = src[11 * stride];
- int src12 = src[12 * stride];
- int src13 = src[13 * stride];
- int src14 = src[14 * stride];
- int src15 = src[15 * stride];
- int src16 = src[16 * stride];
-
-
- dst[0] = CLIP(((7 * ((src0<<1) - src2) + 23 * src1 + 3 * src3 - src4 + round_add) >> 5), 0, 255);
- dst[stride] = CLIP(((19 * src1 + 20 * src2 - src5 + 3 * (src4 - src0 - (src3<<1)) + round_add) >> 5), 0, 255);
- dst[2*stride] = CLIP(((20 * (src2 + src3) + (src0<<1) + 3 * (src5 - ((src1 + src4)<<1)) - src6 + round_add) >> 5), 0, 255);
-
- dst[3*stride] = CLIP(((20 * (src3 + src4) + 3 * ((src6 + src1) - ((src2 + src5)<<1)) - (src0 + src7) + round_add) >> 5), 0, 255);
- dst[4*stride] = CLIP(((20 * (src4 + src5) - 3 * (((src3 + src6)<<1) - (src2 + src7)) - (src1 + src8) + round_add) >> 5), 0, 255);
- dst[5*stride] = CLIP(((20 * (src5 + src6) - 3 * (((src4 + src7)<<1) - (src3 + src8)) - (src2 + src9) + round_add) >> 5), 0, 255);
- dst[6*stride] = CLIP(((20 * (src6 + src7) - 3 * (((src5 + src8)<<1) - (src4 + src9)) - (src3 + src10) + round_add) >> 5), 0, 255);
- dst[7*stride] = CLIP(((20 * (src7 + src8) - 3 * (((src6 + src9)<<1) - (src5 + src10)) - (src4 + src11) + round_add) >> 5), 0, 255);
- dst[8*stride] = CLIP(((20 * (src8 + src9) - 3 * (((src7 + src10)<<1) - (src6 + src11)) - (src5 + src12) + round_add) >> 5), 0, 255);
- dst[9*stride] = CLIP(((20 * (src9 + src10) - 3 * (((src8 + src11)<<1) - (src7 + src12)) - (src6 + src13) + round_add) >> 5), 0, 255);
- dst[10*stride] = CLIP(((20 * (src10 + src11) - 3 * (((src9 + src12)<<1) - (src8 + src13)) - (src7 + src14) + round_add) >> 5), 0, 255);
- dst[11*stride] = CLIP(((20 * (src11 + src12) - 3 * (((src10 + src13)<<1) - (src9 + src14)) - (src8 + src15) + round_add) >> 5), 0, 255);
- dst[12*stride] = CLIP(((20 * (src12 + src13) - 3 * (((src11 + src14)<<1) - (src10 + src15)) - (src9 + src16) + round_add) >> 5), 0, 255);
-
- dst[13*stride] = CLIP(((20 * (src13 + src14) + (src16<<1) + 3 * (src11 - ((src12 + src15) << 1)) - src10 + round_add) >> 5), 0, 255);
- dst[14*stride] = CLIP(((19 * src15 + 20 * src14 + 3 * (src12 - src16 - (src13 << 1)) - src11 + round_add) >> 5), 0, 255);
- dst[15*stride] = CLIP(((23 * src15 + 7 * ((src16<<1) - src14) + 3 * src13 - src12 + round_add) >> 5), 0, 255);
-
- dst++;
- src++;
- }
-}
-
-//----------------------------
-
-void interpolate8x8_lowpass_v(byte *dst, byte *src, int stride, int rounding){
-
- int round_add = 16 - rounding;
- for(int i = 0; i < 9; i++){
- int src0 = src[0];
- int src1 = src[stride];
- int src2 = src[2 * stride];
- int src3 = src[3 * stride];
- int src4 = src[4 * stride];
- int src5 = src[5 * stride];
- int src6 = src[6 * stride];
- int src7 = src[7 * stride];
- int src8 = src[8 * stride];
-
- dst[0] = CLIP(((7 * ((src0<<1) - src2) + 23 * src1 + 3 * src3 - src4 + round_add) >> 5), 0, 255);
- dst[stride] = CLIP(((19 * src1 + 20 * src2 - src5 + 3 * (src4 - src0 - (src3 << 1)) + round_add) >> 5), 0, 255);
- dst[2 * stride] = CLIP(((20 * (src2 + src3) + (src0<<1) + 3 * (src5 - ((src1 + src4) <<1 )) - src6 + round_add) >> 5), 0, 255);
- dst[3 * stride] = CLIP(((20 * (src3 + src4) + 3 * ((src6 + src1) - ((src2 + src5)<<1)) - (src0 + src7) + round_add) >> 5), 0, 255);
- dst[4 * stride] = CLIP(((20 * (src4 + src5) + 3 * ((src2 + src7) - ((src3 + src6)<<1)) - (src1 + src8) + round_add) >> 5), 0, 255);
- dst[5 * stride] = CLIP(((20 * (src5 + src6) + (src8<<1) + 3 * (src3 - ((src4 + src7) << 1)) - src2 + round_add) >> 5), 0, 255);
- dst[6 * stride] = CLIP(((19 * src7 + 20 * src6 - src3 + 3 * (src4 - src8 - (src5 << 1)) + round_add) >> 5), 0, 255);
- dst[7 * stride] = CLIP(((7 * ((src8<<1) - src6) + 23 * src7 + 3 * src5 - src4 + round_add) >> 5), 0, 255);
-
- dst++;
- src++;
- }
-}
-
-//----------------------------
-
-void interpolate16x16_lowpass_hv(byte *dst1, byte *dst2, byte *src, int stride, int rounding){
-
- byte round_add = 16 - rounding;
- byte *h_ptr = dst2;
- for(int i = 0; i < 17; i++){
-
- h_ptr[0] = CLIP(((7 * ((src[0]<<1) - src[2]) + 23 * src[1] + 3 * src[3] - src[4] + round_add) >> 5), 0, 255);
- h_ptr[1] = CLIP(((19 * src[1] + 20 * src[2] - src[5] + 3 * (src[4] - src[0] - (src[3]<<1)) + round_add) >> 5), 0, 255);
- h_ptr[2] = CLIP(((20 * (src[2] + src[3]) + (src[0]<<1) + 3 * (src[5] - ((src[1] + src[4])<<1)) - src[6] + round_add) >> 5), 0, 255);
-
- h_ptr[3] = CLIP(((20 * (src[3] + src[4]) + 3 * ((src[6] + src[1]) - ((src[2] + src[5])<<1)) - (src[0] + src[7]) + round_add) >> 5), 0, 255);
- h_ptr[4] = CLIP(((20 * (src[4] + src[5]) - 3 * (((src[3] + src[6])<<1) - (src[2] + src[7])) - (src[1] + src[8]) + round_add) >> 5), 0, 255);
- h_ptr[5] = CLIP(((20 * (src[5] + src[6]) - 3 * (((src[4] + src[7])<<1) - (src[3] + src[8])) - (src[2] + src[9]) + round_add) >> 5), 0, 255);
- h_ptr[6] = CLIP(((20 * (src[6] + src[7]) - 3 * (((src[5] + src[8])<<1) - (src[4] + src[9])) - (src[3] + src[10]) + round_add) >> 5), 0, 255);
- h_ptr[7] = CLIP(((20 * (src[7] + src[8]) - 3 * (((src[6] + src[9])<<1) - (src[5] + src[10])) - (src[4] + src[11]) + round_add) >> 5), 0, 255);
- h_ptr[8] = CLIP(((20 * (src[8] + src[9]) - 3 * (((src[7] + src[10])<<1) - (src[6] + src[11])) - (src[5] + src[12]) + round_add) >> 5), 0, 255);
- h_ptr[9] = CLIP(((20 * (src[9] + src[10]) - 3 * (((src[8] + src[11])<<1) - (src[7] + src[12])) - (src[6] + src[13]) + round_add) >> 5), 0, 255);
- h_ptr[10] = CLIP(((20 * (src[10] + src[11]) - 3 * (((src[9] + src[12])<<1) - (src[8] + src[13])) - (src[7] + src[14]) + round_add) >> 5), 0, 255);
- h_ptr[11] = CLIP(((20 * (src[11] + src[12]) - 3 * (((src[10] + src[13])<<1) - (src[9] + src[14])) - (src[8] + src[15]) + round_add) >> 5), 0, 255);
- h_ptr[12] = CLIP(((20 * (src[12] + src[13]) - 3 * (((src[11] + src[14])<<1) - (src[10] + src[15])) - (src[9] + src[16]) + round_add) >> 5), 0, 255);
-
- h_ptr[13] = CLIP(((20 * (src[13] + src[14]) + (src[16]<<1) + 3 * (src[11] - ((src[12] + src[15]) << 1)) - src[10] + round_add) >> 5), 0, 255);
- h_ptr[14] = CLIP(((19 * src[15] + 20 * src[14] + 3 * (src[12] - src[16] - (src[13] << 1)) - src[11] + round_add) >> 5), 0, 255);
- h_ptr[15] = CLIP(((23 * src[15] + 7 * ((src[16]<<1) - src[14]) + 3 * src[13] - src[12] + round_add) >> 5), 0, 255);
-
- h_ptr += stride;
- src += stride;
- }
- interpolate16x16_lowpass_v(dst1, dst2, stride, rounding);
-
-}
-
-//----------------------------
-
-void interpolate8x8_lowpass_hv(byte *dst1, byte *dst2, byte *src, int stride, int rounding){
-
- byte round_add = 16 - rounding;
- byte *h_ptr = dst2;
- for(int i = 0; i < 9; i++){
-
- h_ptr[0] = CLIP(((7 * ((src[0]<<1) - src[2]) + 23 * src[1] + 3 * src[3] - src[4] + round_add) >> 5), 0, 255);
- h_ptr[1] = CLIP(((19 * src[1] + 20 * src[2] - src[5] + 3 * (src[4] - src[0] - (src[3]<<1)) + round_add) >> 5), 0, 255);
- h_ptr[2] = CLIP(((20 * (src[2] + src[3]) + (src[0]<<1) + 3 * (src[5] - ((src[1] + src[4])<<1)) - src[6] + round_add) >> 5), 0, 255);
- h_ptr[3] = CLIP(((20 * (src[3] + src[4]) + 3 * ((src[6] + src[1]) - ((src[2] + src[5])<<1)) - (src[0] + src[7]) + round_add) >> 5), 0, 255);
- h_ptr[4] = CLIP(((20 * (src[4] + src[5]) - 3 * (((src[3] + src[6])<<1) - (src[2] + src[7])) - (src[1] + src[8]) + round_add) >> 5), 0, 255);
- h_ptr[5] = CLIP(((20 * (src[5] + src[6]) + (src[8]<<1) + 3 * (src[3] - ((src[4] + src[7]) << 1)) - src[2] + round_add) >> 5), 0, 255);
- h_ptr[6] = CLIP(((19 * src[7] + 20 * src[6] + 3 * (src[4] - src[8] - (src[5] << 1)) - src[3] + round_add) >> 5), 0, 255);
- h_ptr[7] = CLIP(((23 * src[7] + 7 * ((src[8]<<1) - src[6]) + 3 * src[5] - src[4] + round_add) >> 5), 0, 255);
-
- h_ptr += stride;
- src += stride;
- }
- interpolate8x8_lowpass_v(dst1, dst2, stride, rounding);
-}
-
-//----------------------------
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Interpolation related header -
- *
- * Copyright(C) 2001-2003 Peter Ross <pross@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: interpolate8x8.h,v 1.1.1.1 2005-07-13 14:36:15 jeanlf Exp $
- *
- ****************************************************************************/
-
-#ifndef _INTERPOLATE8X8_H_
-#define _INTERPOLATE8X8_H_
-
-#include "mem_transfer.h"
-
-typedef void (INTERPOLATE8X8)(byte *dst, const byte *src, dword stride, bool rounding);
-typedef INTERPOLATE8X8 *INTERPOLATE8X8_PTR;
-
-typedef void (INTERPOLATE8X8_AVG2)(byte *dst, const byte *src1, const byte *src2, dword stride, bool rounding, dword height);
-typedef INTERPOLATE8X8_AVG2 *INTERPOLATE8X8_AVG2_PTR;
-
-typedef void (INTERPOLATE8X8_AVG4)(byte *dst, const byte *src1, const byte *src2, const byte *src3, const byte *src4, dword stride, bool rounding);
-typedef INTERPOLATE8X8_AVG4 *INTERPOLATE8X8_AVG4_PTR;
-
-typedef void (INTERPOLATE_LOWPASS) (byte *dst,
- byte *src,
- int stride,
- int rounding);
-
-typedef INTERPOLATE_LOWPASS *INTERPOLATE_LOWPASS_PTR;
-
-typedef void (INTERPOLATE_LOWPASS_HV) (byte *dst1,
- byte *dst2,
- byte *src,
- int stride,
- int rounding);
-
-typedef INTERPOLATE_LOWPASS_HV *INTERPOLATE_LOWPASS_HV_PTR;
-
-typedef void (INTERPOLATE8X8_6TAP_LOWPASS)(byte *dst, byte *src, int stride, bool rounding);
-
-typedef INTERPOLATE8X8_6TAP_LOWPASS *INTERPOLATE8X8_6TAP_LOWPASS_PTR;
-
-#ifdef _ARM_ //PPC
-extern"C"{
-#endif
-
-INTERPOLATE8X8 interpolate8x8_halfpel_h;
-INTERPOLATE8X8 interpolate8x8_halfpel_hv;
-INTERPOLATE8X8 interpolate8x8_halfpel_v;
-
-#ifdef _ARM_
-}
-#endif
-
-
-INTERPOLATE8X8_AVG2 interpolate8x8_avg2;
-
-INTERPOLATE_LOWPASS interpolate8x8_lowpass_h;
-INTERPOLATE_LOWPASS interpolate8x8_lowpass_v;
-
-INTERPOLATE_LOWPASS interpolate16x16_lowpass_h;
-INTERPOLATE_LOWPASS interpolate16x16_lowpass_v;
-
-INTERPOLATE_LOWPASS_HV interpolate8x8_lowpass_hv;
-INTERPOLATE_LOWPASS_HV interpolate16x16_lowpass_hv;
-
-//----------------------------
-// Notes:
-// x, y is always multiply of 4, so writing to 'cur' is always dword aligned
-// stride is always multiply of 4
-void interpolate8x8_switch(byte *cur, const byte *refn, dword x, dword y, int dx, int dy, dword stride, bool rounding);
-
-inline void interpolate16x16_switch(byte *cur, const byte *refn, dword x, dword y, int dx, int dy, dword stride, bool rounding){
-
- interpolate8x8_switch(cur, refn, x, y, dx, dy, stride, rounding);
- interpolate8x8_switch(cur, refn, x+8, y, dx, dy, stride, rounding);
- interpolate8x8_switch(cur, refn, x, y+8, dx, dy, stride, rounding);
- interpolate8x8_switch(cur, refn, x+8, y+8, dx, dy, stride, rounding);
-}
-
-inline void interpolate32x32_switch(byte *cur, const byte *refn, dword x, dword y, int dx, int dy, dword stride, bool rounding){
- interpolate16x16_switch(cur, refn, x, y, dx, dy, stride, rounding);
- interpolate16x16_switch(cur, refn, x+16, y, dx, dy, stride, rounding);
- interpolate16x16_switch(cur, refn, x, y+16, dx, dy, stride, rounding);
- interpolate16x16_switch(cur, refn, x+16, y+16, dx, dy, stride, rounding);
-}
-
-void interpolate8x8_quarterpel(byte *cur, byte *refn, byte *refh, byte *refv, byte *refhv, dword x, dword y, int dx, int dy, dword stride, bool rounding);
-void interpolate16x16_quarterpel(byte *cur, byte *refn, byte *refh, byte *refv, byte *refhv, dword x, dword y, int dx, int dy, dword stride, bool rounding);
-
-#endif
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - MB coding -
- *
- * Copyright (C) 2002 Michael Militzer <isibaar@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: mbcoding.cpp,v 1.1.1.1 2005-07-13 14:36:15 jeanlf Exp $
- *
- ****************************************************************************/
-
-#include "portab.h"
-#include "global.h"
-#include "bitstream.h"
-#include "vlc_codes.h"
-
-//----------------------------
-/*****************************************************************************
- * VLC tables and other constant arrays
- ****************************************************************************/
-
-struct VLC_TABLE{
- VLC vlc;
- EVENT event;
-};
-
-static const VLC_TABLE coeff_tab[2][102] = {
- /* intra = 0 */
- {
- {{ 2, 2}, {0, 0, 1}},
- {{15, 4}, {0, 0, 2}},
- {{21, 6}, {0, 0, 3}},
- {{23, 7}, {0, 0, 4}},
- {{31, 8}, {0, 0, 5}},
- {{37, 9}, {0, 0, 6}},
- {{36, 9}, {0, 0, 7}},
- {{33, 10}, {0, 0, 8}},
- {{32, 10}, {0, 0, 9}},
- {{ 7, 11}, {0, 0, 10}},
- {{ 6, 11}, {0, 0, 11}},
- {{32, 11}, {0, 0, 12}},
- {{ 6, 3}, {0, 1, 1}},
- {{20, 6}, {0, 1, 2}},
- {{30, 8}, {0, 1, 3}},
- {{15, 10}, {0, 1, 4}},
- {{33, 11}, {0, 1, 5}},
- {{80, 12}, {0, 1, 6}},
- {{14, 4}, {0, 2, 1}},
- {{29, 8}, {0, 2, 2}},
- {{14, 10}, {0, 2, 3}},
- {{81, 12}, {0, 2, 4}},
- {{13, 5}, {0, 3, 1}},
- {{35, 9}, {0, 3, 2}},
- {{13, 10}, {0, 3, 3}},
- {{12, 5}, {0, 4, 1}},
- {{34, 9}, {0, 4, 2}},
- {{82, 12}, {0, 4, 3}},
- {{11, 5}, {0, 5, 1}},
- {{12, 10}, {0, 5, 2}},
- {{83, 12}, {0, 5, 3}},
- {{19, 6}, {0, 6, 1}},
- {{11, 10}, {0, 6, 2}},
- {{84, 12}, {0, 6, 3}},
- {{18, 6}, {0, 7, 1}},
- {{10, 10}, {0, 7, 2}},
- {{17, 6}, {0, 8, 1}},
- {{ 9, 10}, {0, 8, 2}},
- {{16, 6}, {0, 9, 1}},
- {{ 8, 10}, {0, 9, 2}},
- {{22, 7}, {0, 10, 1}},
- {{85, 12}, {0, 10, 2}},
- {{21, 7}, {0, 11, 1}},
- {{20, 7}, {0, 12, 1}},
- {{28, 8}, {0, 13, 1}},
- {{27, 8}, {0, 14, 1}},
- {{33, 9}, {0, 15, 1}},
- {{32, 9}, {0, 16, 1}},
- {{31, 9}, {0, 17, 1}},
- {{30, 9}, {0, 18, 1}},
- {{29, 9}, {0, 19, 1}},
- {{28, 9}, {0, 20, 1}},
- {{27, 9}, {0, 21, 1}},
- {{26, 9}, {0, 22, 1}},
- {{34, 11}, {0, 23, 1}},
- {{35, 11}, {0, 24, 1}},
- {{86, 12}, {0, 25, 1}},
- {{87, 12}, {0, 26, 1}},
- {{ 7, 4}, {1, 0, 1}},
- {{25, 9}, {1, 0, 2}},
- {{ 5, 11}, {1, 0, 3}},
- {{15, 6}, {1, 1, 1}},
- {{ 4, 11}, {1, 1, 2}},
- {{14, 6}, {1, 2, 1}},
- {{13, 6}, {1, 3, 1}},
- {{12, 6}, {1, 4, 1}},
- {{19, 7}, {1, 5, 1}},
- {{18, 7}, {1, 6, 1}},
- {{17, 7}, {1, 7, 1}},
- {{16, 7}, {1, 8, 1}},
- {{26, 8}, {1, 9, 1}},
- {{25, 8}, {1, 10, 1}},
- {{24, 8}, {1, 11, 1}},
- {{23, 8}, {1, 12, 1}},
- {{22, 8}, {1, 13, 1}},
- {{21, 8}, {1, 14, 1}},
- {{20, 8}, {1, 15, 1}},
- {{19, 8}, {1, 16, 1}},
- {{24, 9}, {1, 17, 1}},
- {{23, 9}, {1, 18, 1}},
- {{22, 9}, {1, 19, 1}},
- {{21, 9}, {1, 20, 1}},
- {{20, 9}, {1, 21, 1}},
- {{19, 9}, {1, 22, 1}},
- {{18, 9}, {1, 23, 1}},
- {{17, 9}, {1, 24, 1}},
- {{ 7, 10}, {1, 25, 1}},
- {{ 6, 10}, {1, 26, 1}},
- {{ 5, 10}, {1, 27, 1}},
- {{ 4, 10}, {1, 28, 1}},
- {{36, 11}, {1, 29, 1}},
- {{37, 11}, {1, 30, 1}},
- {{38, 11}, {1, 31, 1}},
- {{39, 11}, {1, 32, 1}},
- {{88, 12}, {1, 33, 1}},
- {{89, 12}, {1, 34, 1}},
- {{90, 12}, {1, 35, 1}},
- {{91, 12}, {1, 36, 1}},
- {{92, 12}, {1, 37, 1}},
- {{93, 12}, {1, 38, 1}},
- {{94, 12}, {1, 39, 1}},
- {{95, 12}, {1, 40, 1}}
- },
- /* intra = 1 */
- {
- {{ 2, 2}, {0, 0, 1}},
- {{15, 4}, {0, 0, 3}},
- {{21, 6}, {0, 0, 6}},
- {{23, 7}, {0, 0, 9}},
- {{31, 8}, {0, 0, 10}},
- {{37, 9}, {0, 0, 13}},
- {{36, 9}, {0, 0, 14}},
- {{33, 10}, {0, 0, 17}},
- {{32, 10}, {0, 0, 18}},
- {{ 7, 11}, {0, 0, 21}},
- {{ 6, 11}, {0, 0, 22}},
- {{32, 11}, {0, 0, 23}},
- {{ 6, 3}, {0, 0, 2}},
- {{20, 6}, {0, 1, 2}},
- {{30, 8}, {0, 0, 11}},
- {{15, 10}, {0, 0, 19}},
- {{33, 11}, {0, 0, 24}},
- {{80, 12}, {0, 0, 25}},
- {{14, 4}, {0, 1, 1}},
- {{29, 8}, {0, 0, 12}},
- {{14, 10}, {0, 0, 20}},
- {{81, 12}, {0, 0, 26}},
- {{13, 5}, {0, 0, 4}},
- {{35, 9}, {0, 0, 15}},
- {{13, 10}, {0, 1, 7}},
- {{12, 5}, {0, 0, 5}},
- {{34, 9}, {0, 4, 2}},
- {{82, 12}, {0, 0, 27}},
- {{11, 5}, {0, 2, 1}},
- {{12, 10}, {0, 2, 4}},
- {{83, 12}, {0, 1, 9}},
- {{19, 6}, {0, 0, 7}},
- {{11, 10}, {0, 3, 4}},
- {{84, 12}, {0, 6, 3}},
- {{18, 6}, {0, 0, 8}},
- {{10, 10}, {0, 4, 3}},
- {{17, 6}, {0, 3, 1}},
- {{ 9, 10}, {0, 8, 2}},
- {{16, 6}, {0, 4, 1}},
- {{ 8, 10}, {0, 5, 3}},
- {{22, 7}, {0, 1, 3}},
- {{85, 12}, {0, 1, 10}},
- {{21, 7}, {0, 2, 2}},
- {{20, 7}, {0, 7, 1}},
- {{28, 8}, {0, 1, 4}},
- {{27, 8}, {0, 3, 2}},
- {{33, 9}, {0, 0, 16}},
- {{32, 9}, {0, 1, 5}},
- {{31, 9}, {0, 1, 6}},
- {{30, 9}, {0, 2, 3}},
- {{29, 9}, {0, 3, 3}},
- {{28, 9}, {0, 5, 2}},
- {{27, 9}, {0, 6, 2}},
- {{26, 9}, {0, 7, 2}},
- {{34, 11}, {0, 1, 8}},
- {{35, 11}, {0, 9, 2}},
- {{86, 12}, {0, 2, 5}},
- {{87, 12}, {0, 7, 3}},
- {{ 7, 4}, {1, 0, 1}},
- {{25, 9}, {0, 11, 1}},
- {{ 5, 11}, {1, 0, 6}},
- {{15, 6}, {1, 1, 1}},
- {{ 4, 11}, {1, 0, 7}},
- {{14, 6}, {1, 2, 1}},
- {{13, 6}, {0, 5, 1}},
- {{12, 6}, {1, 0, 2}},
- {{19, 7}, {1, 5, 1}},
- {{18, 7}, {0, 6, 1}},
- {{17, 7}, {1, 3, 1}},
- {{16, 7}, {1, 4, 1}},
- {{26, 8}, {1, 9, 1}},
- {{25, 8}, {0, 8, 1}},
- {{24, 8}, {0, 9, 1}},
- {{23, 8}, {0, 10, 1}},
- {{22, 8}, {1, 0, 3}},
- {{21, 8}, {1, 6, 1}},
- {{20, 8}, {1, 7, 1}},
- {{19, 8}, {1, 8, 1}},
- {{24, 9}, {0, 12, 1}},
- {{23, 9}, {1, 0, 4}},
- {{22, 9}, {1, 1, 2}},
- {{21, 9}, {1, 10, 1}},
- {{20, 9}, {1, 11, 1}},
- {{19, 9}, {1, 12, 1}},
- {{18, 9}, {1, 13, 1}},
- {{17, 9}, {1, 14, 1}},
- {{ 7, 10}, {0, 13, 1}},
- {{ 6, 10}, {1, 0, 5}},
- {{ 5, 10}, {1, 1, 3}},
- {{ 4, 10}, {1, 2, 2}},
- {{36, 11}, {1, 3, 2}},
- {{37, 11}, {1, 4, 2}},
- {{38, 11}, {1, 15, 1}},
- {{39, 11}, {1, 16, 1}},
- {{88, 12}, {0, 14, 1}},
- {{89, 12}, {1, 0, 8}},
- {{90, 12}, {1, 5, 2}},
- {{91, 12}, {1, 6, 2}},
- {{92, 12}, {1, 17, 1}},
- {{93, 12}, {1, 18, 1}},
- {{94, 12}, {1, 19, 1}},
- {{95, 12}, {1, 20, 1}}
- }
-};
-
-//----------------------------
-/* constants taken from momusys/vm_common/inlcude/max_level.h */
-static const byte max_level[2][2][64] = {
- {
- /* intra = 0, last = 0 */
- {
- 12, 6, 4, 3, 3, 3, 3, 2,
- 2, 2, 2, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0
- },
- /* intra = 0, last = 1 */
- {
- 3, 2, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0
- }
- },
- {
- /* intra = 1, last = 0 */
- {
- 27, 10, 5, 4, 3, 3, 3, 3,
- 2, 2, 1, 1, 1, 1, 1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0
- },
- /* intra = 1, last = 1 */
- {
- 8, 3, 2, 2, 2, 2, 2, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0
- }
- }
-};
-
-//----------------------------
-
-static const byte max_run[2][2][64] = {
- {
- /* intra = 0, last = 0 */
- {
- 0, 26, 10, 6, 2, 1, 1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- },
- /* intra = 0, last = 1 */
- {
- 0, 40, 1, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- }
- },
- {
- /* intra = 1, last = 0 */
- {
- 0, 14, 9, 7, 3, 2, 1, 1,
- 1, 1, 1, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- },
- /* intra = 1, last = 1 */
- {
- 0, 20, 6, 1, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- }
- }
-};
-
-/******************************************************************
- * encoder tables *
- ******************************************************************/
-
-static const VLC sprite_trajectory_len[15] = {
- { 0x00 , 2},
- { 0x02 , 3}, { 0x03, 3}, { 0x04, 3}, { 0x05, 3}, { 0x06, 3},
- { 0x0E , 4}, { 0x1E, 5}, { 0x3E, 6}, { 0x7E, 7}, { 0xFE, 8},
- { 0x1FE, 9}, {0x3FE,10}, {0x7FE,11}, {0xFFE,12} };
-
-
-/******************************************************************
- * decoder tables *
- ******************************************************************/
-
-static const VLC mcbpc_intra_table[64] = {
- {-1, 0}, {20, 6}, {36, 6}, {52, 6}, {4, 4}, {4, 4}, {4, 4}, {4, 4},
- {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3},
- {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3},
- {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3},
- {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1},
- {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1},
- {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1},
- {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}, {3, 1}
-};
-
-//----------------------------
-
-static const VLC mcbpc_inter_table[257] = {
- {VLC_ERROR, 0}, {255, 9}, {52, 9}, {36, 9}, {20, 9}, {49, 9}, {35, 8}, {35, 8},
- {19, 8}, {19, 8}, {50, 8}, {50, 8}, {51, 7}, {51, 7}, {51, 7}, {51, 7},
- {34, 7}, {34, 7}, {34, 7}, {34, 7}, {18, 7}, {18, 7}, {18, 7}, {18, 7},
- {33, 7}, {33, 7}, {33, 7}, {33, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
- {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6},
- {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6},
- {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5},
- {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5},
- {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
- {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
- {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
- {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
- {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
- {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
- {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
- {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
- {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
- {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
- {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
- {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
- {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
- {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
- {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
- {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
- {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
- {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
- {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
- {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
- {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
- {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
- {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
- {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
- {0, 1}
-};
-
-//----------------------------
-
-static const VLC cbpy_table[64] = {
- {-1, 0}, {-1, 0}, {6, 6}, {9, 6}, {8, 5}, {8, 5}, {4, 5}, {4, 5},
- {2, 5}, {2, 5}, {1, 5}, {1, 5}, {0, 4}, {0, 4}, {0, 4}, {0, 4},
- {12, 4}, {12, 4}, {12, 4}, {12, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4},
- {14, 4}, {14, 4}, {14, 4}, {14, 4}, {5, 4}, {5, 4}, {5, 4}, {5, 4},
- {13, 4}, {13, 4}, {13, 4}, {13, 4}, {3, 4}, {3, 4}, {3, 4}, {3, 4},
- {11, 4}, {11, 4}, {11, 4}, {11, 4}, {7, 4}, {7, 4}, {7, 4}, {7, 4},
- {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2},
- {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}
-};
-
-//----------------------------
-
-static const VLC TMNMVtab0[] = {
- {3, 4}, {-3, 4}, {2, 3}, {2, 3}, {-2, 3}, {-2, 3}, {1, 2},
- {1, 2}, {1, 2}, {1, 2}, {-1, 2}, {-1, 2}, {-1, 2}, {-1, 2}
-};
-
-//----------------------------
-
-static const VLC TMNMVtab1[] = {
- {12, 10}, {-12, 10}, {11, 10}, {-11, 10},
- {10, 9}, {10, 9}, {-10, 9}, {-10, 9},
- {9, 9}, {9, 9}, {-9, 9}, {-9, 9},
- {8, 9}, {8, 9}, {-8, 9}, {-8, 9},
- {7, 7}, {7, 7}, {7, 7}, {7, 7},
- {7, 7}, {7, 7}, {7, 7}, {7, 7},
- {-7, 7}, {-7, 7}, {-7, 7}, {-7, 7},
- {-7, 7}, {-7, 7}, {-7, 7}, {-7, 7},
- {6, 7}, {6, 7}, {6, 7}, {6, 7},
- {6, 7}, {6, 7}, {6, 7}, {6, 7},
- {-6, 7}, {-6, 7}, {-6, 7}, {-6, 7},
- {-6, 7}, {-6, 7}, {-6, 7}, {-6, 7},
- {5, 7}, {5, 7}, {5, 7}, {5, 7},
- {5, 7}, {5, 7}, {5, 7}, {5, 7},
- {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7},
- {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7},
- {4, 6}, {4, 6}, {4, 6}, {4, 6},
- {4, 6}, {4, 6}, {4, 6}, {4, 6},
- {4, 6}, {4, 6}, {4, 6}, {4, 6},
- {4, 6}, {4, 6}, {4, 6}, {4, 6},
- {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6},
- {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6},
- {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6},
- {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}
-};
-
-//----------------------------
-
-static const VLC TMNMVtab2[] = {
- {32, 12}, {-32, 12}, {31, 12}, {-31, 12},
- {30, 11}, {30, 11}, {-30, 11}, {-30, 11},
- {29, 11}, {29, 11}, {-29, 11}, {-29, 11},
- {28, 11}, {28, 11}, {-28, 11}, {-28, 11},
- {27, 11}, {27, 11}, {-27, 11}, {-27, 11},
- {26, 11}, {26, 11}, {-26, 11}, {-26, 11},
- {25, 11}, {25, 11}, {-25, 11}, {-25, 11},
- {24, 10}, {24, 10}, {24, 10}, {24, 10},
- {-24, 10}, {-24, 10}, {-24, 10}, {-24, 10},
- {23, 10}, {23, 10}, {23, 10}, {23, 10},
- {-23, 10}, {-23, 10}, {-23, 10}, {-23, 10},
- {22, 10}, {22, 10}, {22, 10}, {22, 10},
- {-22, 10}, {-22, 10}, {-22, 10}, {-22, 10},
- {21, 10}, {21, 10}, {21, 10}, {21, 10},
- {-21, 10}, {-21, 10}, {-21, 10}, {-21, 10},
- {20, 10}, {20, 10}, {20, 10}, {20, 10},
- {-20, 10}, {-20, 10}, {-20, 10}, {-20, 10},
- {19, 10}, {19, 10}, {19, 10}, {19, 10},
- {-19, 10}, {-19, 10}, {-19, 10}, {-19, 10},
- {18, 10}, {18, 10}, {18, 10}, {18, 10},
- {-18, 10}, {-18, 10}, {-18, 10}, {-18, 10},
- {17, 10}, {17, 10}, {17, 10}, {17, 10},
- {-17, 10}, {-17, 10}, {-17, 10}, {-17, 10},
- {16, 10}, {16, 10}, {16, 10}, {16, 10},
- {-16, 10}, {-16, 10}, {-16, 10}, {-16, 10},
- {15, 10}, {15, 10}, {15, 10}, {15, 10},
- {-15, 10}, {-15, 10}, {-15, 10}, {-15, 10},
- {14, 10}, {14, 10}, {14, 10}, {14, 10},
- {-14, 10}, {-14, 10}, {-14, 10}, {-14, 10},
- {13, 10}, {13, 10}, {13, 10}, {13, 10},
- {-13, 10}, {-13, 10}, {-13, 10}, {-13, 10}
-};
-
-//----------------------------
-
-static const VLC dc_lum_tab[] = {
- {0, 0}, {4, 3}, {3, 3}, {0, 3},
- {2, 2}, {2, 2}, {1, 2}, {1, 2},
-};
-
-//---------------------------
-#define LEVELOFFSET 32
-
-int Bitstream::bs_get_spritetrajectory(){
-
- for(int i = 0; i < 12; i++){
- if((int)ShowBits(sprite_trajectory_len[i].len) == sprite_trajectory_len[i].code){
- Skip(sprite_trajectory_len[i].len);
- return i;
- }
- }
- return -1;
-}
-
-//----------------------------
-
-void S_decoder::init_vlc_tables(){
-
- dword i, j, intra, last, run, run_esc, level, level_esc, escape, escape_len, offset;
-
- for (intra = 0; intra < 2; intra++)
- for (i = 0; i < 4096; i++)
- DCT3D[intra][i].event.level = 0;
-
- for (intra = 0; intra < 2; intra++) {
- for (last = 0; last < 2; last++) {
- for (run = 0; run < 63 + last; run++) {
- for (level = 0; level < (dword)(32 << intra); level++) {
- offset = !intra * LEVELOFFSET;
- coeff_VLC[intra][last][level + offset][run].len = 128;
- }
- }
- }
- }
-
- for (intra = 0; intra < 2; intra++) {
- for (i = 0; i < 102; i++) {
- offset = !intra * LEVELOFFSET;
-
- for (j = 0; j < (dword)(1 << (12 - coeff_tab[intra][i].vlc.len)); j++) {
- DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].len = coeff_tab[intra][i].vlc.len;
- DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].event = coeff_tab[intra][i].event;
- }
-
- coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].code
- = coeff_tab[intra][i].vlc.code << 1;
- coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].len
- = coeff_tab[intra][i].vlc.len + 1;
-
- if (!intra) {
- coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].code
- = (coeff_tab[intra][i].vlc.code << 1) | 1;
- coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].len
- = coeff_tab[intra][i].vlc.len + 1;
- }
- }
- }
-
- for (intra = 0; intra < 2; intra++) {
- for (last = 0; last < 2; last++) {
- for (run = 0; run < 63 + last; run++) {
- for (level = 1; level < (dword)(32 << intra); level++) {
-
- if (level <= max_level[intra][last][run] && run <= max_run[intra][last][level])
- continue;
-
- offset = !intra * LEVELOFFSET;
- level_esc = level - max_level[intra][last][run];
- run_esc = run - 1 - max_run[intra][last][level];
-
- if (level_esc <= max_level[intra][last][run] && run <= max_run[intra][last][level_esc]) {
- escape = ESCAPE1;
- escape_len = 7 + 1;
- run_esc = run;
- } else {
- if (run_esc <= max_run[intra][last][level] && level <= max_level[intra][last][run_esc]) {
- escape = ESCAPE2;
- escape_len = 7 + 2;
- level_esc = level;
- } else {
- if (!intra) {
- coeff_VLC[intra][last][level + offset][run].code
- = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1;
- coeff_VLC[intra][last][level + offset][run].len = 30;
- coeff_VLC[intra][last][offset - level][run].code
- = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-(int)level & 0xfff) << 1) | 1;
- coeff_VLC[intra][last][offset - level][run].len = 30;
- }
- continue;
- }
- }
-
- coeff_VLC[intra][last][level + offset][run].code
- = (escape << coeff_VLC[intra][last][level_esc + offset][run_esc].len)
- | coeff_VLC[intra][last][level_esc + offset][run_esc].code;
- coeff_VLC[intra][last][level + offset][run].len
- = coeff_VLC[intra][last][level_esc + offset][run_esc].len + escape_len;
-
- if (!intra) {
- coeff_VLC[intra][last][offset - level][run].code
- = (escape << coeff_VLC[intra][last][level_esc + offset][run_esc].len)
- | coeff_VLC[intra][last][level_esc + offset][run_esc].code | 1;
- coeff_VLC[intra][last][offset - level][run].len
- = coeff_VLC[intra][last][level_esc + offset][run_esc].len + escape_len;
- }
- }
-
- if (!intra) {
- coeff_VLC[intra][last][0][run].code
- = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-32 & 0xfff) << 1) | 1;
- coeff_VLC[intra][last][0][run].len = 30;
- }
- }
- }
- }
-
- /* init sprite_trajectory tables
- * even if GMC is not specified (it might be used later...) */
- /*
- {
- dword k;
- int l;
- sprite_trajectory_code[0+16384].code = 0;
- sprite_trajectory_code[0+16384].len = 0;
- for (k=0;k<14;k++) {
- int limit = (1<<k);
-
- for (l=-(2*limit-1); l <= -limit; l++) {
- sprite_trajectory_code[l+16384].code = (2*limit-1)+l;
- sprite_trajectory_code[l+16384].len = k+1;
- }
-
- for (l=limit; l<= 2*limit-1; l++) {
- sprite_trajectory_code[l+16384].code = l;
- sprite_trajectory_code[l+16384].len = k+1;
- }
- }
- }
- */
-}
-
-
-/***************************************************************
- * decoding stuff starts here *
- ***************************************************************/
-
-
-/*
- * for IVOP addbits == 0
- * for PVOP addbits == fcode - 1
- * for BVOP addbits == max(fcode,bcode) - 1
- * returns true or false
- */
-int Bitstream::check_resync_marker(int addbits){
-
- dword nbitsresyncmarker = NUMBITS_VP_RESYNC_MARKER + addbits;
- dword nbits = NumBitsToByteAlign();
- dword code = ShowBits(nbits);
-
- if(code == (((dword)1 << (nbits - 1)) - 1)){
- return ShowBitsFromByteAlign(nbitsresyncmarker) == RESYNC_MARKER;
- }
- return 0;
-}
-
-//----------------------------
-
-int Bitstream::get_mcbpc_intra(){
-
- dword index;
-
- index = ShowBits(9);
- index >>= 3;
-
- Skip(mcbpc_intra_table[index].len);
-
- return mcbpc_intra_table[index].code;
-
-}
-
-//----------------------------
-
-int Bitstream::GetMcbpcInter(){
-
- dword index = MIN(ShowBits(9), 256);
- Skip(mcbpc_inter_table[index].len);
-
- return mcbpc_inter_table[index].code;
-}
-
-//----------------------------
-
-int Bitstream::GetCbpy(int intra){
-
- dword index = ShowBits(6);
- Skip(cbpy_table[index].len);
- int cbpy = cbpy_table[index].code;
- if(!intra)
- cbpy = 15 - cbpy;
- return cbpy;
-}
-
-//----------------------------
-
-static int get_mv_data(Bitstream * bs){
-
- if(bs->GetBit())
- return 0;
-
- dword index = bs->ShowBits(12);
-
- if(index >= 512){
- index = (index >> 8) - 2;
- bs->Skip(TMNMVtab0[index].len);
- return TMNMVtab0[index].code;
- }
-
- if (index >= 128) {
- index = (index >> 2) - 32;
- bs->Skip(TMNMVtab1[index].len);
- return TMNMVtab1[index].code;
- }
-
- index -= 4;
-
- bs->Skip(TMNMVtab2[index].len);
- return TMNMVtab2[index].code;
-}
-
-//----------------------------
-
-int Bitstream::GetMoveVector(int fcode){
-
- int scale_fac = 1 << (fcode - 1);
- int data = get_mv_data(this);
-
- if(scale_fac == 1 || data == 0)
- return data;
-
- int res = GetBits(fcode - 1);
- int mv = ((ABS(data) - 1) * scale_fac) + res + 1;
-
- return data < 0 ? -mv : mv;
-}
-
-//----------------------------
-
-int Bitstream::get_dc_dif(dword dc_size){
-
- int code = GetBits(dc_size);
- int msb = code >> (dc_size - 1);
-
- if (msb == 0)
- return (-1 * (code ^ ((1 << dc_size) - 1)));
-
- return code;
-
-}
-
-//----------------------------
-
-int Bitstream::get_dc_size_lum(){
-
- int code = ShowBits(11);
-
- for(int i = 11; i > 3; i--) {
- if (code == 1) {
- Skip(i);
- return i + 1;
- }
- code >>= 1;
- }
-
- Skip(dc_lum_tab[code].len);
- return dc_lum_tab[code].code;
-
-}
-
-//----------------------------
-
-int Bitstream::get_dc_size_chrom(){
-
- dword code, i;
-
- code = ShowBits(12);
-
- for (i = 12; i > 2; i--) {
- if (code == 1) {
- Skip(i);
- return i;
- }
- code >>= 1;
- }
-
- return 3 - GetBits(2);
-
-}
-
-//----------------------------
-
-int S_decoder::get_coeff(Bitstream *bs, int *run, int *last, int intra, int short_video_header){
-
- dword mode;
- int level;
- REVERSE_EVENT *reverse_event;
-
- if(short_video_header) /* inter-VLCs will be used for both intra and inter blocks */
- intra = 0;
-
- if(bs->ShowBits(7) != ESCAPE){
- reverse_event = &DCT3D[intra][bs->ShowBits(12)];
-
- if((level = reverse_event->event.level) == 0)
- goto error;
-
- *last = reverse_event->event.last;
- *run = reverse_event->event.run;
-
- bs->Skip(reverse_event->len);
-
- return bs->GetBits(1) ? -level : level;
- }
-
- bs->Skip(7);
-
- if(short_video_header){
- //escape mode 4 - H.263 type, only used if short_video_header = 1
- *last = bs->GetBit();
- *run = bs->GetBits(6);
- level = bs->GetBits(8);
- if (level == 0 || level == 128)
- DPRINTF(XVID_DEBUG_ERROR, "Illegal LEVEL for ESCAPE mode 4: %d\n", level);
- return (level << 24) >> 24;
- }
-
- mode = bs->ShowBits(2);
- if(mode < 3){
- bs->Skip((mode == 2) ? 2 : 1);
-
- reverse_event = &DCT3D[intra][bs->ShowBits(12)];
-
- if((level = reverse_event->event.level) == 0)
- goto error;
- *last = reverse_event->event.last;
- *run = reverse_event->event.run;
- bs->Skip(reverse_event->len);
-
- if(mode < 2) /* first escape mode, level is offset */
- level += max_level[intra][*last][*run];
- else /* second escape mode, run is offset */
- *run += max_run[intra][*last][level] + 1;
- return bs->GetBits(1) ? -level : level;
- }
- //third escape mode - fixed length codes
- bs->Skip(2);
- *last = bs->GetBits(1);
- *run = bs->GetBits(6);
- bs->Skip(1); //marker
- level = bs->GetBits(12);
- bs->Skip(1); //marker
-
- return (level << 20) >> 20;
-
-error:
- *run = VLC_ERROR;
- return 0;
-}
-
-//----------------------------
-
-void S_decoder::get_intra_block(Bitstream *bs, int *block, int direction, int coeff){
-
- const dword *scan = scan_tables[direction];
- int last;
- do{
- int run;
- int level = get_coeff(bs, &run, &last, 1, 0);
- if(run == -1){
- DPRINTF(XVID_DEBUG_ERROR,"fatal: invalid run");
- break;
- }
- coeff += run;
- block[scan[coeff]] = level;
-
- //DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i\n", scan[coeff], level);
-
- if(level < -2047 || level > 2047){
- DPRINTF(XVID_DEBUG_ERROR,"warning: intra_overflow %i\n", level);
- }
- coeff++;
- } while(!last);
-}
-
-//----------------------------
-
-void S_decoder::get_inter_block(Bitstream * bs, int *block, int direction){
-
- const dword *scan = scan_tables[direction];
- int p = 0;
- int last;
- do{
- int run;
- int level = get_coeff(bs, &run, &last, 0, 0);
- if(run == -1){
- DPRINTF(XVID_DEBUG_ERROR,"fatal: invalid run");
- break;
- }
- p += run;
- block[scan[p]] = level;
-
- //DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i\n", scan[p], level);
-
- if(level < -2047 || level > 2047){
- DPRINTF(XVID_DEBUG_ERROR,"warning: inter overflow %i\n", level);
- }
- p++;
- } while(!last);
-}
-
-//----------------------------
-
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Prediction module -
- *
- * Copyright (C) 2001-2003 Michael Militzer <isibaar@xvid.org>
- * 2001-2003 Peter Ross <pross@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: mbprediction.cpp,v 1.1.1.1 2005-07-13 14:36:15 jeanlf Exp $
- *
- ****************************************************************************/
-
-#include "global.h"
-#include "mbprediction.h"
-
-//----------------------------
-
-#if 0
-
-#define Divide(a,b) (((a)>0) ? ((a)+((b)>>1))/(b) : ((a)-((b)>>1))/(b))
-
-#else
-
-#define RET_DIV(a, N) return (a*N+32768) >> 16;
-#define RET_SHR(a, N, S) return (a+N) >> S;
-
-static int Divide(int a, int b){
- switch(b){
- case 1: return a;
- case 2: return a >> 1;
- case 4: RET_SHR(a, 2, 2);
- case 8: RET_SHR(a, 4, 3);
- case 16: RET_SHR(a, 8, 4);
- case 32: RET_SHR(a, 16, 5);
- case 3: RET_DIV(a, 21845);
- case 5: RET_DIV(a, 13107);
- case 6: RET_DIV(a, 10923);
- case 7: RET_DIV(a, 9362);
- case 9: RET_DIV(a, 7282);
- case 10: RET_DIV(a, 6554);
- case 11: RET_DIV(a, 5958);
- case 12: RET_DIV(a, 5461);
- case 13: RET_DIV(a, 5041);
- case 14: RET_DIV(a, 4681);
- case 15: RET_DIV(a, 4369);
- case 17: RET_DIV(a, 3855);
- case 18: RET_DIV(a, 3641);
- case 19: RET_DIV(a, 3449);
- case 20: RET_DIV(a, 3277);
- case 21: RET_DIV(a, 3121);
- case 22: RET_DIV(a, 2979);
- case 23: RET_DIV(a, 2849);
- case 24: RET_DIV(a, 2731);
- case 25: RET_DIV(a, 2621);
- case 26: RET_DIV(a, 2521);
- case 27: RET_DIV(a, 2427);
- case 28: RET_DIV(a, 2341);
- case 29: RET_DIV(a, 2260);
- case 30: RET_DIV(a, 2185);
- case 31: RET_DIV(a, 2114);
- }
- return ((a>0) ? (a+(b>>1))/b : (a-(b>>1))/b);
-}
-#endif
-
-//----------------------------
-
-inline int rescale(int predict_quant, int current_quant, int coeff){
-
- if(!coeff)
- return 0;
- return Divide(coeff * predict_quant, current_quant);
-}
-
-//----------------------------
-
-static const int default_acdc_values[15] = {
- 1024,
- 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0
-};
-
-//----------------------------
-/* get dc/ac prediction direction for a single block and place
- predictor values into MB->pred_values[j][..]
-*/
-void predict_acdc(MACROBLOCK *pMBs, dword x, dword y, dword mb_width, dword block, int qcoeff[64], dword current_quant, int iDcScaler, int predictors[8], int bound){
-
- const int mbpos = (y * mb_width) + x;
- int *left, *top, *diag, *current;
-
- int left_quant = current_quant;
- int top_quant = current_quant;
-
- const int *pLeft = default_acdc_values;
- const int *pTop = default_acdc_values;
- const int *pDiag = default_acdc_values;
-
- dword index = x + y * mb_width; /* current macroblock */
- int *acpred_direction = &pMBs[index].acpred_directions[block];
- dword i;
-
- left = top = diag = current = 0;
-
- /* grab left,top and diag macroblocks */
-
- /* left macroblock */
-
- if (x && mbpos >= bound + 1 &&
- (pMBs[index - 1].mode == MODE_INTRA ||
- pMBs[index - 1].mode == MODE_INTRA_Q)) {
-
- left = pMBs[index - 1].pred_values[0];
- left_quant = pMBs[index - 1].quant;
- }
- /* top macroblock */
-
- if (mbpos >= bound + (int)mb_width &&
- (pMBs[index - mb_width].mode == MODE_INTRA ||
- pMBs[index - mb_width].mode == MODE_INTRA_Q)) {
-
- top = pMBs[index - mb_width].pred_values[0];
- top_quant = pMBs[index - mb_width].quant;
- }
- /* diag macroblock */
-
- if (x && mbpos >= bound + (int)mb_width + 1 &&
- (pMBs[index - 1 - mb_width].mode == MODE_INTRA ||
- pMBs[index - 1 - mb_width].mode == MODE_INTRA_Q)) {
-
- diag = pMBs[index - 1 - mb_width].pred_values[0];
- }
-
- current = pMBs[index].pred_values[0];
-
- /* now grab pLeft, pTop, pDiag _blocks_ */
-
- switch(block){
- case 0:
- if(left)
- pLeft = left + MBPRED_SIZE;
- if(top)
- pTop = top + (MBPRED_SIZE << 1);
- if(diag)
- pDiag = diag + 3 * MBPRED_SIZE;
- break;
-
- case 1:
- pLeft = current;
- left_quant = current_quant;
- if(top){
- pTop = top + 3 * MBPRED_SIZE;
- pDiag = top + (MBPRED_SIZE << 1);
- }
- break;
-
- case 2:
- if(left){
- pLeft = left + 3 * MBPRED_SIZE;
- pDiag = left + MBPRED_SIZE;
- }
- pTop = current;
- top_quant = current_quant;
- break;
-
- case 3:
- pLeft = current + (MBPRED_SIZE << 1);
- left_quant = current_quant;
- pTop = current + MBPRED_SIZE;
- top_quant = current_quant;
- pDiag = current;
- break;
-
- case 4:
- if(left)
- pLeft = left + (MBPRED_SIZE << 2);
- if(top)
- pTop = top + (MBPRED_SIZE << 2);
- if(diag)
- pDiag = diag + (MBPRED_SIZE << 2);
- break;
-
- case 5:
- if(left)
- pLeft = left + 5 * MBPRED_SIZE;
- if(top)
- pTop = top + 5 * MBPRED_SIZE;
- if(diag)
- pDiag = diag + 5 * MBPRED_SIZE;
- break;
- }
-
- /*
- * determine ac prediction direction & ac/dc predictor place rescaled ac/dc
- * predictions into predictors[] for later use
- */
-
- if(ABS(pLeft[0] - pDiag[0]) < ABS(pDiag[0] - pTop[0])){
- //vertical
- *acpred_direction = 1;
- predictors[0] = Divide(pTop[0], iDcScaler);
- for(i = 1; i < 8; i++)
- predictors[i] = rescale(top_quant, current_quant, pTop[i]);
- }else{
- //horizontal
- *acpred_direction = 2;
- predictors[0] = Divide(pLeft[0], iDcScaler);
- for(i = 1; i < 8; i++)
- predictors[i] = rescale(left_quant, current_quant, pLeft[i + 7]);
- }
-}
-
-//----------------------------
-/* decoder: add predictors to dct_codes[] and
- store current coeffs to pred_values[] for future prediction
-*/
-void add_acdc(MACROBLOCK *pMB, dword block, int dct_codes[64], dword iDcScaler, int predictors[8]){
-
- byte acpred_direction = pMB->acpred_directions[block];
- int *pCurrent = pMB->pred_values[block];
-
- DPRINTF(XVID_DEBUG_COEFF,"predictor[0] %i\n", predictors[0]);
-
- dct_codes[0] += predictors[0]; /* dc prediction */
- pCurrent[0] = dct_codes[0] * iDcScaler;
-
- if(acpred_direction == 1){
- for(int i = 1; i < 8; i++){
- int level = dct_codes[i] + predictors[i];
- //DPRINTF(XVID_DEBUG_COEFF,"predictor[%i] %i\n",i, predictors[i]);
- dct_codes[i] = level;
- pCurrent[i] = level;
- pCurrent[i + 7] = dct_codes[i * 8];
- }
- }else
- if(acpred_direction == 2){
- for(int i = 1; i < 8; i++){
- int level = dct_codes[i * 8] + predictors[i];
- //DPRINTF(XVID_DEBUG_COEFF,"predictor[%i] %i\n",i*8, predictors[i]);
- dct_codes[i * 8] = level;
- pCurrent[i + 7] = level;
- pCurrent[i] = dct_codes[i];
- }
- }else{
- for(int i = 1; i < 8; i++) {
- pCurrent[i] = dct_codes[i];
- pCurrent[i + 7] = dct_codes[i * 8];
- }
- }
-}
-
-//----------------------------
-
-static const VECTOR zeroMV = { 0, 0 };
-
-VECTOR get_pmv2(const MACROBLOCK * const mbs, const int mb_width, const int bound, const int x, const int y, const int block){
-
- int lx, ly, lz; /* left */
- int tx, ty, tz; /* top */
- int rx, ry, rz; /* top-right */
- int lpos, tpos, rpos;
- int num_cand = 0, last_cand = 1;
-
- VECTOR pmv[4]; /* left neighbour, top neighbour, top-right neighbour */
-
- switch(block){
- case 0:
- lx = x - 1; ly = y; lz = 1;
- tx = x; ty = y - 1; tz = 2;
- rx = x + 1; ry = y - 1; rz = 2;
- break;
- case 1:
- lx = x; ly = y; lz = 0;
- tx = x; ty = y - 1; tz = 3;
- rx = x + 1; ry = y - 1; rz = 2;
- break;
- case 2:
- lx = x - 1; ly = y; lz = 3;
- tx = x; ty = y; tz = 0;
- rx = x; ry = y; rz = 1;
- break;
- default:
- lx = x; ly = y; lz = 2;
- tx = x; ty = y; tz = 0;
- rx = x; ry = y; rz = 1;
- }
-
- lpos = lx + ly * mb_width;
- rpos = rx + ry * mb_width;
- tpos = tx + ty * mb_width;
-
- if(lpos >= bound && lx >= 0){
- num_cand++;
- pmv[1] = mbs[lpos].mvs[lz];
- }else
- pmv[1] = zeroMV;
-
- if(tpos >= bound){
- num_cand++;
- last_cand = 2;
- pmv[2] = mbs[tpos].mvs[tz];
- }else
- pmv[2] = zeroMV;
-
- if(rpos >= bound && rx < mb_width){
- num_cand++;
- last_cand = 3;
- pmv[3] = mbs[rpos].mvs[rz];
- }else
- pmv[3] = zeroMV;
-
- //if there're more than one candidate, we return the median vector
- if(num_cand > 1){
- //set median
- pmv[0].x =
- MIN(MAX(pmv[1].x, pmv[2].x),
- MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
- pmv[0].y =
- MIN(MAX(pmv[1].y, pmv[2].y),
- MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
- return pmv[0];
- }
-
- return pmv[last_cand]; //no point calculating median mv
-}
-
-//----------------------------
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Prediction header -
- *
- * Copyright(C) 2002-2003 xvid team <xvid-devel@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: mbprediction.h,v 1.1.1.1 2005-07-13 14:36:15 jeanlf Exp $
- *
- ****************************************************************************/
-
-
-#ifndef _MBPREDICTION_H_
-#define _MBPREDICTION_H_
-
-#include "portab.h"
-#include "decoder.h"
-#include "global.h"
-
-#define MIN(X, Y) ((X)<(Y)?(X):(Y))
-#define MAX(X, Y) ((X)>(Y)?(X):(Y))
-
-/* very large value */
-#define MV_MAX_ERROR (4096 * 256)
-
-#define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) )
-
-void add_acdc(MACROBLOCK *pMB, dword block, int dct_codes[64], dword iDcScaler, int predictors[8]);
-
-void predict_acdc(MACROBLOCK * pMBs, dword x, dword y, dword mb_width, dword block, int qcoeff[64], dword current_quant, int iDcScaler, int predictors[8], int bound);
-
-VECTOR
-get_pmv2(const MACROBLOCK * const mbs,
- const int mb_width,
- const int bound,
- const int x,
- const int y,
- const int block);
-
-#endif /* _MBPREDICTION_H_ */
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Aligned Memory Allocator -
- *
- * Copyright(C) 2002-2003 Edouard Gomez <ed.gomez@free.fr>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: mem_align.cpp,v 1.3 2010-02-23 16:23:32 jeanlf Exp $
- *
- ****************************************************************************/
-
-#include "mem_align.h"
-#include "global.h"
-
-#ifdef __SYMBIAN32__
-#include <e32std.h>
-#endif
-
-/*****************************************************************************
- * xvid_malloc
- *
- * This function allocates 'size' bytes (usable by the user) on the heap and
- * takes care of the requested 'alignment'.
- * In order to align the allocated memory block, the xvid_malloc allocates
- * 'size' bytes + 'alignment' bytes. So try to keep alignment very small
- * when allocating small pieces of memory.
- *
- * NB : a block allocated by xvid_malloc _must_ be freed with xvid_free
- * (the libc free will return an error)
- *
- * Returned value : - NULL on error
- * - Pointer to the allocated aligned block
- *
- ****************************************************************************/
-
-#include "Rules.h"
-
-void *xvid_malloc(long size, dword alignment){
-
- byte *mem_ptr;
-
-
- if (!alignment) {
-
- /* We have not to satisfy any alignment */
- //mem_ptr = (byte*)gf_malloc(size + 1);
- //mem_ptr = new(ELeave) byte[size+1];
- mem_ptr = new byte[size+1];
- if(mem_ptr) {
-
- /* Store (mem_ptr - "real allocated memory") in *(mem_ptr-1) */
- *mem_ptr = (byte)1;
-
- /* Return the mem_ptr pointer */
- return ((void *)(mem_ptr+1));
- }
- } else {
- byte *tmp;
-
- /* Allocate the required size memory + alignment so we
- * can realign the data if necessary */
- //tmp = (byte *) gf_malloc(size + alignment);
- //tmp = new(ELeave) byte[size + alignment];
- tmp = new byte[size + alignment];
- if(tmp) {
-
- /* Align the tmp pointer */
- mem_ptr =
- (byte *) ((dword)(tmp + alignment - 1) & (~(dword)(alignment - 1)));
-
- /* Special case where gf_malloc have already satisfied the alignment
- * We must add alignment to mem_ptr because we must store
- * (mem_ptr - tmp) in *(mem_ptr-1)
- * If we do not add alignment to mem_ptr then *(mem_ptr-1) points
- * to a forbidden memory space */
- if (mem_ptr == tmp)
- mem_ptr += alignment;
-
- /* (mem_ptr - tmp) is stored in *(mem_ptr-1) so we are able to retrieve
- * the real gf_malloc block allocated and free it in xvid_free */
- *(mem_ptr - 1) = (byte) (mem_ptr - tmp);
-
- /* Return the aligned pointer */
- return ((void *)mem_ptr);
- }
- }
- return 0;
-}
-
-/*****************************************************************************
- * xvid_free
- *
- * Free a previously 'xvid_malloc' allocated block. Does not free NULL
- * references.
- *
- * Returned value : None.
- *
- ****************************************************************************/
-
-void xvid_free(void *mem_ptr){
-
- if(!mem_ptr)
- return;
-
- /* Aligned pointer */
- byte *ptr = (byte*)mem_ptr;
-
- /* *(ptr - 1) holds the offset to the real allocated block
- * we sub that offset os we free the real pointer */
- ptr -= *(ptr - 1);
-
- /* Free the memory */
- //free(ptr);
- delete[] ptr;
-}
-
-//----------------------------
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Aligned Memory Allocator header -
- *
- * Copyright(C) 2002-2003 Edouard Gomez <ed.gomez@free.fr>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: mem_align.h,v 1.1.1.1 2005-07-13 14:36:15 jeanlf Exp $
- *
- ****************************************************************************/
-
-#ifndef _MEM_ALIGN_H_
-#define _MEM_ALIGN_H_
-
-#include "portab.h"
-#include "Rules.h"
-
-void *xvid_malloc(long size, dword alignment);
-void xvid_free(void *mem_ptr);
-
-#endif /* _MEM_ALIGN_H_ */
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - 8bit<->16bit transfer -
- *
- * Copyright(C) 2001-2003 Peter Ross <pross@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: mem_transfer.cpp,v 1.1.1.1 2005-07-13 14:36:16 jeanlf Exp $
- *
- ****************************************************************************/
-
-#include "global.h"
-#include "mem_transfer.h"
-
-/*****************************************************************************
- *
- * All these functions are used to transfer data from a 8 bit data array
- * to a 16 bit data array.
- *
- * This is typically used during motion compensation, that's why some
- * functions also do the addition/substraction of another buffer during the
- * so called transfer.
- *
- ****************************************************************************/
-
-//----------------------------
-/*
- * SRC - the source buffer
- * DST - the destination buffer
- *
- * Then the function does the 8->16 bit transfer and this serie of operations :
- *
- * SRC (16bit) = SRC
- * DST (8bit) = max(min(SRC, 255), 0)
- */
-void transfer_16to8copy(byte *dst, const int *src, dword stride){
-
- for(int j = 0; j < 8; j++){
- for(int i = 0; i < 8; i++){
- int pixel = *src++;
-
- if(pixel < 0)
- pixel = 0;
- //else
- if(pixel > 255)
- pixel = 255;
- dst[i] = byte(pixel);
- }
- dst += stride;
- }
-}
-
-//----------------------------
-/*
- * SRC - the source buffer
- * DST - the destination buffer
- *
- * Then the function does the 16->8 bit transfer and this serie of operations :
- *
- * SRC (16bit) = SRC
- * DST (8bit) = max(min(DST+SRC, 255), 0)
- */
-void transfer_16to8add(byte *dst, const int *src, dword stride){
-
- for(int j = 0; j < 8; j++){
- for(int i = 0; i < 8; i++){
- int pixel = dst[i] + *src++;
-
- if(pixel < 0)
- pixel = 0;
- //else
- if(pixel > 255)
- pixel = 255;
- dst[i] = byte(pixel);
- }
- //src += 8;
- dst += stride;
- }
-}
-
-#ifndef _ARM_
-//----------------------------
-/*
- * SRC - the source buffer
- * DST - the destination buffer
- *
- * Then the function does the 8->8 bit transfer and this serie of operations :
- *
- * SRC (8bit) = SRC
- * DST (8bit) = SRC
- */
-void transfer8x8_copy(byte *dst, const byte *src, dword stride){
-
- assert(!(stride&3));
- assert(!(dword(dst)&3));
-#if defined USE_ARM_ASM && 1
- int y, tmp, tmp1;
-
-#define NL "add %0, %0, %4\n add %1, %1, %4\n\t"
- asm volatile(
- "orr %2, %1, %4\n\t"
- "tst %2, #3\n bne .tc_no_dw\n\t"
- //dword version
- "\n.tc_dw_loop:\n\t"
-#define COPY_QW "ldmia %1, { %2, %3 }\n stmia %0, { %2, %3 }\n\t"
- COPY_QW NL COPY_QW NL COPY_QW NL COPY_QW NL COPY_QW NL COPY_QW NL COPY_QW NL COPY_QW
- "b .tc_end\n\t"
-
- "\n.tc_no_dw:\n\t"
- "tst %2, #1\n bne .tc_no_w\n\t"
- //word version
- "\n.tc_w_loop:\n\t"
-#define COPY_W \
- "ldrh %2, [%1, #0]\n strh %2, [%0, #0]\n\t" \
- "ldrh %2, [%1, #2]\n strh %2, [%0, #2]\n\t" \
- "ldrh %2, [%1, #4]\n strh %2, [%0, #4]\n\t" \
- "ldrh %2, [%1, #6]\n strh %2, [%0, #6]\n\t"
- COPY_W NL COPY_W NL COPY_W NL COPY_W NL COPY_W NL COPY_W NL COPY_W NL COPY_W
- "b .tc_end\n\t"
-
- "\n.tc_no_w:\n\t"
- "mov %5, #8\n\t"
- "\n.tc_b_loop:\n\t"
- "ldrb %2, [%1, #0]\n strb %2, [%0, #0]\n\t"
- "ldrb %2, [%1, #1]\n strb %2, [%0, #1]\n\t"
- "ldrb %2, [%1, #2]\n strb %2, [%0, #2]\n\t"
- "ldrb %2, [%1, #3]\n strb %2, [%0, #3]\n\t"
- "ldrb %2, [%1, #4]\n strb %2, [%0, #4]\n\t"
- "ldrb %2, [%1, #5]\n strb %2, [%0, #5]\n\t"
- "ldrb %2, [%1, #6]\n strb %2, [%0, #6]\n\t"
- "ldrb %2, [%1, #7]\n strb %2, [%0, #7]\n\t"
- NL
- "subs %5, %5, #1\n bne .tc_b_loop\n\t"
- "\n.tc_end:\n\t"
- : "+r"(dst), "+r"(src), "&=r"(tmp), "&=r"(tmp1)
- : "r"(stride), "r"(y)
- );
-#else
- if(!(dword(src)&3) && !(dword(dst)&3)){
- for(dword y = 8; y--; ){
- ((dword*)dst)[0] = ((dword*)src)[0];
- ((dword*)dst)[1] = ((dword*)src)[1];
-
- src += stride;
- dst += stride;
- }
- }else
- if(!(dword(src)&1) && !(dword(dst)&1)){
- for(dword y = 8; y--; ){
- ((word*)dst)[0] = ((word*)src)[0];
- ((word*)dst)[1] = ((word*)src)[1];
- ((word*)dst)[2] = ((word*)src)[2];
- ((word*)dst)[3] = ((word*)src)[3];
-
- src += stride;
- dst += stride;
- }
- }else{
- for(dword y = 8; y--; ){
- dst[0] = src[0];
- dst[1] = src[1];
- dst[2] = src[2];
- dst[3] = src[3];
- dst[4] = src[4];
- dst[5] = src[5];
- dst[6] = src[6];
- dst[7] = src[7];
-
- src += stride;
- dst += stride;
- }
- }
-#endif
-}
-#endif
-
-//----------------------------
-#ifndef PROFILE
-
-#ifdef __SYMBIAN32__
-
-#include <e32base.h>
-
-void MemSet(void *dst, byte c, dword len){
- Mem::Fill(dst, len, c);
-}
-
-//----------------------------
-
-void MemCpy(void *dst, const void *src, dword len){
- Mem::Copy(dst, src, len);
-}
-
-//----------------------------
-
-int MemCmp(const void *mem1, const void *mem2, dword len){
- return Mem::Compare((byte*)mem1, len, (byte*)mem2, len);
-}
-
-//----------------------------
-
-dword StrLen(const char *cp){ return User::StringLength((const byte*)cp); }
-
-//----------------------------
-
-void Fatal(const char *msg, dword code){
-
- int len = StrLen(msg);
- TBuf16<20> desc; desc.Copy(TPtr8((byte*)msg, Min(len, 20), len));
- User::Panic(desc, code);
-}
-
-
-#else
-
-//----------------------------
-#include <memory.h>
-#include <stdio.h>
-
-void MemSet(void *dst, byte c, dword len){
- memset(dst, c, len);
-}
-
-//----------------------------
-
-void MemCpy(void *dst, const void *src, dword len){
- memcpy(dst, src, len);
-}
-
-//----------------------------
-
-int MemCmp(const void *mem1, const void *mem2, dword len){
- return memcmp(mem1, mem2, len);
-}
-
-//----------------------------
-
-void *operator new(size_t sz, TLeave){
- void *vp = new byte[sz];
- if(!vp){
- //todo: fatal error
- Fatal("Not enough memory", sz);
- }
- return vp;
-}
-
-//----------------------------
-#include <windows.h>
-
-void Fatal(const char *msg, dword code){
-
-#ifdef _WIN32_WCE
- wchar_t buf[256];
- swprintf(buf, L"%i (%i)", msg, code);
- MessageBox(NULL, buf, L"Fatal error", MB_OK | MB_ICONERROR);
-#else
- char buf[256];
- sprintf(buf, "%i (%i)", msg, code);
- MessageBox(NULL, buf, "Fatal error", MB_OK | MB_ICONERROR);
-#endif
- exit(1);
-}
-
-//----------------------------
-#endif
-#endif
-//----------------------------
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - 8<->16 bit buffer transfer header -
- *
- * Copyright(C) 2001-2003 Peter Ross <pross@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: mem_transfer.h,v 1.1.1.1 2005-07-13 14:36:16 jeanlf Exp $
- *
- ****************************************************************************/
-
-#ifndef _MEM_TRANSFER_H
-#define _MEM_TRANSFER_H
-
-#include "Rules.h"
-
-/*****************************************************************************
- * transfer16to8 API
- ****************************************************************************/
-void transfer_16to8copy(byte *dst, const int *src, dword stride);
-
-/*****************************************************************************
- * transfer16to8 + addition op API
- ****************************************************************************/
-void transfer_16to8add(byte *dst, const int *src, dword stride);
-
-/*****************************************************************************
- * transfer8to8 + no op
- ****************************************************************************/
-#ifdef _ARM_
-extern"C"
-#endif
-void transfer8x8_copy(byte *const dst, const byte * const src, const dword stride);
-
-//----------------------------
-
-inline void transfer16x16_copy(byte * const dst, const byte * const src, const dword stride){
-
- transfer8x8_copy(dst, src, stride);
- transfer8x8_copy(dst + 8, src + 8, stride);
- transfer8x8_copy(dst + 8*stride, src + 8*stride, stride);
- transfer8x8_copy(dst + 8*stride + 8, src + 8*stride + 8, stride);
-}
-
-//----------------------------
-
-#endif
+++ /dev/null
-This is not original version of XviD codec.
-To obtain official source code for XviD, please visit www.xvid.org.
-This is a modified version of the original software.
-
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Portable macros, types and inlined assembly -
- *
- * Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>
- * 2002-2003 Peter Ross <pross@xvid.org>
- * 2002-2003 Edouard Gomez <ed.gomez@free.fr>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: portab.h,v 1.1.1.1 2005-07-13 14:36:16 jeanlf Exp $
- *
- ****************************************************************************/
-
-#ifndef _PORTAB_H_
-#define _PORTAB_H_
-
-#include "Rules.h"
-
-#define ARCH_IS_LITTLE_ENDIAN
-#define ARCH_IS_GENERIC
-
-
-/*****************************************************************************
- * Common things
- ****************************************************************************/
-
-/* Buffer size for msvc implementation because it outputs to DebugOutput */
-#ifdef _DEBUG
-extern dword xvid_debug;
-#define DPRINTF_BUF_SZ 1024
-#endif
-
-/*****************************************************************************
- * Types used in XviD sources
- ****************************************************************************/
-
-/*----------------------------------------------------------------------------
- | For MSVC
- *---------------------------------------------------------------------------*/
-
-//#if defined(_MSC_VER) || defined (__WATCOMC__)
-#define int64_t int
-
-/*----------------------------------------------------------------------------
- | For all other compilers, use the standard header file
- | (compiler should be ISO C99 compatible, perhaps ISO C89 is enough)
- *---------------------------------------------------------------------------*/
-
-//#endif
-
-/*****************************************************************************
- * Some things that are only architecture dependant
- ****************************************************************************/
-
-#define CACHE_LINE 32
-
-/*****************************************************************************
- * MSVC compiler specific macros, functions
- ****************************************************************************/
-
-#ifdef _MSC_VER
-
-/*----------------------------------------------------------------------------
- | Common msvc stuff
- *---------------------------------------------------------------------------*/
-
- /*
- * This function must be declared/defined all the time because MSVC does
- * not support C99 variable arguments macros.
- *
- * Btw, if the MS compiler does its job well, it should remove the nop
- * DPRINTF function when not compiling in _DEBUG mode
- */
-#if defined _DEBUG && defined _WINDOWS
-
-void DPRINTF(int level, char *fmt, int p=0);
-
-#else
-
-inline void DPRINTF(int level, char *fmt, int p=0){}
-
-#endif
-
-
-/*****************************************************************************
- * GNU CC compiler stuff
- ****************************************************************************/
-
-#elif defined __GNUC__ || defined __ICC /* Compiler test */
-
-/*----------------------------------------------------------------------------
- | Common gcc stuff
- *---------------------------------------------------------------------------*/
-
-/*
- * As gcc is (mostly) C99 compliant, we define DPRINTF only if it's realy needed
- * and it's a macro calling fprintf directly
- */
-# ifdef _DEBUG
-
- /* Needed for all debuf fprintf calls */
-# include <stdio.h>
-# include <stdarg.h>
-
- inline void DPRINTF(int level, char *format, int p=0){
- va_list args;
- va_start(args, format);
- if(xvid_debug & level){
- vfprintf(stderr, format, args);
- }
- }
-
-# else /* _DEBUG */
-inline void DPRINTF(int level, char *format, int p=0) {}
-# endif /* _DEBUG */
-
-#else //Compiler test
-
- /*
- * Ok we know nothing about the compiler, so we fallback to ANSI C
- * features, so every compiler should be happy and compile the code.
- *
- * This is (mostly) equivalent to ARCH_IS_GENERIC.
- */
-
-#ifdef _DEBUG
- /* Needed for all debuf fprintf calls */
-# include <stdio.h>
-# include <stdarg.h>
-
-static __inline void DPRINTF(int level, char *format, int p=0){
- va_list args;
- va_start(args, format);
- if(xvid_debug & level) {
- vfprintf(stderr, format, args);
- }
-}
-
-# else //_DEBUG
-inline void DPRINTF(int level, char *format, int p=0){}
-#endif //_DEBUG
-
-#define ByteSwap(a) \
- ((a) = ((a) << 24) | (((a) & 0xff00) << 8) | (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
-
-#define DECLARE_ALIGNED_MATRIX(name, sizex, sizey, type, alignment) \
- type name[(sizex)*(sizey)]
-
-#endif //Compiler test
-
-
-#endif /* PORTAB_H */
+++ /dev/null
-static void FUNC_H(byte *Dst, const byte *Src, int H, int BpS, int Rnd){
- while(H-->0) {
- int i, k;
- int Sums[SIZE] = { 0 };
- for(i=0; i<=SIZE; ++i)
- for(k=0; k<SIZE; ++k)
- Sums[k] += TABLE[i][k] * Src[i];
-
- for(i=0; i<SIZE; ++i) {
- int C = ( Sums[i] + 16-Rnd ) >> 5;
- if (C<0) C = 0; else if (C>255) C = 255;
- STORE(Dst[i], C);
- }
- Src += BpS;
- Dst += BpS;
- }
-}
-
-static void FUNC_V(byte *Dst, const byte *Src, int W, int BpS, int Rnd){
- while(W-->0) {
- int i, k;
- int Sums[SIZE] = { 0 };
- const byte *S = Src++;
- byte *D = Dst++;
- for(i=0; i<=SIZE; ++i) {
- for(k=0; k<SIZE; ++k)
- Sums[k] += TABLE[i][k] * S[0];
- S += BpS;
- }
-
- for(i=0; i<SIZE; ++i) {
- int C = ( Sums[i] + 16-Rnd )>>5;
- if (C<0) C = 0; else if (C>255) C = 255;
- STORE(D[0], C);
- D += BpS;
- }
- }
-}
-
-static
-void FUNC_HA(byte *Dst, const byte *Src, int H, int BpS, int Rnd)
-{
- while(H-->0) {
- int i, k;
- int Sums[SIZE] = { 0 };
- for(i=0; i<=SIZE; ++i)
- for(k=0; k<SIZE; ++k)
- Sums[k] += TABLE[i][k] * Src[i];
-
- for(i=0; i<SIZE; ++i) {
- int C = ( Sums[i] + 16-Rnd ) >> 5;
- if (C<0) C = 0; else if (C>255) C = 255;
- C = (C+Src[i]+1-Rnd) >> 1;
- STORE(Dst[i], C);
- }
- Src += BpS;
- Dst += BpS;
- }
-}
-
-static
-void FUNC_HA_UP(byte *Dst, const byte *Src, int H, int BpS, int Rnd)
-{
- while(H-->0) {
- int i, k;
- int Sums[SIZE] = { 0 };
- for(i=0; i<=SIZE; ++i)
- for(k=0; k<SIZE; ++k)
- Sums[k] += TABLE[i][k] * Src[i];
-
- for(i=0; i<SIZE; ++i) {
- int C = ( Sums[i] + 16-Rnd ) >> 5;
- if (C<0) C = 0; else if (C>255) C = 255;
- C = (C+Src[i+1]+1-Rnd) >> 1;
- STORE(Dst[i], C);
- }
- Src += BpS;
- Dst += BpS;
- }
-}
-
-static
-void FUNC_VA(byte *Dst, const byte *Src, int W, int BpS, int Rnd)
-{
- while(W-->0) {
- int i, k;
- int Sums[SIZE] = { 0 };
- const byte *S = Src;
- byte *D = Dst;
-
- for(i=0; i<=SIZE; ++i) {
- for(k=0; k<SIZE; ++k)
- Sums[k] += TABLE[i][k] * S[0];
- S += BpS;
- }
-
- S = Src;
- for(i=0; i<SIZE; ++i) {
- int C = ( Sums[i] + 16-Rnd )>>5;
- if (C<0) C = 0; else if (C>255) C = 255;
- C = ( C+S[0]+1-Rnd ) >> 1;
- STORE(D[0], C);
- D += BpS;
- S += BpS;
- }
- Src++;
- Dst++;
- }
-}
-
-static
-void FUNC_VA_UP(byte *Dst, const byte *Src, int W, int BpS, int Rnd)
-{
- while(W-->0) {
- int i, k;
- int Sums[SIZE] = { 0 };
- const byte *S = Src;
- byte *D = Dst;
-
- for(i=0; i<=SIZE; ++i) {
- for(k=0; k<SIZE; ++k)
- Sums[k] += TABLE[i][k] * S[0];
- S += BpS;
- }
-
- S = Src + BpS;
- for(i=0; i<SIZE; ++i) {
- int C = ( Sums[i] + 16-Rnd )>>5;
- if (C<0) C = 0; else if (C>255) C = 255;
- C = ( C+S[0]+1-Rnd ) >> 1;
- STORE(D[0], C);
- D += BpS;
- S += BpS;
- }
- Dst++;
- Src++;
- }
-}
-
-#undef STORE
-#undef FUNC_H
-#undef FUNC_V
-#undef FUNC_HA
-#undef FUNC_VA
-#undef FUNC_HA_UP
-#undef FUNC_VA_UP
+++ /dev/null
-#include "portab.h"
-
-//----------------------------
-// Quarterpel FIR definition
-
-static const int FIR_Tab_16[17][16] = {
- { 14, -3, 2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 23, 19, -6, 3, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
- { -7, 20, 20, -6, 3, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 3, -6, 20, 20, -6, 3, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
- { -1, 3, -6, 20, 20, -6, 3, -1, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 0, -1, 3, -6, 20, 20, -6, 3, -1, 0, 0, 0, 0, 0, 0, 0 },
- { 0, 0, -1, 3, -6, 20, 20, -6, 3, -1, 0, 0, 0, 0, 0, 0 },
- { 0, 0, 0, -1, 3, -6, 20, 20, -6, 3, -1, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 0, -1, 3, -6, 20, 20, -6, 3, -1, 0, 0, 0, 0 },
- { 0, 0, 0, 0, 0, -1, 3, -6, 20, 20, -6, 3, -1, 0, 0, 0 },
- { 0, 0, 0, 0, 0, 0, -1, 3, -6, 20, 20, -6, 3, -1, 0, 0 },
- { 0, 0, 0, 0, 0, 0, 0, -1, 3, -6, 20, 20, -6, 3, -1, 0 },
- { 0, 0, 0, 0, 0, 0, 0, 0, -1, 3, -6, 20, 20, -6, 3, -1 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 3, -6, 20, 20, -6, 3 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 3, -6, 20, 20, -7 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 3, -6, 19, 23 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 2, -3, 14 }
-};
-
-static const int FIR_Tab_8[9][8] = {
- { 14, -3, 2, -1, 0, 0, 0, 0 },
- { 23, 19, -6, 3, -1, 0, 0, 0 },
- { -7, 20, 20, -6, 3, -1, 0, 0 },
- { 3, -6, 20, 20, -6, 3, -1, 0 },
- { -1, 3, -6, 20, 20, -6, 3, -1 },
- { 0, -1, 3, -6, 20, 20, -6, 3 },
- { 0, 0, -1, 3, -6, 20, 20, -7 },
- { 0, 0, 0, -1, 3, -6, 19, 23 },
- { 0, 0, 0, 0, -1, 2, -3, 14 }
-};
-
-
-//----------------------------
-
-/* Implementation
- ****************************************************************************/
-
-/* 16x? filters */
-
-#define SIZE 16
-#define TABLE FIR_Tab_16
-
-#define STORE(d,s) (d) = (s)
-#define FUNC_H H_Pass_16_C
-#define FUNC_V V_Pass_16_C
-#define FUNC_HA H_Pass_Avrg_16_C
-#define FUNC_VA V_Pass_Avrg_16_C
-#define FUNC_HA_UP H_Pass_Avrg_Up_16_C
-#define FUNC_VA_UP V_Pass_Avrg_Up_16_C
-
-#include "qpel.inl"
-
-/* note: B-frame always uses Rnd=0... */
-#define STORE(d,s) (d) = ( (s)+(d)+1 ) >> 1
-#define FUNC_H H_Pass_16_Add_C
-#define FUNC_V V_Pass_16_Add_C
-#define FUNC_HA H_Pass_Avrg_16_Add_C
-#define FUNC_VA V_Pass_Avrg_16_Add_C
-#define FUNC_HA_UP H_Pass_Avrg_Up_16_Add_C
-#define FUNC_VA_UP V_Pass_Avrg_Up_16_Add_C
-
-#include "qpel.inl"
-
-#undef SIZE
-#undef TABLE
-
-/* 8x? filters */
-
-#define SIZE 8
-#define TABLE FIR_Tab_8
-
-#define STORE(d,s) (d) = (s)
-#define FUNC_H H_Pass_8_C
-#define FUNC_V V_Pass_8_C
-#define FUNC_HA H_Pass_Avrg_8_C
-#define FUNC_VA V_Pass_Avrg_8_C
-#define FUNC_HA_UP H_Pass_Avrg_Up_8_C
-#define FUNC_VA_UP V_Pass_Avrg_Up_8_C
-
-#include "qpel.inl"
-
-/* note: B-frame always uses Rnd=0... */
-#define STORE(d,s) (d) = ( (s)+(d)+1 ) >> 1
-#define FUNC_H H_Pass_8_Add_C
-#define FUNC_V V_Pass_8_Add_C
-#define FUNC_HA H_Pass_Avrg_8_Add_C
-#define FUNC_VA V_Pass_Avrg_8_Add_C
-#define FUNC_HA_UP H_Pass_Avrg_Up_8_Add_C
-#define FUNC_VA_UP V_Pass_Avrg_Up_8_Add_C
-
-#include "qpel.inl"
-
-#undef SIZE
-#undef TABLE
-
-//----------------------------
-
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - (de)Quantization related header -
- *
- * Copyright(C) 2003 Edouard Gomez <ed.gomez@free.fr>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: quant.h,v 1.1.1.1 2005-07-13 14:36:16 jeanlf Exp $
- *
- ****************************************************************************/
-
-#ifndef _QUANT_H_
-#define _QUANT_H_
-
-#include "portab.h"
-
-/*****************************************************************************
- * Common API for Intra (de)Quant functions
- ****************************************************************************/
-
-typedef void (quant_intraFunc)(int *coeff, const int *data, dword quant, dword dcscalar, const dword *mpeg_quant_matrices);
-
-typedef quant_intraFunc *quant_intraFuncPtr;
-
-/* DeQuant functions */
-quant_intraFunc dequant_h263_intra;
-quant_intraFunc dequant_mpeg_intra;
-
-/*****************************************************************************
- * Common API for Inter (de)Quant functions
- ****************************************************************************/
-
-typedef void (quant_interFunc)(int *coeff, const int* data, dword quant, const dword *mpeg_quant_matrices);
-
-typedef quant_interFunc *quant_interFuncPtr;
-
-quant_interFunc dequant_h263_inter;
-quant_interFunc dequant_mpeg_inter;
-
-#endif /* _QUANT_H_ */
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - MPEG4 Quantization H263 implementation -
- *
- * Copyright(C) 2001-2003 Peter Ross <pross@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: quant_h263.cpp,v 1.1.1.1 2005-07-13 14:36:16 jeanlf Exp $
- *
- ****************************************************************************/
-
-#include "global.h"
-#include "quant.h"
-
-//----------------------------
-/* dequantize intra-block & clamp to [-2048,2047]
- */
-void dequant_h263_intra(int *data, const int *coeff, dword quant, dword dcscalar, const dword *mpeg_quant_matrices){
-
- const int quant_m_2 = quant << 1;
- const int quant_add = (quant & 1 ? quant : quant - 1);
-
- data[0] = *coeff++ * dcscalar;
- if(data[0] < -2048){
- data[0] = -2048;
- }//else
- if(data[0] > 2047){
- data[0] = 2047;
- }
- for(int i = 1; i < 64; i++){
- int acLevel = *coeff++;
-
- if(acLevel == 0){
- data[i] = 0;
- }else
- if(acLevel < 0){
- acLevel = quant_m_2 * -acLevel + quant_add;
- data[i] = (acLevel <= 2048 ? -acLevel : -2048);
- }else{
- acLevel = quant_m_2 * acLevel + quant_add;
- data[i] = (acLevel <= 2047 ? acLevel : 2047);
- }
- }
-}
-
-//----------------------------
-/* dequantize inter-block & clamp to [-2048,2047]
- */
-
-void dequant_h263_inter(int *data, const int *coeff, dword quant, const dword *mpeg_quant_matrices){
-
- const dword quant_m_2 = quant << 1;
- const dword quant_add = (quant & 1 ? quant : quant - 1);
-
- for(int i = 0; i < 64; i++){
- int acLevel = *coeff++;
-
- if(acLevel == 0){
- data[i] = 0;
- }else
- if(acLevel < 0){
- acLevel = acLevel * quant_m_2 - quant_add;
- data[i] = (acLevel >= -2048 ? acLevel : -2048);
- }else{
- acLevel = acLevel * quant_m_2 + quant_add;
- data[i] = (acLevel <= 2047 ? acLevel : 2047);
- }
- }
-}
-
-//----------------------------
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Quantization matrix management code -
- *
- * Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>
- * 2002 Peter Ross <pross@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: quant_matrix.cpp,v 1.1.1.1 2005-07-13 14:36:16 jeanlf Exp $
- *
- ****************************************************************************/
-
-#include "quant_matrix.h"
-
-#define FIX(X) (((X)==1) ? 0xFFFF : ((1UL << 16) / (X) + 1))
-#define FIXL(X) ((1UL << 16) / (X) - 1)
-
-/*****************************************************************************
- * Default matrices
- ****************************************************************************/
-
-static const byte default_intra_matrix[64] = {
- 8, 17, 18, 19, 21, 23, 25, 27,
- 17, 18, 19, 21, 23, 25, 27, 28,
- 20, 21, 22, 23, 24, 26, 28, 30,
- 21, 22, 23, 24, 26, 28, 30, 32,
- 22, 23, 24, 26, 28, 30, 32, 35,
- 23, 24, 26, 28, 30, 32, 35, 38,
- 25, 26, 28, 30, 32, 35, 38, 41,
- 27, 28, 30, 32, 35, 38, 41, 45
-};
-
-//----------------------------
-
-static const byte default_inter_matrix[64] = {
- 16, 17, 18, 19, 20, 21, 22, 23,
- 17, 18, 19, 20, 21, 22, 23, 24,
- 18, 19, 20, 21, 22, 23, 24, 25,
- 19, 20, 21, 22, 23, 24, 26, 27,
- 20, 21, 22, 23, 25, 26, 27, 28,
- 21, 22, 23, 24, 26, 27, 28, 30,
- 22, 23, 24, 26, 27, 28, 30, 31,
- 23, 24, 25, 27, 28, 30, 31, 33
-};
-
-//----------------------------
-
-const byte *get_default_intra_matrix(){
- return default_intra_matrix;
-}
-
-//----------------------------
-
-const byte *get_default_inter_matrix(){
- return default_inter_matrix;
-}
-
-//----------------------------
-
-void set_intra_matrix(dword *mpeg_quant_matrices, const byte *matrix){
-
- dword *intra_matrix = mpeg_quant_matrices + 0*64;
- dword *intra_matrix1 = mpeg_quant_matrices + 1*64;
- dword *intra_matrix_fix = mpeg_quant_matrices + 2*64;
- dword *intra_matrix_fixl = mpeg_quant_matrices + 3*64;
-
- for(int i = 0; i < 64; i++) {
- intra_matrix[i] = (!i) ? 8 : matrix[i];
- intra_matrix1[i] = (intra_matrix[i]>>1);
- intra_matrix1[i] += ((intra_matrix[i] == 1) ? 1: 0);
- intra_matrix_fix[i] = FIX(intra_matrix[i]);
- intra_matrix_fixl[i] = FIXL(intra_matrix[i]);
- }
-}
-
-//----------------------------
-
-void set_inter_matrix(dword *mpeg_quant_matrices, const byte *matrix){
-
- dword *inter_matrix = mpeg_quant_matrices + 4*64;
- dword *inter_matrix1 = mpeg_quant_matrices + 5*64;
- dword *inter_matrix_fix = mpeg_quant_matrices + 6*64;
- dword *inter_matrix_fixl = mpeg_quant_matrices + 7*64;
-
- for(int i = 0; i < 64; i++){
- inter_matrix1[i] = ((inter_matrix[i] = matrix[i])>>1);
- inter_matrix1[i] += ((inter_matrix[i] == 1) ? 1: 0);
- inter_matrix_fix[i] = FIX(inter_matrix[i]);
- inter_matrix_fixl[i] = FIXL(inter_matrix[i]);
- }
-}
-
-//----------------------------
-
-void init_mpeg_matrix(dword *mpeg_quant_matrices){
-
- set_intra_matrix(mpeg_quant_matrices, default_intra_matrix);
- set_inter_matrix(mpeg_quant_matrices, default_inter_matrix);
-}
-
-//----------------------------
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Quantization matrix management header -
- *
- * Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>
- * 2002 Peter Ross <pross@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: quant_matrix.h,v 1.1.1.1 2005-07-13 14:36:16 jeanlf Exp $
- *
- ****************************************************************************/
-
-#ifndef _QUANT_MATRIX_H_
-#define _QUANT_MATRIX_H_
-
-#include "portab.h"
-#include "Rules.h"
-
-void init_mpeg_matrix(dword *mpeg_quant_matrices);
-
-void set_intra_matrix(dword *mpeg_quant_matrices, const byte *matrix);
-void set_inter_matrix(dword *mpeg_quant_matrices, const byte *matrix);
-
-inline const dword *get_intra_matrix(const dword *mpeg_quant_matrices){ return (mpeg_quant_matrices + 0*64); }
-inline const dword *get_inter_matrix(const dword *mpeg_quant_matrices){ return(mpeg_quant_matrices + 4*64); }
-
-const byte *get_default_intra_matrix(void);
-const byte *get_default_inter_matrix(void);
-
-#endif /* _QUANT_MATRIX_H_ */
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - MPEG4 Quantization related header -
- *
- * Copyright(C) 2001-2003 Peter Ross <pross@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: quant_mpeg.cpp,v 1.1.1.1 2005-07-13 14:36:16 jeanlf Exp $
- *
- ****************************************************************************/
-
-#include "global.h"
-#include "quant.h"
-#include "quant_matrix.h"
-
-//----------------------------
-/* dequantize intra-block & clamp to [-2048,2047]
- *
- * data[i] = (coeff[i] * default_intra_matrix[i] * quant2) >> 4;
- */
-void dequant_mpeg_intra(int *data, const int *coeff, dword quant, dword dcscalar, const dword *mpeg_quant_matrices){
-
- const dword *intra_matrix = get_intra_matrix(mpeg_quant_matrices);
-
- data[0] = coeff[0] * dcscalar;
- if(data[0] < -2048){
- data[0] = -2048;
- }else
- if(data[0] > 2047){
- data[0] = 2047;
- }
-
- for(int i = 1; i < 64; i++){
- if(coeff[i] == 0){
- data[i] = 0;
- }else
- if(coeff[i] < 0){
- int level = -coeff[i];
-
- level = (level * intra_matrix[i] * quant) >> 3;
- data[i] = (level <= 2048 ? -level : -2048);
- }else{
- dword level = coeff[i];
-
- level = (level * intra_matrix[i] * quant) >> 3;
- data[i] = (level <= 2047 ? level : 2047);
- }
- }
-}
-
-//----------------------------
-/* dequantize inter-block & clamp to [-2048,2047]
- * data = ((2 * coeff + SIGN(coeff)) * inter_matrix[i] * quant) / 16
- */
-
-void dequant_mpeg_inter(int *data, const int *coeff, dword quant, const dword *mpeg_quant_matrices){
-
- dword sum = 0;
- const dword *inter_matrix = get_inter_matrix(mpeg_quant_matrices);
-
- for(int i = 0; i < 64; i++){
- if(coeff[i] == 0){
- data[i] = 0;
- }else
- if(coeff[i] < 0){
- int level = -coeff[i];
-
- level = ((2 * level + 1) * inter_matrix[i] * quant) >> 4;
- data[i] = (level <= 2048 ? -level : -2048);
- }else{
- dword level = coeff[i];
- level = ((2 * level + 1) * inter_matrix[i] * quant) >> 4;
- data[i] = (level <= 2047 ? level : 2047);
- }
- sum ^= data[i];
- }
- /* mismatch control */
- if ((sum & 1) == 0) {
- data[63] ^= 1;
- }
-}
-
-//----------------------------
-
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * Reduced-Resolution utilities
- *
- * Copyright(C) 2002 Pascal Massimino <skal@planet-d.net>
- *
- * This file is part of XviD, a free MPEG-4 video encoder/decoder
- *
- * XviD is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Under section 8 of the GNU General Public License, the copyright
- * holders of XVID explicitly forbid distribution in the following
- * countries:
- *
- * - Japan
- * - United States of America
- *
- * Linking XviD statically or dynamically with other modules is making a
- * combined work based on XviD. Thus, the terms and conditions of the
- * GNU General Public License cover the whole combination.
- *
- * As a special exception, the copyright holders of XviD give you
- * permission to link XviD with independent modules that communicate with
- * XviD solely through the VFW1.1 and DShow interfaces, regardless of the
- * license terms of these independent modules, and to copy and distribute
- * the resulting combined work under terms of your choice, provided that
- * every copy of the combined work is accompanied by a complete copy of
- * the source code of XviD (the version of XviD used to produce the
- * combined work), being distributed under the terms of the GNU General
- * Public License plus this exception. An independent module is a module
- * which is not derived from or based on XviD.
- *
- * Note that people who make modified versions of XviD are not obligated
- * to grant this special exception for their modified versions; it is
- * their choice whether to do so. The GNU General Public License gives
- * permission to release a modified version without this exception; this
- * exception also makes it possible to release a modified version which
- * carries forward this exception.
- *
- * $Id: reduced.cpp,v 1.1.1.1 2005-07-13 14:36:16 jeanlf Exp $
- *
- ****************************************************************************/
-
-#include "portab.h"
-#include "global.h"
-#include "reduced.h"
-
-/*----------------------------------------------------------------------------
- * Upsampling (1/3/3/1) filter
- *--------------------------------------------------------------------------*/
-
-#define ADD(dst,src) (dst) = CLIP((dst)+(src), 0, 255)
-
-inline void Filter_31(byte *Dst1, byte *Dst2, const int *Src1, const int *Src2){
-
- /* Src[] is assumed to be >=0. So we can use ">>2" instead of "/2" */
- int a = (3*Src1[0]+ Src2[0]+2) >> 2;
- int b = ( Src1[0]+3*Src2[0]+2) >> 2;
- Dst1[0] = CLIP(a, 0, 255);
- Dst2[0] = CLIP(b, 0, 255);
-}
-
-//----------------------------
-
-inline void Filter_9331(byte *Dst1, byte *Dst2, const int *Src1, const int *Src2){
-
- /* Src[] is assumed to be >=0. So we can use ">>4" instead of "/16" */
- int a = (9*Src1[0]+ 3*Src1[1]+ 3*Src2[0] + 1*Src2[1] + 8) >> 4;
- int b = (3*Src1[0]+ 9*Src1[1]+ 1*Src2[0] + 3*Src2[1] + 8) >> 4;
- int c = (3*Src1[0]+ 1*Src1[1]+ 9*Src2[0] + 3*Src2[1] + 8) >> 4;
- int d = (1*Src1[0]+ 3*Src1[1]+ 3*Src2[0] + 9*Src2[1] + 8) >> 4;
- Dst1[0] = CLIP(a, 0, 255);
- Dst1[1] = CLIP(b, 0, 255);
- Dst2[0] = CLIP(c, 0, 255);
- Dst2[1] = CLIP(d, 0, 255);
-}
-
-//----------------------------
-
-void copy_upsampled_8x8_16to8(byte *Dst, const int *Src, int BpS){
- int x, y;
-
- Dst[0] = CLIP(Src[0], 0, 255);
- for(x=0; x<7; ++x)
- Filter_31(Dst+2*x+1, Dst+2*x+2, Src+x, Src+x+1);
- Dst[15] = CLIP(Src[7], 0, 255);
- Dst += BpS;
- for(y=0; y<7; ++y) {
- byte *const Dst2 = Dst + BpS;
- Filter_31(Dst, Dst2, Src, Src+8);
- for(x=0; x<7; ++x)
- Filter_9331(Dst+2*x+1, Dst2+2*x+1, Src+x, Src+x+8);
- Filter_31(Dst+15, Dst2+15, Src+7, Src+7+8);
- Src += 8;
- Dst += 2*BpS;
- }
- Dst[0] = CLIP(Src[0], 0, 255);
- for(x=0; x<7; ++x) Filter_31(Dst+2*x+1, Dst+2*x+2, Src+x, Src+x+1);
- Dst[15] = CLIP(Src[7], 0, 255);
-}
-
-//----------------------------
-
-inline void Filter_Add_31(byte *Dst1, byte *Dst2, const int *Src1, const int *Src2){
-
- /* Here, we must use "/4", since Src[] is in [-256, 255] */
- int a = (3*Src1[0]+ Src2[0] + 2) / 4;
- int b = ( Src1[0]+3*Src2[0] + 2) / 4;
- ADD(Dst1[0], a);
- ADD(Dst2[0], b);
-}
-
-//----------------------------
-
-inline void Filter_Add_9331(byte *Dst1, byte *Dst2, const int *Src1, const int *Src2){
-
- int a = (9*Src1[0]+ 3*Src1[1]+ 3*Src2[0] + 1*Src2[1] + 8) / 16;
- int b = (3*Src1[0]+ 9*Src1[1]+ 1*Src2[0] + 3*Src2[1] + 8) / 16;
- int c = (3*Src1[0]+ 1*Src1[1]+ 9*Src2[0] + 3*Src2[1] + 8) / 16;
- int d = (1*Src1[0]+ 3*Src1[1]+ 3*Src2[0] + 9*Src2[1] + 8) / 16;
- ADD(Dst1[0], a);
- ADD(Dst1[1], b);
- ADD(Dst2[0], c);
- ADD(Dst2[1], d);
-}
-
-//----------------------------
-
-void add_upsampled_8x8_16to8(byte *Dst, const int *Src, const int BpS){
-
- int x, y;
-
- ADD(Dst[0], Src[0]);
- for(x=0; x<7; ++x)
- Filter_Add_31(Dst+2*x+1, Dst+2*x+2, Src+x, Src+x+1);
- ADD(Dst[15], Src[7]);
- Dst += BpS;
- for(y=0; y<7; ++y) {
- byte *const Dst2 = Dst + BpS;
- Filter_Add_31(Dst, Dst2, Src, Src+8);
- for(x=0; x<7; ++x)
- Filter_Add_9331(Dst+2*x+1, Dst2+2*x+1, Src+x, Src+x+8);
- Filter_Add_31(Dst+15, Dst2+15, Src+7, Src+7+8);
- Src += 8;
- Dst += 2*BpS;
- }
- ADD(Dst[0], Src[0]);
- for(x=0; x<7; ++x) Filter_Add_31(Dst+2*x+1, Dst+2*x+2, Src+x, Src+x+1);
- ADD(Dst[15], Src[7]);
-}
-#undef ADD
-
-/*----------------------------------------------------------------------------
- * horizontal and vertical deblocking
- *--------------------------------------------------------------------------*/
-
-void hfilter_31(byte *Src1, byte *Src2, int Nb_Blks){
-
- Nb_Blks *= 8;
- while(Nb_Blks-->0) {
- byte a = ( 3*Src1[0] + 1*Src2[0] + 2 ) >> 2;
- byte b = ( 1*Src1[0] + 3*Src2[0] + 2 ) >> 2;
- *Src1++ = a;
- *Src2++ = b;
- }
-}
-
-//----------------------------
-
-void vfilter_31(byte *Src1, byte *Src2, const int BpS, int Nb_Blks){
- Nb_Blks *= 8;
- while(Nb_Blks-->0) {
- byte a = ( 3*Src1[0] + 1*Src2[0] + 2 ) >> 2;
- byte b = ( 1*Src1[0] + 3*Src2[0] + 2 ) >> 2;
- *Src1 = a;
- *Src2 = b;
- Src1 += BpS;
- Src2 += BpS;
- }
-}
-
-//----------------------------
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Reduced VOP header -
- *
- * Copyright(C) 2002 Pascal Massimino <skal@planet-d.net>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: reduced.h,v 1.1.1.1 2005-07-13 14:36:16 jeanlf Exp $
- *
- ****************************************************************************/
-
-#ifndef _REDUCED_H_
-#define _REDUCED_H_
-
-#include "portab.h"
-
-/* decoding */
-typedef void (COPY_UPSAMPLED_8X8_16TO8)(byte *Dst, const int *Src, int BpS);
-typedef void (ADD_UPSAMPLED_8X8_16TO8)(byte *Dst, const int *Src, int BpS);
-
-/* deblocking: Note: "Nb"_Blks is the number of 8-pixels blocks to process */
-typedef void HFILTER_31(byte *Src1, byte *Src2, int Nb_Blks);
-typedef void VFILTER_31(byte *Src1, byte *Src2, int BpS, int Nb_Blks);
-
-/* encoding: WARNING! These read 1 pixel outside of the input 16x16 block! */
-typedef void FILTER_18X18_TO_8X8(int *Dst, const byte *Src, int BpS);
-typedef void FILTER_DIFF_18X18_TO_8X8(int *Dst, const byte *Src, int BpS);
-
-
-extern COPY_UPSAMPLED_8X8_16TO8 copy_upsampled_8x8_16to8;
-extern ADD_UPSAMPLED_8X8_16TO8 add_upsampled_8x8_16to8;
-
-extern VFILTER_31 vfilter_31;
-
-extern HFILTER_31 hfilter_31;
-
-/* rrv motion vector scale-up */
-#define RRV_MV_SCALEUP(a) ( (a)>0 ? 2*(a)-1 : (a)<0 ? 2*(a)+1 : (a) )
-
-#endif /* _REDUCED_H_ */
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Variable Length Code header -
- *
- * Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: vlc_codes.h,v 1.1.1.1 2005-07-13 14:36:16 jeanlf Exp $
- *
- ****************************************************************************/
-#ifndef _VLC_CODES_H_
-#define _VLC_CODES_H_
-
-#include "portab.h"
-
-#define VLC_ERROR (-1)
-
-#define ESCAPE 3
-#define ESCAPE1 6
-#define ESCAPE2 14
-#define ESCAPE3 15
-
-struct VLC{
- int code;
- byte len;
-};
-
-struct EVENT{
- byte last;
- byte run;
- char level;
-};
-
-
-
-#endif /* _VLC_CODES_H */
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - Native API implementation -
- *
- * Copyright(C) 2001-2003 Peter Ross <pross@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: xvid.cpp,v 1.1.1.1 2005-07-13 14:36:16 jeanlf Exp $
- *
- ****************************************************************************/
-
-#include "xvid.h"
-#include "decoder.h"
-#include "interpolate8x8.h"
-#include "reduced.h"
-#include "mem_transfer.h"
-#include "quant.h"
-
-#ifdef _DEBUG
-dword xvid_debug = 0;
-#endif
-
-/*****************************************************************************
- * XviD Init Entry point
- *
- * Well this function initialize all internal function pointers according
- * to the CPU features forced by the library client or autodetected (depending
- * on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all
- * image colorspace transformation tables.
- *
- * Returned value : XVID_ERR_OK
- * + API_VERSION in the input XVID_INIT_PARAM structure
- * + core build " " " " "
- *
- ****************************************************************************/
-
-
-static int xvid_gbl_init(xvid_gbl_init_t * init){
- //unsigned int cpu_flags;
-
- if (XVID_VERSION_MAJOR(init->version) != 1)
- return XVID_ERR_VERSION;
-
-#if defined(_DEBUG)
- xvid_debug = init->debug;
-#endif
-
- return 0;
-}
-
-/*****************************************************************************
- * XviD Global Entry point
- *
- * Well this function initialize all internal function pointers according
- * to the CPU features forced by the library client or autodetected (depending
- * on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all
- * image colorspace transformation tables.
- *
- ****************************************************************************/
-
-int xvid_global(void *handle, int opt, void *param1, void *param2){
-
- switch(opt){
- case XVID_GBL_INIT :
- return xvid_gbl_init((xvid_gbl_init_t*)param1);
- /*
- case XVID_GBL_INFO :
- return xvid_gbl_info((xvid_gbl_info_t*)param1);
- case XVID_GBL_CONVERT:
- return xvid_gbl_convert((xvid_gbl_convert_t*)param1);
- */
-
- default :
- return XVID_ERR_FAIL;
- }
-}
-
-/*****************************************************************************
- * XviD Native decoder entry point
- *
- * This function is just a wrapper to all the option cases.
- *
- * Returned values : XVID_ERR_FAIL when opt is invalid
- * else returns the wrapped function result
- *
- ****************************************************************************/
-int xvid_decore(void *handle, int opt, void *param1, void *param2){
-
- switch (opt) {
- case XVID_DEC_CREATE:
- return decoder_create((xvid_dec_create_t *) param1);
-
- case XVID_DEC_DESTROY:
- delete (S_decoder*)handle;
- return 0;
-
- case XVID_DEC_DECODE:
- return ((S_decoder*)handle)->Decode((xvid_dec_frame_t *) param1, (xvid_dec_stats_t*) param2);
-
- default:
- return XVID_ERR_FAIL;
- }
-}
-
-//----------------------------
-
-extern const dword scan_tables[3][64];
-const dword scan_tables[3][64] = {
- /* zig_zag_scan */
- { 0, 1, 8, 16, 9, 2, 3, 10,
- 17, 24, 32, 25, 18, 11, 4, 5,
- 12, 19, 26, 33, 40, 48, 41, 34,
- 27, 20, 13, 6, 7, 14, 21, 28,
- 35, 42, 49, 56, 57, 50, 43, 36,
- 29, 22, 15, 23, 30, 37, 44, 51,
- 58, 59, 52, 45, 38, 31, 39, 46,
- 53, 60, 61, 54, 47, 55, 62, 63},
-
- /* horizontal_scan */
- { 0, 1, 2, 3, 8, 9, 16, 17,
- 10, 11, 4, 5, 6, 7, 15, 14,
- 13, 12, 19, 18, 24, 25, 32, 33,
- 26, 27, 20, 21, 22, 23, 28, 29,
- 30, 31, 34, 35, 40, 41, 48, 49,
- 42, 43, 36, 37, 38, 39, 44, 45,
- 46, 47, 50, 51, 56, 57, 58, 59,
- 52, 53, 54, 55, 60, 61, 62, 63},
-
- /* vertical_scan */
- { 0, 8, 16, 24, 1, 9, 2, 10,
- 17, 25, 32, 40, 48, 56, 57, 49,
- 41, 33, 26, 18, 3, 11, 4, 12,
- 19, 27, 34, 42, 50, 58, 35, 43,
- 51, 59, 20, 28, 5, 13, 6, 14,
- 21, 29, 36, 44, 52, 60, 37, 45,
- 53, 61, 22, 30, 7, 15, 23, 31,
- 38, 46, 54, 62, 39, 47, 55, 63}
-};
-
-//----------------------------
-
-#ifdef WIN32
-# include <windows.h>
-# include <stdio.h>
-
-#ifdef _DEBUG
-# define snprintf _snprintf
-# define vsnprintf _vsnprintf
-
-void DPRINTF(int level, char *fmt, int p){
- if(xvid_debug & level){
- //va_list args;
- char buf[DPRINTF_BUF_SZ];
- //va_start(args, fmt);
- //vsprintf(buf, fmt, args);
- sprintf(buf, fmt, p);
- OutputDebugString(buf);
- //fprintf(stderr, "%s", buf);
- }
-}
-#endif
-
-#elif defined _WINDOWS
-
-inline void DPRINTF(int level, char *fmt, int p){
-}
-
-#endif
-
-//----------------------------
-
+++ /dev/null
-/*****************************************************************************
- *
- * XVID MPEG-4 VIDEO CODEC
- * - XviD Main header file -
- *
- * Copyright(C) 2001-2003 Peter Ross <pross@xvid.org>
- *
- * This program is free software ; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation ; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY ; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id: xvid.h,v 1.2 2006-12-13 15:12:27 jeanlf Exp $
- *
- ****************************************************************************/
-
-#ifndef _XVID_H_
-#define _XVID_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#include "Rules.h"
-
-
-#ifdef PROFILE
-#include <Profiler.h>
-#define PROF_S(n) prof.MarkS(n)
-#define PROF_E(n) prof.MarkE(n)
-
-enum{
- PROF_TICK,
- PROF_CONV,
- PROF_UPD,
- PROF_DECODE,
- PROF_DRAWTXT,
- PROF_FRM_I,
- PROF_FRM_P,
- PROF_BINT_MBI,
- PROF_FRM_B,
- PROF_0,
- PROF_1,
- PROF_2,
- PROF_3,
- PROF_4,
- PROF_5,
- PROF_6,
- PROF_7,
-};
-
-#else
-#define PROF_S(n)
-#define PROF_E(n)
-#endif
-
-#ifdef __MARM__
-//#define USE_ARM_ASM
-#endif
-
-/*****************************************************************************
- * versioning
- ****************************************************************************/
-
-/* versioning
- version takes the form "$major.$minor.$patch"
- $patch is incremented when there is no api change
- $minor is incremented when the api is changed, but remains backwards compatible
- $major is incremented when the api is changed significantly
-
- when initialising an xvid structure, you must always zero it, and set the version field.
- memset(&struct,0,sizeof(struct));
- struct.version = XVID_VERSION;
-
- XVID_UNSTABLE is defined only during development.
- */
-
-#define XVID_MAKE_VERSION(a,b,c) ((((a)&0xff)<<16) | (((b)&0xff)<<8) | ((c)&0xff))
-#define XVID_VERSION_MAJOR(a) ((char)(((a)>>16) & 0xff))
-#define XVID_VERSION_MINOR(a) ((char)(((a)>> 8) & 0xff))
-#define XVID_VERSION_PATCH(a) ((char)(((a)>> 0) & 0xff))
-
-#define XVID_MAKE_API(a,b) ((((a)&0xff)<<16) | (((b)&0xff)<<0))
-#define XVID_API_MAJOR(a) (((a)>>16) & 0xff)
-#define XVID_API_MINOR(a) (((a)>> 0) & 0xff)
-
-#define XVID_VERSION XVID_MAKE_VERSION(1,0,-127)
-#define XVID_API XVID_MAKE_API(4, 0)
-
-#define EDGE_SIZE 16
-
-#define XVID_UNSTABLE
-
-/* Bitstream Version
- * this will be writen into the bitstream to allow easy detection of xvid
- * encoder bugs in the decoder, without this it might not possible to
- * automatically distinquish between a file which has been encoded with an
- * old & buggy XVID from a file which has been encoded with a bugfree version
- * see the infamous interlacing bug ...
- *
- * this MUST be increased if an encoder bug is fixed, increasing it too often
- * doesnt hurt but not increasing it could cause difficulty for decoders in the
- * future
- */
-#define XVID_BS_VERSION "0023"
-
-
-/*****************************************************************************
- * error codes
- ****************************************************************************/
-
- /* all functions return values <0 indicate error */
-
-#define XVID_ERR_FAIL -1 /* general fault */
-#define XVID_ERR_MEMORY -2 /* memory allocation error */
-#define XVID_ERR_FORMAT -3 /* file format error */
-#define XVID_ERR_VERSION -4 /* structure version not supported */
-#define XVID_ERR_END -5 /* encoder only; end of stream reached */
-
-
-
-/*****************************************************************************
- * xvid_image_t
- ****************************************************************************/
-
-/* colorspace values */
-
-//#define XVID_CSP_USER (1<< 0) /* 4:2:0 planar */
-//#define XVID_CSP_I420 (1<< 1) /* 4:2:0 packed(planar win32) */
-//#define XVID_CSP_YV12 (1<< 2) /* 4:2:0 packed(planar win32) */
-//#define XVID_CSP_YUY2 (1<< 3) /* 4:2:2 packed */
-//#define XVID_CSP_UYVY (1<< 4) /* 4:2:2 packed */
-//#define XVID_CSP_YVYU (1<< 5) /* 4:2:2 packed */
-//#define XVID_CSP_BGRA (1<< 6) /* 32-bit bgra packed */
-//#define XVID_CSP_ABGR (1<< 7) /* 32-bit abgr packed */
-//#define XVID_CSP_RGBA (1<< 8) /* 32-bit rgba packed */
-//#define XVID_CSP_BGR (1<< 9) /* 24-bit bgr packed */
-//#define XVID_CSP_RGB555 (1<<10) /* 16-bit rgb555 packed */
-//#define XVID_CSP_RGB565 (1<<11) /* 16-bit rgb565 packed */
-//#define XVID_CSP_SLICE (1<<12) /* decoder only: 4:2:0 planar, per slice rendering */
-//#define XVID_CSP_INTERNAL (1<<13) /* decoder only: 4:2:0 planar, returns ptrs to internal buffers */
-//#define XVID_CSP_NULL (1<<14) /* decoder only: dont output anything */
-//#define XVID_CSP_VFLIP (1<<31) /* vertical flip mask */
-
-/* xvid_image_t
- for non-planar colorspaces use only plane[0] and stride[0]
- four plane reserved for alpha*/
-/*
-typedef struct {
- int csp; // [in] colorspace; or with XVID_CSP_VFLIP to perform vertical flip
- void *plane; // [in] image plane ptrs
- int stride; // [in] image stride; "bytes per row"
-} xvid_image_t;
-*/
-
-/* video-object-sequence profiles */
-#define XVID_PROFILE_S_L0 0x08 /* simple */
-#define XVID_PROFILE_S_L1 0x01
-#define XVID_PROFILE_S_L2 0x02
-#define XVID_PROFILE_S_L3 0x03
-#define XVID_PROFILE_ARTS_L1 0x91 /* advanced realtime simple */
-#define XVID_PROFILE_ARTS_L2 0x92
-#define XVID_PROFILE_ARTS_L3 0x93
-#define XVID_PROFILE_ARTS_L4 0x94
-#define XVID_PROFILE_AS_L0 0xf0 /* advanced simple */
-#define XVID_PROFILE_AS_L1 0xf1
-#define XVID_PROFILE_AS_L2 0xf2
-#define XVID_PROFILE_AS_L3 0xf3
-#define XVID_PROFILE_AS_L4 0xf4
-
-/* aspect ratios */
-#define XVID_PAR_11_VGA 1 /* 1:1 vga (square), default if AR is not precised (ie: ==0) */
-#define XVID_PAR_43_PAL 2 /* 4:3 pal (12:11 625-line) */
-#define XVID_PAR_43_NTSC 3 /* 4:3 ntsc (10:11 525-line) */
-#define XVID_PAR_169_PAL 4 /* 16:9 pal (16:11 625-line) */
-#define XVID_PAR_169_NTSC 5 /* 16:9 ntsc (40:33 525-line) */
-#define XVID_PAR_EXT 15 /* extended par; use par_width, par_height */
-
-/* frame type flags */
-#define XVID_TYPE_VOL -1 /* decoder only: vol was decoded */
-#define XVID_TYPE_NOTHING 0 /* decoder only (encoder stats): nothing was decoded/encoded */
-#define XVID_TYPE_AUTO 0 /* encoder: automatically determine coding type */
-#define XVID_TYPE_IVOP 1 /* intra frame */
-#define XVID_TYPE_PVOP 2 /* predicted frame */
-#define XVID_TYPE_BVOP 3 /* bidirectionally encoded */
-#define XVID_TYPE_SVOP 4 /* predicted+sprite frame */
-
-
-/*****************************************************************************
- * xvid_global()
- ****************************************************************************/
-
-/* cpu_flags definitions (make sure to sync this with cpuid.asm for ia32) */
-
-//#define XVID_CPU_FORCE (1<<31) /* force passed cpu flags */
-//#define XVID_CPU_ASM (1<< 7) /* native assembly */
-/* ARCH_IS_IA32 */
-//#define XVID_CPU_MMX (1<< 0) /* mmx : pentiumMMX,k6 */
-//#define XVID_CPU_MMXEXT (1<< 1) /* mmx-ext : pentium2, athlon */
-//#define XVID_CPU_SSE (1<< 2) /* sse : pentium3, athlonXP */
-//#define XVID_CPU_SSE2 (1<< 3) /* sse2 : pentium4, athlon64 */
-//#define XVID_CPU_3DNOW (1<< 4) /* 3dnow : k6-2 */
-//#define XVID_CPU_3DNOWEXT (1<< 5) /* 3dnow-ext : athlon */
-//#define XVID_CPU_TSC (1<< 6) /* tsc : Pentium */
-/* ARCH_IS_PPC */
-//#define XVID_CPU_ALTIVEC (1<< 0) /* altivec */
-
-
-#define XVID_DEBUG_ERROR (1<< 0)
-#define XVID_DEBUG_STARTCODE (1<< 1)
-#define XVID_DEBUG_HEADER (1<< 2)
-#define XVID_DEBUG_TIMECODE (1<< 3)
-#define XVID_DEBUG_MB (1<< 4)
-#define XVID_DEBUG_COEFF (1<< 5)
-#define XVID_DEBUG_MV (1<< 6)
-#define XVID_DEBUG_RC (1<< 7)
-#define XVID_DEBUG_DEBUG (1<<31)
-
-/* XVID_GBL_INIT param1 */
-typedef struct {
- int version;
- unsigned int cpu_flags; /* [in:opt] zero = autodetect cpu; XVID_CPU_FORCE|{cpu features} = force cpu features */
- int debug; /* [in:opt] debug level */
-} xvid_gbl_init_t;
-
-
-/* XVID_GBL_INFO param1 */
-#if 0
-typedef struct {
- int version;
- int actual_version; // [out] returns the actual xvidcore version
- const char * build; // [out] if !null, points to description of this xvid core build
- unsigned int cpu_flags; // [out] detected cpu features
- int num_threads; // [out] detected number of cpus/threads
-} xvid_gbl_info_t;
-#endif
-
-
-#define XVID_GBL_INIT 0 /* initialize xvidcore; must be called before using xvid_decore, or xvid_encore) */
-//#define XVID_GBL_INFO 1 /* return some info about xvidcore, and the host computer */
-//#define XVID_GBL_CONVERT 2 /* colorspace conversion utility */
-
-int xvid_global(void *handle, int opt, void *param1, void *param2);
-
-
-class C_xvid_image{
-public:
- byte *y;
- byte *u;
- byte *v;
-
- C_xvid_image():
- y(NULL),
- u(NULL),
- v(NULL)
- {}
-};
-
-void * InitCodec(dword sx, dword sy, dword fcc);
-void CloseCodec(void *handle);
-//int DecodeFrame(void *handle, const void *buf, dword sz_in, byte **y, byte **u, byte **v, dword *pitch);
-int DecodeFrame(void *handle, const void *buf, dword sz_in, byte *&y, byte *&u, byte *&v, dword &pitch);
-
-/*****************************************************************************
- * xvid_decore()
- ****************************************************************************/
-
-#define XVID_DEC_CREATE 0 /* create decore instance; return 0 on success */
-#define XVID_DEC_DESTROY 1 /* destroy decore instance: return 0 on success */
-#define XVID_DEC_DECODE 2 /* decode a frame: returns number of bytes consumed >= 0 */
-
-int xvid_decore(void *handle, int opt, void *param1, void *param2);
-
-/* XVID_DEC_CREATE param 1
- image width & height may be specified here when the dimensions are
- known in advance. */
-typedef struct {
- int version;
- int width; /* [in:opt] image width */
- int height; /* [in:opt] image width */
- void *handle; /* [out] decore context handle */
-#ifdef PROFILE
- C_profiler *prof;
-#endif
-} xvid_dec_create_t;
-
-
-/* XVID_DEC_DECODE param1 */
-/* general flags */
-#define XVID_LOWDELAY (1<<0) /* lowdelay mode */
-#define XVID_DISCONTINUITY (1<<1) /* indicates break in stream */
-
-typedef struct {
- int version;
- int general; /* [in:opt] general flags */
- const void *bitstream; /* [in] bitstream (read from)*/
- int length; /* [in] bitstream length */
- //xvid_image_t output; /* [in] output image (written to) */
- const C_xvid_image *img_out;
-} xvid_dec_frame_t;
-
-
-/* XVID_DEC_DECODE param2 :: optional */
-typedef struct
-{
- int version;
-
- int type; /* [out] output data type */
- union {
- struct { /* type>0 {XVID_TYPE_IVOP,XVID_TYPE_PVOP,XVID_TYPE_BVOP,XVID_TYPE_SVOP} */
- int general; /* [out] flags */
- int time_base; /* [out] time base */
- int time_increment; /* [out] time increment */
-
- /* XXX: external deblocking stuff */
- int * qscale; /* [out] pointer to quantizer table */
- int qscale_stride; /* [out] quantizer scale stride */
-
- } vop;
- struct { /* XVID_TYPE_VOL */
- int general; /* [out] flags */
- int width; /* [out] width */
- int height; /* [out] height */
- int par; /* [out] picture aspect ratio (refer to XVID_PAR_xxx above) */
- int par_width; /* [out] aspect ratio width */
- int par_height; /* [out] aspect ratio height */
- } vol;
- } data;
-} xvid_dec_stats_t;
-
-
-
-#define XVID_ZONE_QUANT (1<<0)
-#define XVID_ZONE_WEIGHT (1<<1)
-
-typedef struct
-{
- int frame;
- int mode;
- int increment;
- int base;
-} xvid_enc_zone_t;
-
-
-
-/*****************************************************************************
- xvid plugin system -- internals
-
- xvidcore will call XVID_PLG_INFO and XVID_PLG_CREATE during XVID_ENC_CREATE
- before encoding each frame xvidcore will call XVID_PLG_BEFORE
- after encoding each frame xvidcore will call XVID_PLG_AFTER
- xvidcore will call XVID_PLG_DESTROY during XVID_ENC_DESTROY
- ****************************************************************************/
-
-
-#define XVID_PLG_CREATE (1<<0)
-#define XVID_PLG_DESTROY (1<<1)
-#define XVID_PLG_INFO (1<<2)
-#define XVID_PLG_BEFORE (1<<3)
-#define XVID_PLG_FRAME (1<<4)
-#define XVID_PLG_AFTER (1<<5)
-
-/* xvid_plg_info_t.flags */
-#define XVID_REQORIGINAL (1<<0) /* plugin requires a copy of the original (uncompressed) image */
-#define XVID_REQPSNR (1<<1) /* plugin requires psnr between the uncompressed and compressed image*/
-#define XVID_REQDQUANTS (1<<2) /* plugin requires access to the dquant table */
-
-
-typedef struct
-{
- int version;
- int flags; /* [in:opt] plugin flags */
-} xvid_plg_info_t;
-
-
-typedef struct
-{
- int version;
-
- int num_zones; /* [out] */
- xvid_enc_zone_t * zones; /* [out] */
-
- int width; /* [out] */
- int height; /* [out] */
- int mb_width; /* [out] */
- int mb_height; /* [out] */
- int fincr; /* [out] */
- int fbase; /* [out] */
-
- void * param; /* [out] */
-} xvid_plg_create_t;
-
-
-typedef struct
-{
- int version;
-
- int num_frames; /* [out] total frame encoded */
-} xvid_plg_destroy_t;
-
-
-
-/*****************************************************************************
- xvid plugin system -- external
-
- the application passes xvid an array of "xvid_plugin_t" at XVID_ENC_CREATE. the array
- indicates the plugin function pointer and plugin-specific data.
- xvidcore handles the rest. example:
-
- xvid_enc_create_t create;
- xvid_enc_plugin_t plugins[2];
-
- plugins[0].func = xvid_psnr_func;
- plugins[0].param = NULL;
- plugins[1].func = xvid_cbr_func;
- plugins[1].param = &cbr_data;
-
- create.num_plugins = 2;
- create.plugins = plugins;
-
- ****************************************************************************/
-
-typedef int (xvid_plugin_func)(void * handle, int opt, void * param1, void * param2);
-
-typedef struct
-{
- xvid_plugin_func * func;
- void * param;
-} xvid_enc_plugin_t;
-
-
-xvid_plugin_func xvid_plugin_single; /* single-pass rate control */
-xvid_plugin_func xvid_plugin_2pass1; /* two-pass rate control: first pass */
-xvid_plugin_func xvid_plugin_2pass2; /* two-pass rate control: second pass */
-
-xvid_plugin_func xvid_plugin_lumimasking; /* lumimasking */
-
-xvid_plugin_func xvid_plugin_psnr; /* write psnr values to stdout */
-xvid_plugin_func xvid_plugin_dump; /* dump before and after yuvpgms */
-
-
-/* single pass rate control
- * CBR and Constant quantizer modes */
-typedef struct
-{
- int version;
-
- int bitrate; /* [in] bits per second */
- int reaction_delay_factor; /* [in] */
- int averaging_period; /* [in] */
- int buffer; /* [in] */
-} xvid_plugin_single_t;
-
-
-typedef struct {
- int version;
-
- char * filename;
-} xvid_plugin_2pass1_t;
-
-
-#define XVID_PAYBACK_BIAS 0 /* payback with bias */
-#define XVID_PAYBACK_PROP 1 /* payback proportionally */
-
-typedef struct {
- int version;
-
- int bitrate; /* [in] bits per second */
- char * filename; /* [in] first pass stats filename */
-
- int keyframe_boost; /* [in] keyframe boost percentage: [0..100] */
- int curve_compression_high; /* [in] percentage of compression performed on the high part of the curve (above average) */
- int curve_compression_low; /* [in] percentage of compression performed on the low part of the curve (below average) */
- int overflow_control_strength;/* [in] Payback delay expressed in number of frames */
- int max_overflow_improvement; /* [in] percentage of allowed range for a frame that gets bigger because of overflow bonus */
- int max_overflow_degradation; /* [in] percentage of allowed range for a frame that gets smaller because of overflow penalty */
-
- int kfreduction; /* [in] maximum bitrate reduction applied to an iframe under the kfthreshold distance limit */
- int kfthreshold; /* [in] if an iframe is closer to the next iframe than this distance, a quantity of bits
- * is substracted from its bit allocation. The reduction is computed as multiples of
- * kfreduction/kthreshold. It reaches kfreduction when the distance == kfthreshold,
- * 0 for 1<distance<kfthreshold */
-
- int container_frame_overhead; /* [in] How many bytes the controller has to compensate per frame due to container format overhead */
-} xvid_plugin_2pass2_t;
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+++ /dev/null
-
- AREA XVID,CODE,READONLY
- EXPORT XVID_ClearMatrix
- EXPORT XVID_MemCpy
- EXPORT interpolate8x8_halfpel_hv
- EXPORT interpolate8x8_halfpel_h
- EXPORT interpolate8x8_halfpel_v
- EXPORT transfer8x8_copy
-
-;----------------------------
-XVID_ClearMatrix
-
- mov r1, #0
- mov r2, #0
- mov r3, #0
- mov r12, #0
- stmia r0!, { r1, r2, r3, r12 }
- stmia r0!, { r1, r2, r3, r12 }
- stmia r0!, { r1, r2, r3, r12 }
- stmia r0!, { r1, r2, r3, r12 }
- stmia r0!, { r1, r2, r3, r12 }
- stmia r0!, { r1, r2, r3, r12 }
- stmia r0!, { r1, r2, r3, r12 }
- stmia r0!, { r1, r2, r3, r12 }
-
- stmia r0!, { r1, r2, r3, r12 }
- stmia r0!, { r1, r2, r3, r12 }
- stmia r0!, { r1, r2, r3, r12 }
- stmia r0!, { r1, r2, r3, r12 }
- stmia r0!, { r1, r2, r3, r12 }
- stmia r0!, { r1, r2, r3, r12 }
- stmia r0!, { r1, r2, r3, r12 }
- stmia r0!, { r1, r2, r3, r12 }
-
- mov pc, lr
-
-;----------------------------
-XVID_MemCpy
-
- stmfd sp!, { r4 - r6 }
-
- subs r2, r2, #16
- blt mc_no16
-mc_loop16
- ;the order of regs in {} is not important, now it's ordered as to avoid compiler warnings
- ldmia r1!, { r3 - r6 }
- stmia r0!, { r3 - r6 }
- subs r2, r2, #16
- bge mc_loop16
-mc_no16
- adds r2, r2, #16
- beq mc_end
-mc_loop4
- ldr r3, [r1], #4
- str r3, [r0], #4
- subs r2, r2, #4
- bne mc_loop4
-mc_end
-
- ldmfd sp!, { r4 - r6 }
- mov pc, lr
-
-;----------------------------
-interpolate8x8_halfpel_hv
-
- stmfd sp!, { r4 - r9, r14 }
-
- tst r3, r3
- movne r14, #1
- moveq r14, #2
-
- mov r3, #8
-ihhv_loop
- add r4, r1, r2
- ldrb r5, [r1, #8]
- ldrb r7, [r4, #8]
- add r5, r5, r7
- ;7+8
- ldrb r6, [r1, #7]
- ldrb r7, [r4, #7]
- add r6, r6, r7
- add r7, r5, r6
- add r7, r7, r14
- mov r8, r7, asr #2
- ;6+7
- ldrb r5, [r1, #6]
- ldrb r7, [r4, #6]
- add r5, r5, r7
- add r7, r5, r6
- add r7, r7, r14
- mov r7, r7, asr #2
- orr r8, r7, r8, asl #8
- ;5+6
- ldrb r6, [r1, #5]
- ldrb r7, [r4, #5]
- add r6, r6, r7
- add r7, r5, r6
- add r7, r7, r14
- mov r7, r7, asr #2
- orr r8, r7, r8, asl #8
- ;4+5
- ldrb r5, [r1, #4]
- ldrb r7, [r4, #4]
- add r5, r5, r7
- add r7, r5, r6
- add r7, r7, r14
- mov r7, r7, asr #2
- orr r8, r7, r8, asl #8
-
- str r8, [r0, #4]
-
- ;3+4
- ldrb r6, [r1, #3]
- ldrb r7, [r4, #3]
- add r6, r6, r7
- add r7, r5, r6
- add r7, r7, r14
- mov r8, r7, asr #2
- ;2+3
- ldrb r5, [r1, #2]
- ldrb r7, [r4, #2]
- add r5, r5, r7
- add r7, r5, r6
- add r7, r7, r14
- mov r7, r7, asr #2
- orr r8, r7, r8, asl #8
- ;1+2
- ldrb r6, [r1, #1]
- ldrb r7, [r4, #1]
- add r6, r6, r7
- add r7, r5, r6
- add r7, r7, r14
- mov r7, r7, asr #2
- orr r8, r7, r8, asl #8
- ;0+1
- ldrb r5, [r1, #0]
- ldrb r7, [r4, #0]
- add r5, r5, r7
- add r7, r5, r6
- add r7, r7, r14
- mov r7, r7, asr #2
- orr r8, r7, r8, asl #8
-
- str r8, [r0, #0]
-
- add r0, r0, r2
- add r1, r1, r2
- subs r3, r3, #1
- bne ihhv_loop
-
- ldmfd sp!, { r4 - r9, r14 }
- mov pc, lr
-
-;----------------------------
-interpolate8x8_halfpel_h
-
- stmfd sp!, { r4 - r6 }
-
- ands r3, r3, #1
- beq i_hp_h_no_round
-
- mov r6, #8
-ihh_loop
- ldrb r12, [r1, #8]
- ;7+8
- ldrb r3, [r1, #7]
- add r4, r12, r3
- mov r4, r4, asr #1
- ;6+7
- ldrb r12, [r1, #6]
- add r5, r12, r3
- mov r5, r5, asr #1
- orr r4, r5, r4, asl #8
- ;5+6
- ldrb r3, [r1, #5]
- add r5, r12, r3
- mov r5, r5, asr #1
- orr r4, r5, r4, asl #8
- ;4+5
- ldrb r12, [r1, #4]
- add r5, r12, r3
- mov r5, r5, asr #1
- orr r4, r5, r4, asl #8
-
- str r4, [r0, #4]
-
- ;3+4
- ldrb r3, [r1, #3]
- add r4, r12, r3
- mov r4, r4, asr #1
- ;2+3
- ldrb r12, [r1, #2]
- add r5, r12, r3
- mov r5, r5, asr #1
- orr r4, r5, r4, asl #8
- ;1+2
- ldrb r3, [r1, #1]
- add r5, r12, r3
- mov r5, r5, asr #1
- orr r4, r5, r4, asl #8
- ;0+1
- ldrb r12, [r1, #0]
- add r5, r12, r3
- mov r5, r5, asr #1
- orr r4, r5, r4, asl #8
-
- str r4, [r0, #0]
-
- add r0, r0, r2
- add r1, r1, r2
- subs r6, r6, #1
- bne ihh_loop
- b i_hp_h_end
-
-i_hp_h_no_round
-
- mov r6, #8
-ihh_loop1
- ldrb r12, [r1, #8]
- ;7+8
- ldrb r3, [r1, #7]
- add r4, r12, r3
- add r4, r4, #1
- mov r4, r4, asr #1
- ;6+7
- ldrb r12, [r1, #6]
- add r5, r12, r3
- add r5, r5, #1
- mov r5, r5, asr #1
- orr r4, r5, r4, asl #8
- ;5+6
- ldrb r3, [r1, #5]
- add r5, r12, r3
- add r5, r5, #1
- mov r5, r5, asr #1
- orr r4, r5, r4, asl #8
- ;4+5
- ldrb r12, [r1, #4]
- add r5, r12, r3
- add r5, r5, #1
- mov r5, r5, asr #1
- orr r4, r5, r4, asl #8
-
- str r4, [r0, #4]
-
- ;3+4
- ldrb r3, [r1, #3]
- add r4, r12, r3
- add r4, r4, #1
- mov r4, r4, asr #1
- ;2+3
- ldrb r12, [r1, #2]
- add r5, r12, r3
- add r5, r5, #1
- mov r5, r5, asr #1
- orr r4, r5, r4, asl #8
- ;1+2
- ldrb r3, [r1, #1]
- add r5, r12, r3
- add r5, r5, #1
- mov r5, r5, asr #1
- orr r4, r5, r4, asl #8
- ;0+1
- ldrb r12, [r1, #0]
- add r5, r12, r3
- add r5, r5, #1
- mov r5, r5, asr #1
- orr r4, r5, r4, asl #8
-
- str r4, [r0, #0]
-
- add r0, r0, r2
- add r1, r1, r2
- subs r6, r6, #1
- bne ihh_loop1
-
-i_hp_h_end
- ldmfd sp!, { r4 - r6 }
- mov pc, lr
-
-;----------------------------
-interpolate8x8_halfpel_v
-
- stmfd sp!, { r4 - r6 }
-
- ands r3, r3, #1
- beq i_hp_v_no_round
-
- mov r6, #8
-ihv_loop
- add r5, r1, r2
- ;3
- ldrb r12, [r1, #3]
- ldrb r3, [r5, #3]
- add r4, r12, r3
- mov r4, r4, asr #1
- ;2
- ldrb r12, [r1, #2]
- ldrb r3, [r5, #2]
- add r12, r12, r3
- mov r12, r12, asr #1
- orr r4, r12, r4, asl #8
- ;1
- ldrb r12, [r1, #1]
- ldrb r3, [r5, #1]
- add r12, r12, r3
- mov r12, r12, asr #1
- orr r4, r12, r4, asl #8
- ;0
- ldrb r12, [r1, #0]
- ldrb r3, [r5, #0]
- add r12, r12, r3
- mov r12, r12, asr #1
- orr r4, r12, r4, asl #8
-
- str r4, [r0, #0]
-
- ;7
- ldrb r12, [r1, #7]
- ldrb r3, [r5, #7]
- add r4, r12, r3
- mov r4, r4, asr #1
- ;6
- ldrb r12, [r1, #6]
- ldrb r3, [r5, #6]
- add r12, r12, r3
- mov r12, r12, asr #1
- orr r4, r12, r4, asl #8
- ;5
- ldrb r12, [r1, #5]
- ldrb r3, [r5, #5]
- add r12, r12, r3
- mov r12, r12, asr #1
- orr r4, r12, r4, asl #8
- ;4
- ldrb r12, [r1, #4]
- ldrb r3, [r5, #4]
- add r12, r12, r3
- mov r12, r12, asr #1
- orr r4, r12, r4, asl #8
-
- str r4, [r0, #4]
-
- add r0, r0, r2
- add r1, r1, r2
- subs r6, r6, #1
- bne ihv_loop
- b i_hp_v_end
-
-i_hp_v_no_round
- mov r6, #8
-ihv_loop1
- add r5, r1, r2
- ;3
- ldrb r12, [r1, #3]
- ldrb r3, [r5, #3]
- add r4, r12, r3
- add r4, r4, #1
- mov r4, r4, asr #1
- ;2
- ldrb r12, [r1, #2]
- ldrb r3, [r5, #2]
- add r12, r12, r3
- add r12, r12, #1
- mov r12, r12, asr #1
- orr r4, r12, r4, asl #8
- ;1
- ldrb r12, [r1, #1]
- ldrb r3, [r5, #1]
- add r12, r12, r3
- add r12, r12, #1
- mov r12, r12, asr #1
- orr r4, r12, r4, asl #8
- ;0
- ldrb r12, [r1, #0]
- ldrb r3, [r5, #0]
- add r12, r12, r3
- add r12, r12, #1
- mov r12, r12, asr #1
- orr r4, r12, r4, asl #8
-
- str r4, [r0, #0]
-
- ;7
- ldrb r12, [r1, #7]
- ldrb r3, [r5, #7]
- add r4, r12, r3
- add r4, r4, #1
- mov r4, r4, asr #1
- ;6
- ldrb r12, [r1, #6]
- ldrb r3, [r5, #6]
- add r12, r12, r3
- add r12, r12, #1
- mov r12, r12, asr #1
- orr r4, r12, r4, asl #8
- ;5
- ldrb r12, [r1, #5]
- ldrb r3, [r5, #5]
- add r12, r12, r3
- add r12, r12, #1
- mov r12, r12, asr #1
- orr r4, r12, r4, asl #8
- ;4
- ldrb r12, [r1, #4]
- ldrb r3, [r5, #4]
- add r12, r12, r3
- add r12, r12, #1
- mov r12, r12, asr #1
- orr r4, r12, r4, asl #8
-
- str r4, [r0, #4]
-
- add r0, r0, r2
- add r1, r1, r2
- subs r6, r6, #1
- bne ihv_loop1
-i_hp_v_end
- ldmfd sp!, { r4 - r6 }
- mov pc, lr
-
-;----------------------------
-transfer8x8_copy
-
- orr r12, r1, r2
- tst r12, #3
- bne tc_no_dw
- ;dword version
-;tc_dw_loop
- ldmia r1, { r12, r3 }
- stmia r0, { r12, r3 }
- add r0, r0, r2
- add r1, r1, r2
-
- ldmia r1, { r12, r3 }
- stmia r0, { r12, r3 }
- add r0, r0, r2
- add r1, r1, r2
-
- ldmia r1, { r12, r3 }
- stmia r0, { r12, r3 }
- add r0, r0, r2
- add r1, r1, r2
-
- ldmia r1, { r12, r3 }
- stmia r0, { r12, r3 }
- add r0, r0, r2
- add r1, r1, r2
-
- ldmia r1, { r12, r3 }
- stmia r0, { r12, r3 }
- add r0, r0, r2
- add r1, r1, r2
-
- ldmia r1, { r12, r3 }
- stmia r0, { r12, r3 }
- add r0, r0, r2
- add r1, r1, r2
-
- ldmia r1, { r12, r3 }
- stmia r0, { r12, r3 }
- add r0, r0, r2
- add r1, r1, r2
-
- ldmia r1, { r12, r3 }
- stmia r0, { r12, r3 }
-
- mov pc, lr
-
-tc_no_dw
- tst r12, #1
- bne tc_no_w
- ;word version
-;tc_w_loop
- ldrh r12, [r1, #0]
- strh r12, [r0, #0]
- ldrh r12, [r1, #2]
- strh r12, [r0, #2]
- ldrh r12, [r1, #4]
- strh r12, [r0, #4]
- ldrh r12, [r1, #6]
- strh r12, [r0, #6]
- add r0, r0, r2
- add r1, r1, r2
-
- ldrh r12, [r1, #0]
- strh r12, [r0, #0]
- ldrh r12, [r1, #2]
- strh r12, [r0, #2]
- ldrh r12, [r1, #4]
- strh r12, [r0, #4]
- ldrh r12, [r1, #6]
- strh r12, [r0, #6]
- add r0, r0, r2
- add r1, r1, r2
-
- ldrh r12, [r1, #0]
- strh r12, [r0, #0]
- ldrh r12, [r1, #2]
- strh r12, [r0, #2]
- ldrh r12, [r1, #4]
- strh r12, [r0, #4]
- ldrh r12, [r1, #6]
- strh r12, [r0, #6]
- add r0, r0, r2
- add r1, r1, r2
-
- ldrh r12, [r1, #0]
- strh r12, [r0, #0]
- ldrh r12, [r1, #2]
- strh r12, [r0, #2]
- ldrh r12, [r1, #4]
- strh r12, [r0, #4]
- ldrh r12, [r1, #6]
- strh r12, [r0, #6]
- add r0, r0, r2
- add r1, r1, r2
-
- ldrh r12, [r1, #0]
- strh r12, [r0, #0]
- ldrh r12, [r1, #2]
- strh r12, [r0, #2]
- ldrh r12, [r1, #4]
- strh r12, [r0, #4]
- ldrh r12, [r1, #6]
- strh r12, [r0, #6]
- add r0, r0, r2
- add r1, r1, r2
-
- ldrh r12, [r1, #0]
- strh r12, [r0, #0]
- ldrh r12, [r1, #2]
- strh r12, [r0, #2]
- ldrh r12, [r1, #4]
- strh r12, [r0, #4]
- ldrh r12, [r1, #6]
- strh r12, [r0, #6]
- add r0, r0, r2
- add r1, r1, r2
-
- ldrh r12, [r1, #0]
- strh r12, [r0, #0]
- ldrh r12, [r1, #2]
- strh r12, [r0, #2]
- ldrh r12, [r1, #4]
- strh r12, [r0, #4]
- ldrh r12, [r1, #6]
- strh r12, [r0, #6]
- add r0, r0, r2
- add r1, r1, r2
-
- ldrh r12, [r1, #0]
- strh r12, [r0, #0]
- ldrh r12, [r1, #2]
- strh r12, [r0, #2]
- ldrh r12, [r1, #4]
- strh r12, [r0, #4]
- ldrh r12, [r1, #6]
- strh r12, [r0, #6]
-
- mov pc, lr
-
-tc_no_w
- mov r3, #8
-tc_b_loop
- ldrb r12, [r1, #0]
- strb r12, [r0, #0]
- ldrb r12, [r1, #1]
- strb r12, [r0, #1]
- ldrb r12, [r1, #2]
- strb r12, [r0, #2]
- ldrb r12, [r1, #3]
- strb r12, [r0, #3]
- ldrb r12, [r1, #4]
- strb r12, [r0, #4]
- ldrb r12, [r1, #5]
- strb r12, [r0, #5]
- ldrb r12, [r1, #6]
- strb r12, [r0, #6]
- ldrb r12, [r1, #7]
- strb r12, [r0, #7]
- add r0, r0, r2
- add r1, r1, r2
-
- subs r3, r3, #1
- bne tc_b_loop
-
- mov pc, lr
-
-;----------------------------
-
- END
\ No newline at end of file