M2VRequantiser-v1.1/LICENSE.txt0000644000000000000000000004310311422311540016143 0ustar rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 Lesser 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. 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.) 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. 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. 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 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. Copyright (C) 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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. , 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 Lesser General Public License instead of this License. M2VRequantiser-v1.1/Makefile0000644000000000000000000000121011422311540015751 0ustar rootroot00000000000000PREFIX ?= /usr/local CC = gcc CFLAGS ?= -O2 -g -funroll-loops -frename-registers CFLAGS += -D_LARGEFILE_SOURCE -DLARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -D_REENTRANT CFLAGS += -Wall OBJECTS = main.o LDFLAGS += -s LOADLIBES += -lm INSTALL ?= install all: M2VRequantiser M2VRequantiser : $(OBJECTS) $(CC) $(CFLAGS) $(OBJECTS) $(LDFLAGS) $(LOADLIBES) -o M2VRequantiser %.o : %.c $(CC) $(CFLAGS) -c $< install: all $(INSTALL) -d $(PREFIX)/bin $(INSTALL) -m 755 M2VRequantiser $(PREFIX)/bin uninstall: rm -f $(PREFIX)/bin/M2VRequantiser clean: rm -f M2VRequantiser *.o *~ core M2VRequantiser-v1.1/README.txt0000644000000000000000000000624211422311540016021 0ustar rootroot00000000000000License Requantize MPEG-2 streams without recompressing. 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Introduction I recently discovered that 'tcrequant' (part of the transcode suite of tools) has been deprecated. Worst still I found that when I ran 'tcrequant' on my 64-bit Linux workstation is was corrupting the video. See the links below for details. - http://tcforge.berlios.de/archives/2009/01/18/transcode_1_1_0_final_release/index.html - http://www.mail-archive.com/transcode-users@exit1.org/msg01773.html Therefore I decided to get the M2VRequantiser code from Metakine working on both 32-bit and 64-bit Linux as a replacement for 'tcrequant'. I've tried to preserve the credits and copyrights where they are known. I forked M2VRequantiser from a source tarball downloaded on April 20th 2009 from the URL below. - http://www.metakine.com/products/dvdremaster/developers.html. These credits/copyrights are taken from the source tarball I downloaded. * M2VRequantiser is based on libmpeg2 and mpeg2enc which are released under the GNU General Public License and copyright by their respective owners. * M2VRequantiser by Makira * New code and modifications copyright Antoine Missout * Thanks to Sven Goethel for error resilience patches Usage M2VRequantiser accepts the raw MPEG2 video data (not VOB) from the standard input and writes the recompressed frames to the standard output. M2VRequantiser takes two arguments. The first one is a floating point value specifying the ratio of compression. The second is the size of the M2V, since the data is streamed to M2VRequantiser it cannot know the M2V size. The following command would recompress 'original.m2v', whose size is 1024000 bytes, by a factor of 1.25. M2VRequantiser 1.25 1024000 < original.m2v > requantised.m2v Install To compile M2VRequantiser run 'make'. To install M2VRequantiser run 'make install' as root. Known Limitations - Only tested on 32-bit and 64-bit Ubuntu. - I am not a C programmer ;-) Source Code You can grab the source from Launchpad. Contributions are welcome :-) - https://code.launchpad.net/m2vrequantiser References - http://www.metakine.com/products/dvdremaster/developers.html - http://lxdvdrip.berlios.de/ v1.1 2010, 23rd July. - Incorporated Debian packaging and patches from Christian Marillat - Now builds for all arches (Works for armel, mipsel and sparc). - Hosted project on Launchpad. v1.0 2009, 23rd April. - Ported Stefan Becker's 64-bit compatibility and argument parsing patches - Added simple progress indicator and Makefile M2VRequantiser-v1.1/debian/0000755000000000000000000000000011422311540015541 5ustar rootroot00000000000000M2VRequantiser-v1.1/debian/README.source0000644000000000000000000000005011422311540017713 0ustar rootroot00000000000000 See /usr/share/doc/quilt/README.source M2VRequantiser-v1.1/debian/changelog0000644000000000000000000000102411422311540017410 0ustar rootroot00000000000000m2vrequantiser (1.1-0.0) unstable; urgency=low * Incorporated Debian packaging and patches from Christian Marillat. -- Martin Wimpress Fri, 23 Jul 2010 13:54:27 +0100 m2vrequantiser (1.0-0.1) unstable; urgency=low * Build for all arches (Works for armel, mipsel and sparc). -- Christian Marillat Sat, 01 May 2010 16:33:20 +0200 m2vrequantiser (1.0-0.0) unstable; urgency=low * Initial release. -- Christian Marillat Sun, 07 Mar 2010 08:43:01 +0100 M2VRequantiser-v1.1/debian/compat0000644000000000000000000000000211422311540016737 0ustar rootroot000000000000007 M2VRequantiser-v1.1/debian/control0000644000000000000000000000071011422311540017142 0ustar rootroot00000000000000Source: m2vrequantiser Section: video Priority: extra Maintainer: Martin Wimpress Bugs: mailto:code@flexion.org Homepage: https://launchpad.net/m2vrequantiser Standards-Version: 3.8.4 Build-Depends: debhelper (>= 7), quilt Package: m2vrequantiser Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Description: requantize MPEG-2 streams without recompressing. m2vrequantiser requantize MPEG-2 streams without recompressing. M2VRequantiser-v1.1/debian/copyright0000644000000000000000000000131211422311540017471 0ustar rootroot00000000000000This work was packaged for Debian by: Martin Wimpress on Fri, 23 Jul 2010 13:54:27 +0100 It was downloaded from: https://launchpad.net/m2vrequantiser Upstream Author: Martin Wimpress Copyright: Copyright © 2010 Martin Wimpress License: You should have received a copy of the GNU General Public License with the Debian GNU/Linux distribution in file /usr/share/common-licenses/GPL-2; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA The Debian packaging is: Copyright © 2010 Martin Wimpress and is licensed under the GPL version 2, see "/usr/share/common-licenses/GPL-2". M2VRequantiser-v1.1/debian/rules0000755000000000000000000000222211422311540016617 0ustar rootroot00000000000000#!/usr/bin/make -f #export DH_VERBOSE=1 include /usr/share/quilt/quilt.make DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE)) CROSS= --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE) else CROSS= --build $(DEB_BUILD_GNU_TYPE) endif build: build-stamp build-stamp: debian/stamp-patched dh_testdir $(MAKE) -j $(NCPUS) touch $@ clean: unpatch dh_testdir dh_testroot rm -f build-stamp [ ! -f Makefile ] || $(MAKE) clean dh_clean install: build dh_testdir dh_testroot dh_prep $(MAKE) install PREFIX=$(CURDIR)/debian/m2vrequantiser/usr # Build architecture-independent files here. binary-indep: build install # Build architecture-dependent files here. binary-arch: build install dh_testdir dh_testroot dh_installdocs README.txt dh_installman dh_installchangelogs dh_link dh_strip dh_compress dh_fixperms dh_makeshlibs dh_installdeb dh_shlibdeps dh_gencontrol dh_md5sums dh_builddeb -- -Zbzip2 binary: binary-indep binary-arch .PHONY: build clean binary-indep binary-arch binary install M2VRequantiser-v1.1/debian/source/0000755000000000000000000000000011422311540017041 5ustar rootroot00000000000000M2VRequantiser-v1.1/debian/source/format0000644000000000000000000000000411422311540020246 0ustar rootroot000000000000001.0 M2VRequantiser-v1.1/debian/watch0000644000000000000000000000014211422311540016567 0ustar rootroot00000000000000version=3 http://launchpad.net/m2vrequantiser/trunk/(.*)/+download/M2VRequantiser-v(.*)\.tar\.gz M2VRequantiser-v1.1/getvlc.h0000644000000000000000000003742411422311540015766 0ustar rootroot00000000000000 /* macroblock modes */ #define MACROBLOCK_INTRA 1 #define MACROBLOCK_PATTERN 2 #define MACROBLOCK_MOTION_BACKWARD 4 #define MACROBLOCK_MOTION_FORWARD 8 #define MACROBLOCK_QUANT 16 #define DCT_TYPE_INTERLACED 32 /* motion_type */ #define MOTION_TYPE_MASK (3*64) #define MOTION_TYPE_BASE 64 #define MC_FIELD (1*64) #define MC_FRAME (2*64) #define MC_16X8 (2*64) #define MC_DMV (3*64) /* picture structure */ #define TOP_FIELD 1 #define BOTTOM_FIELD 2 #define FRAME_PICTURE 3 /* remove num valid bits from bit_buf */ #define DUMPBITS(bit_buf,bits,num) Flush_Bits(num) #define COPYBITS(bit_buf,bits,num) Copy_Bits(num) /* take num bits from the high part of bit_buf and zero extend them */ #define UBITS(bit_buf,num) (((uint32_t)(inbitbuf)) >> (32 - (num))) /* take num bits from the high part of bit_buf and sign extend them */ #define SBITS(bit_buf,num) (((int32_t)(inbitbuf)) >> (32 - (num))) typedef struct { uint8_t modes; uint8_t len; } MBtab; typedef struct { uint8_t delta; uint8_t len; } MVtab; typedef struct { int8_t dmv; uint8_t len; } DMVtab; typedef struct { uint8_t cbp; uint8_t len; } CBPtab; typedef struct { uint8_t size; uint8_t len; } DCtab; typedef struct { uint8_t run; uint8_t level; uint8_t len; } DCTtab; typedef struct { uint8_t mba; uint8_t len; } MBAtab; #define INTRA MACROBLOCK_INTRA #define QUANT MACROBLOCK_QUANT static const MBtab MB_I [] = { {INTRA|QUANT, 2}, {INTRA, 1} }; #define MC MACROBLOCK_MOTION_FORWARD #define CODED MACROBLOCK_PATTERN static const MBtab MB_P [] = { {INTRA|QUANT, 6}, {CODED|QUANT, 5}, {MC|CODED|QUANT, 5}, {INTRA, 5}, {MC, 3}, {MC, 3}, {MC, 3}, {MC, 3}, {CODED, 2}, {CODED, 2}, {CODED, 2}, {CODED, 2}, {CODED, 2}, {CODED, 2}, {CODED, 2}, {CODED, 2}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1}, {MC|CODED, 1} }; #define FWD MACROBLOCK_MOTION_FORWARD #define BWD MACROBLOCK_MOTION_BACKWARD #define INTER MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD static const MBtab MB_B [] = { {0, 0}, {INTRA|QUANT, 6}, {BWD|CODED|QUANT, 6}, {FWD|CODED|QUANT, 6}, {INTER|CODED|QUANT, 5}, {INTER|CODED|QUANT, 5}, {INTRA, 5}, {INTRA, 5}, {FWD, 4}, {FWD, 4}, {FWD, 4}, {FWD, 4}, {FWD|CODED, 4}, {FWD|CODED, 4}, {FWD|CODED, 4}, {FWD|CODED, 4}, {BWD, 3}, {BWD, 3}, {BWD, 3}, {BWD, 3}, {BWD, 3}, {BWD, 3}, {BWD, 3}, {BWD, 3}, {BWD|CODED, 3}, {BWD|CODED, 3}, {BWD|CODED, 3}, {BWD|CODED, 3}, {BWD|CODED, 3}, {BWD|CODED, 3}, {BWD|CODED, 3}, {BWD|CODED, 3}, {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2} }; #undef INTRA #undef QUANT #undef MC #undef CODED #undef FWD #undef BWD #undef INTER static const MVtab MV_4 [] = { { 3, 6}, { 2, 4}, { 1, 3}, { 1, 3}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2} }; static const MVtab MV_10 [] = { { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, {15,10}, {14,10}, {13,10}, {12,10}, {11,10}, {10,10}, { 9, 9}, { 9, 9}, { 8, 9}, { 8, 9}, { 7, 9}, { 7, 9}, { 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}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7} }; static const DMVtab DMV_2 [] = { { 0, 1}, { 0, 1}, { 1, 2}, {-1, 2} }; static const CBPtab CBP_7 [] = { {0x22, 7}, {0x12, 7}, {0x0a, 7}, {0x06, 7}, {0x21, 7}, {0x11, 7}, {0x09, 7}, {0x05, 7}, {0x3f, 6}, {0x3f, 6}, {0x03, 6}, {0x03, 6}, {0x24, 6}, {0x24, 6}, {0x18, 6}, {0x18, 6}, {0x3e, 5}, {0x3e, 5}, {0x3e, 5}, {0x3e, 5}, {0x02, 5}, {0x02, 5}, {0x02, 5}, {0x02, 5}, {0x3d, 5}, {0x3d, 5}, {0x3d, 5}, {0x3d, 5}, {0x01, 5}, {0x01, 5}, {0x01, 5}, {0x01, 5}, {0x38, 5}, {0x38, 5}, {0x38, 5}, {0x38, 5}, {0x34, 5}, {0x34, 5}, {0x34, 5}, {0x34, 5}, {0x2c, 5}, {0x2c, 5}, {0x2c, 5}, {0x2c, 5}, {0x1c, 5}, {0x1c, 5}, {0x1c, 5}, {0x1c, 5}, {0x28, 5}, {0x28, 5}, {0x28, 5}, {0x28, 5}, {0x14, 5}, {0x14, 5}, {0x14, 5}, {0x14, 5}, {0x30, 5}, {0x30, 5}, {0x30, 5}, {0x30, 5}, {0x0c, 5}, {0x0c, 5}, {0x0c, 5}, {0x0c, 5}, {0x20, 4}, {0x20, 4}, {0x20, 4}, {0x20, 4}, {0x20, 4}, {0x20, 4}, {0x20, 4}, {0x20, 4}, {0x10, 4}, {0x10, 4}, {0x10, 4}, {0x10, 4}, {0x10, 4}, {0x10, 4}, {0x10, 4}, {0x10, 4}, {0x08, 4}, {0x08, 4}, {0x08, 4}, {0x08, 4}, {0x08, 4}, {0x08, 4}, {0x08, 4}, {0x08, 4}, {0x04, 4}, {0x04, 4}, {0x04, 4}, {0x04, 4}, {0x04, 4}, {0x04, 4}, {0x04, 4}, {0x04, 4}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3} }; static const CBPtab CBP_9 [] = { {0, 0}, {0x00, 9}, {0x27, 9}, {0x1b, 9}, {0x3b, 9}, {0x37, 9}, {0x2f, 9}, {0x1f, 9}, {0x3a, 8}, {0x3a, 8}, {0x36, 8}, {0x36, 8}, {0x2e, 8}, {0x2e, 8}, {0x1e, 8}, {0x1e, 8}, {0x39, 8}, {0x39, 8}, {0x35, 8}, {0x35, 8}, {0x2d, 8}, {0x2d, 8}, {0x1d, 8}, {0x1d, 8}, {0x26, 8}, {0x26, 8}, {0x1a, 8}, {0x1a, 8}, {0x25, 8}, {0x25, 8}, {0x19, 8}, {0x19, 8}, {0x2b, 8}, {0x2b, 8}, {0x17, 8}, {0x17, 8}, {0x33, 8}, {0x33, 8}, {0x0f, 8}, {0x0f, 8}, {0x2a, 8}, {0x2a, 8}, {0x16, 8}, {0x16, 8}, {0x32, 8}, {0x32, 8}, {0x0e, 8}, {0x0e, 8}, {0x29, 8}, {0x29, 8}, {0x15, 8}, {0x15, 8}, {0x31, 8}, {0x31, 8}, {0x0d, 8}, {0x0d, 8}, {0x23, 8}, {0x23, 8}, {0x13, 8}, {0x13, 8}, {0x0b, 8}, {0x0b, 8}, {0x07, 8}, {0x07, 8} }; static const DCtab DC_lum_5 [] = { {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {0, 3}, {0, 3}, {0, 3}, {0, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {4, 3}, {4, 3}, {4, 3}, {4, 3}, {5, 4}, {5, 4}, {6, 5} }; static const DCtab DC_chrom_5 [] = { {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, {4, 4}, {4, 4}, {5, 5} }; static const DCtab DC_long [] = { {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, { 6, 5}, { 6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, { 6, 5}, { 6, 5}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, { 7, 6}, { 7, 6}, {8, 7}, {8, 7}, {8, 7}, {8, 7}, {9, 8}, {9, 8}, {10, 9}, {11, 9} }; static const DCTtab DCT_16 [] = { {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, { 2,18, 0}, { 2,17, 0}, { 2,16, 0}, { 2,15, 0}, { 7, 3, 0}, { 17, 2, 0}, { 16, 2, 0}, { 15, 2, 0}, { 14, 2, 0}, { 13, 2, 0}, { 12, 2, 0}, { 32, 1, 0}, { 31, 1, 0}, { 30, 1, 0}, { 29, 1, 0}, { 28, 1, 0} }; static const DCTtab DCT_15 [] = { { 1,40,15}, { 1,39,15}, { 1,38,15}, { 1,37,15}, { 1,36,15}, { 1,35,15}, { 1,34,15}, { 1,33,15}, { 1,32,15}, { 2,14,15}, { 2,13,15}, { 2,12,15}, { 2,11,15}, { 2,10,15}, { 2, 9,15}, { 2, 8,15}, { 1,31,14}, { 1,31,14}, { 1,30,14}, { 1,30,14}, { 1,29,14}, { 1,29,14}, { 1,28,14}, { 1,28,14}, { 1,27,14}, { 1,27,14}, { 1,26,14}, { 1,26,14}, { 1,25,14}, { 1,25,14}, { 1,24,14}, { 1,24,14}, { 1,23,14}, { 1,23,14}, { 1,22,14}, { 1,22,14}, { 1,21,14}, { 1,21,14}, { 1,20,14}, { 1,20,14}, { 1,19,14}, { 1,19,14}, { 1,18,14}, { 1,18,14}, { 1,17,14}, { 1,17,14}, { 1,16,14}, { 1,16,14} }; static const DCTtab DCT_13 [] = { { 11, 2,13}, { 10, 2,13}, { 6, 3,13}, { 4, 4,13}, { 3, 5,13}, { 2, 7,13}, { 2, 6,13}, { 1,15,13}, { 1,14,13}, { 1,13,13}, { 1,12,13}, { 27, 1,13}, { 26, 1,13}, { 25, 1,13}, { 24, 1,13}, { 23, 1,13}, { 1,11,12}, { 1,11,12}, { 9, 2,12}, { 9, 2,12}, { 5, 3,12}, { 5, 3,12}, { 1,10,12}, { 1,10,12}, { 3, 4,12}, { 3, 4,12}, { 8, 2,12}, { 8, 2,12}, { 22, 1,12}, { 22, 1,12}, { 21, 1,12}, { 21, 1,12}, { 1, 9,12}, { 1, 9,12}, { 20, 1,12}, { 20, 1,12}, { 19, 1,12}, { 19, 1,12}, { 2, 5,12}, { 2, 5,12}, { 4, 3,12}, { 4, 3,12}, { 1, 8,12}, { 1, 8,12}, { 7, 2,12}, { 7, 2,12}, { 18, 1,12}, { 18, 1,12} }; static const DCTtab DCT_B14_10 [] = { { 17, 1,10}, { 6, 2,10}, { 1, 7,10}, { 3, 3,10}, { 2, 4,10}, { 16, 1,10}, { 15, 1,10}, { 5, 2,10} }; static const DCTtab DCT_B14_8 [] = { { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6}, { 3, 2, 7}, { 3, 2, 7}, { 10, 1, 7}, { 10, 1, 7}, { 1, 4, 7}, { 1, 4, 7}, { 9, 1, 7}, { 9, 1, 7}, { 8, 1, 6}, { 8, 1, 6}, { 8, 1, 6}, { 8, 1, 6}, { 7, 1, 6}, { 7, 1, 6}, { 7, 1, 6}, { 7, 1, 6}, { 2, 2, 6}, { 2, 2, 6}, { 2, 2, 6}, { 2, 2, 6}, { 6, 1, 6}, { 6, 1, 6}, { 6, 1, 6}, { 6, 1, 6}, { 14, 1, 8}, { 1, 6, 8}, { 13, 1, 8}, { 12, 1, 8}, { 4, 2, 8}, { 2, 3, 8}, { 1, 5, 8}, { 11, 1, 8} }; static const DCTtab DCT_B14AC_5 [] = { { 1, 3, 5}, { 5, 1, 5}, { 4, 1, 5}, { 1, 2, 4}, { 1, 2, 4}, { 3, 1, 4}, { 3, 1, 4}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2} }; static const DCTtab DCT_B14DC_5 [] = { { 1, 3, 5}, { 5, 1, 5}, { 4, 1, 5}, { 1, 2, 4}, { 1, 2, 4}, { 3, 1, 4}, { 3, 1, 4}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 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}, { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1} }; static const DCTtab DCT_B15_10 [] = { { 6, 2, 9}, { 6, 2, 9}, { 15, 1, 9}, { 15, 1, 9}, { 3, 4,10}, { 17, 1,10}, { 16, 1, 9}, { 16, 1, 9} }; static const DCTtab DCT_B15_8 [] = { { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6}, { 8, 1, 7}, { 8, 1, 7}, { 9, 1, 7}, { 9, 1, 7}, { 7, 1, 7}, { 7, 1, 7}, { 3, 2, 7}, { 3, 2, 7}, { 1, 7, 6}, { 1, 7, 6}, { 1, 7, 6}, { 1, 7, 6}, { 1, 6, 6}, { 1, 6, 6}, { 1, 6, 6}, { 1, 6, 6}, { 5, 1, 6}, { 5, 1, 6}, { 5, 1, 6}, { 5, 1, 6}, { 6, 1, 6}, { 6, 1, 6}, { 6, 1, 6}, { 6, 1, 6}, { 2, 5, 8}, { 12, 1, 8}, { 1,11, 8}, { 1,10, 8}, { 14, 1, 8}, { 13, 1, 8}, { 4, 2, 8}, { 2, 4, 8}, { 3, 1, 5}, { 3, 1, 5}, { 3, 1, 5}, { 3, 1, 5}, { 3, 1, 5}, { 3, 1, 5}, { 3, 1, 5}, { 3, 1, 5}, { 2, 2, 5}, { 2, 2, 5}, { 2, 2, 5}, { 2, 2, 5}, { 2, 2, 5}, { 2, 2, 5}, { 2, 2, 5}, { 2, 2, 5}, { 4, 1, 5}, { 4, 1, 5}, { 4, 1, 5}, { 4, 1, 5}, { 4, 1, 5}, { 4, 1, 5}, { 4, 1, 5}, { 4, 1, 5}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 3, 4}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 1, 2}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 2, 3}, { 1, 4, 5}, { 1, 4, 5}, { 1, 4, 5}, { 1, 4, 5}, { 1, 4, 5}, { 1, 4, 5}, { 1, 4, 5}, { 1, 4, 5}, { 1, 5, 5}, { 1, 5, 5}, { 1, 5, 5}, { 1, 5, 5}, { 1, 5, 5}, { 1, 5, 5}, { 1, 5, 5}, { 1, 5, 5}, { 10, 1, 7}, { 10, 1, 7}, { 2, 3, 7}, { 2, 3, 7}, { 11, 1, 7}, { 11, 1, 7}, { 1, 8, 7}, { 1, 8, 7}, { 1, 9, 7}, { 1, 9, 7}, { 1,12, 8}, { 1,13, 8}, { 3, 3, 8}, { 5, 2, 8}, { 1,14, 8}, { 1,15, 8} }; static const MBAtab MBA_5 [] = { {6, 5}, {5, 5}, {4, 4}, {4, 4}, {3, 4}, {3, 4}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1} }; static const MBAtab MBA_11 [] = { {32, 11}, {31, 11}, {30, 11}, {29, 11}, {28, 11}, {27, 11}, {26, 11}, {25, 11}, {24, 11}, {23, 11}, {22, 11}, {21, 11}, {20, 10}, {20, 10}, {19, 10}, {19, 10}, {18, 10}, {18, 10}, {17, 10}, {17, 10}, {16, 10}, {16, 10}, {15, 10}, {15, 10}, {14, 8}, {14, 8}, {14, 8}, {14, 8}, {14, 8}, {14, 8}, {14, 8}, {14, 8}, {13, 8}, {13, 8}, {13, 8}, {13, 8}, {13, 8}, {13, 8}, {13, 8}, {13, 8}, {12, 8}, {12, 8}, {12, 8}, {12, 8}, {12, 8}, {12, 8}, {12, 8}, {12, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {11, 8}, {10, 8}, {10, 8}, {10, 8}, {10, 8}, {10, 8}, {10, 8}, {10, 8}, {10, 8}, { 9, 8}, { 9, 8}, { 9, 8}, { 9, 8}, { 9, 8}, { 9, 8}, { 9, 8}, { 9, 8}, { 8, 7}, { 8, 7}, { 8, 7}, { 8, 7}, { 8, 7}, { 8, 7}, { 8, 7}, { 8, 7}, { 8, 7}, { 8, 7}, { 8, 7}, { 8, 7}, { 8, 7}, { 8, 7}, { 8, 7}, { 8, 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, 7} }; M2VRequantiser-v1.1/main.c0000644000000000000000000017506211422311540015422 0ustar rootroot00000000000000/* Requantize MPEG-2 streams without recompressing. 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Code from libmpeg2 and mpeg2enc copyright by their respective owners New code and modifications copyright Antoine Missout Thanks to Sven Goethel for error resilience patches */ // toggles: // #define LOG_RATE_CONTROL // some stats // #define DEMO // demo mode // #define STAT // print stats on exit // #define USE_FD // use 2 lasts args for input/output paths #define NDEBUG // turns off asserts #define REMOVE_BYTE_STUFFING // removes series of 0x00 #if defined(__ppc__) || defined(__ppc64__) #define USE_GLOBAL_REGISTER // assign registers to bit buffers #elif defined(__i386__) || defined (__x86_64__) // #define USE_GLOBAL_REGISTER // assign registers to bit buffers //#else //# #error "Unknown Architecture" #endif #define MAX_ERRORS 0 // if above copy slice //#define CHANGE_BRIGHTNESS //add a param to command line, changing brightness: _will_not_recompress_, disables max_errors //#define WIN // for windows fixes, use with USE_FD // params: // if not defined, non intra block in p frames are requantised // if defined and >= 0, we keep coeff. in pos 0..n-1 in scan order // and coeff which would have been non-null if requantised // if defined and < 0 we drop max 1/x coeffs. // experimental, looks better when undefined // #define P_FRAME_NON_INTRA_DROP 8 // params for fact = 1.0, fact = 3.0 and fact = 10.0 // we'll make a linear interpolation between static const int i_factors[3] = { 5, 15, 65 }; static const int p_factors[3] = { 5, 25, 85 }; static const int b_factors[3] = { 25, 45, 105 }; static const double i_min_stresses[3] = { 0.80, 0.50, 0.00 }; static const double p_min_stresses[3] = { 0.60, 0.35, 0.00 }; static const double b_min_stresses[3] = { 0.00, 0.00, 0.00 }; // factor up to which alt table will be used // (though alt_table gives better psnr up to factor around ~2.5 // the result is less pleasing to watch than normal table // so this is disabled) static const double max_alt_table = 0.00; // includes #include #include #include #include #include #ifndef USE_FD #include #include #endif // quant table #include "qTable.h" // useful constants #define I_TYPE 1 #define P_TYPE 2 #define B_TYPE 3 #ifdef WIN #define MINLINE #else #define MINLINE inline #endif // gcc #ifdef HAVE_BUILTIN_EXPECT #define likely(x) __builtin_expect ((x) != 0, 1) #define unlikely(x) __builtin_expect ((x) != 0, 0) #else #define likely(x) (x) #define unlikely(x) (x) #endif // user defined types //typedef unsigned int uint; typedef unsigned char uint8; typedef unsigned short uint16; typedef unsigned int uint32; #ifdef WIN typedef __int64 uint64; #else typedef unsigned long long uint64; #endif typedef char int8; typedef short int16; typedef int int32; #ifdef WIN typedef __int64 int64; #else typedef long long int64; #endif typedef signed int sint; typedef signed char sint8; typedef signed short sint16; typedef signed int sint32; #ifdef WIN typedef __int64 sint64; #else typedef signed long long sint64; #endif #define BITS_IN_BUF (8) // global variables static uint8 *cbuf, *rbuf, *wbuf, *orbuf, *owbuf; #ifdef USE_GLOBAL_REGISTER register int inbitcnt asm ("r13"); register int outbitcnt asm ("r14"); register uint32 inbitbuf asm ("r15"); register uint32 outbitbuf asm ("r16"); #else static int inbitcnt, outbitcnt; static uint32 inbitbuf, outbitbuf; #endif static uint64 inbytecnt, outbytecnt; static float fact_x; static int mloka1, mloka2, eof; static int64 orim2vsize; static int64 bytediff; static double stress_factor; // from 0.0 to 1.0 static int i_factor; static int p_factor; static int b_factor; static double i_min_stress; static double p_min_stress; static double b_min_stress; static short quant_table_id_data[4096]; static short *quant_table_id = &quant_table_id_data[2048]; #ifdef USE_FD static FILE *ifd, *ofd; #endif #ifdef STAT static uint64 ori_i, ori_p, ori_b; static uint64 new_i, new_p, new_b; static uint64 cnt_i, cnt_p, cnt_b; static uint64 cnt_p_i, cnt_p_ni; static uint64 cnt_b_i, cnt_b_ni; #endif #ifdef DEMO // gopCount variable int gopCount; #endif #ifdef LOG_RATE_CONTROL FILE* LOG_FILE; #endif #ifdef CHANGE_BRIGHTNESS int delta_bright; int dc_reset; int old_dc_pred, new_dc_pred; #endif // mpeg2 state // seq header static uint horizontal_size_value; static uint vertical_size_value; // pic header static uint picture_coding_type; // pic code ext static uint f_code[2][2]; static uint intra_dc_precision; static uint picture_structure; static uint frame_pred_frame_dct; static uint concealment_motion_vectors; static uint q_scale_type; static uint intra_vlc_format; static uint alternate_scan; // error static int validPicHeader; static int validSeqHeader; static int validExtHeader; static int sliceError; // slice or mb static uint quantizer_scale; static uint new_quantizer_scale; static uint last_coded_scale; static int h_offset, v_offset; static int mb_skip, mb_add; static int mb_out; static int mb_sav_run, mb_sav_lev, mb_sav_c; static short *curTable; // block data typedef struct { uint8 run; short level; } RunLevel; static RunLevel block[6][65]; // terminated by level = 0, so we need 64+1 // end mpeg2 state #ifndef NDEBUG #define DEB(msg) fprintf (stderr, "%s:%d " msg, __FILE__, __LINE__) #define DEBF(format, args...) fprintf (stderr, "%s:%d " format, __FILE__, __LINE__, args) #else #define DEB(msg) #ifdef WIN #define DEBF(format, args) #else #define DEBF(format, args...) #endif #endif #define LOG(msg) fprintf (stderr, msg) #ifdef WIN #define LOGF(format, arg1) fprintf (stderr, format, arg1) #else #define LOGF(format, args...) fprintf (stderr, format, args) #endif #define BUF_SIZE (16*1024*1024) #define MIN_READ (4*1024*1024) #define MIN_WRITE (8*1024*1024) #define MAX_READ (10*1024*1024) #define MOV_READ \ mloka1 = rbuf - cbuf; if (mloka1) memmove(orbuf, cbuf, mloka1);\ cbuf = rbuf = orbuf; rbuf += mloka1; #ifdef USE_FD #define WRITE \ mloka1 = wbuf - owbuf; \ fwrite(owbuf, mloka1, 1, ofd); \ outbytecnt += mloka1; \ wbuf = owbuf; #define LOCK(x) \ while (unlikely(x > (rbuf-cbuf))) \ { \ if (!eof)\ { \ mloka2 = MIN_READ; \ while (mloka2) \ {\ assert(rbuf + mloka2 < orbuf + BUF_SIZE); \ mloka1 = fread(rbuf, 1, mloka2, ifd); \ if (mloka1 <= 0) { eof = 1; break; } \ inbytecnt += mloka1; \ rbuf += mloka1; \ mloka2 -= mloka1; \ }\ } else { RETURN } \ } #else #define WRITE \ mloka1 = wbuf - owbuf; \ write(1, owbuf, mloka1); \ outbytecnt += mloka1; \ wbuf = owbuf; \ mloka1 = rbuf - cbuf; if (mloka1) memmove(orbuf, cbuf, mloka1);\ cbuf = rbuf = orbuf; rbuf += mloka1; #define LOCK(x) \ while (unlikely(x > (rbuf-cbuf))) \ { \ if (!eof)\ { \ mloka2 = MIN_READ; \ while (mloka2) \ {\ assert(rbuf + mloka2 < orbuf + BUF_SIZE); \ mloka1 = read(0, rbuf, mloka2); \ if (mloka1 <= 0) { eof = 1; break; } \ inbytecnt += mloka1; \ rbuf += mloka1; \ mloka2 -= mloka1; \ }\ } else { RETURN } \ } #endif #ifdef STAT #define RETURN \ assert(rbuf >= cbuf);\ mloka1 = rbuf - cbuf;\ if (mloka1) { COPY(mloka1); }\ WRITE \ free(orbuf); \ free(owbuf); \ \ LOG("Stats:\n");\ \ LOGF("Wanted fact_x: %.1f\n", fact_x);\ \ LOGF("cnt_i: %.0f ", (float)cnt_i); \ if (cnt_i) LOGF("ori_i: %.0f new_i: %.0f fact_i: %.1f\n", (float)ori_i, (float)new_i, (float)ori_i/(float)new_i); \ else LOG("\n");\ \ LOGF("cnt_p: %.0f ", (float)cnt_p); \ if (cnt_p) LOGF("ori_p: %.0f new_p: %.0f fact_p: %.1f cnt_p_i: %.0f cnt_p_ni: %.0f propor: %.1f i\n", \ (float)ori_p, (float)new_p, (float)ori_p/(float)new_p, (float)cnt_p_i, (float)cnt_p_ni, (float)cnt_p_i/((float)cnt_p_i+(float)cnt_p_ni)); \ else LOG("\n");\ \ LOGF("cnt_b: %.0f ", (float)cnt_b); \ if (cnt_b) LOGF("ori_b: %.0f new_b: %.0f fact_b: %.1f cnt_b_i: %.0f cnt_b_ni: %.0f propor: %.1f i\n", \ (float)ori_b, (float)new_b, (float)ori_b/(float)new_b, (float)cnt_b_i, (float)cnt_b_ni, (float)cnt_b_i/((float)cnt_b_i+(float)cnt_b_ni)); \ else LOG("\n");\ \ LOGF("Final fact_x: %.1f\n", (float)inbytecnt/(float)outbytecnt);\ exit(0); #else #define RETURN \ assert(rbuf >= cbuf);\ mloka1 = rbuf - cbuf;\ if (mloka1) { COPY(mloka1); }\ WRITE \ free(orbuf); \ free(owbuf); \ exit(0); #endif #define COPY(x)\ assert(x > 0); \ assert(wbuf + x < owbuf + BUF_SIZE); \ assert(cbuf + x < orbuf + BUF_SIZE); \ assert(cbuf + x >= orbuf); \ assert(wbuf + x >= orbuf); \ memcpy(wbuf, cbuf, x);\ cbuf += x; \ wbuf += x; #define SEEKR(x)\ cbuf += x; \ assert (cbuf <= rbuf); \ assert (cbuf < orbuf + BUF_SIZE); \ assert (cbuf >= orbuf); #define SEEKW(x)\ wbuf += x; \ assert (wbuf < owbuf + BUF_SIZE); \ assert (wbuf >= owbuf); static MINLINE void putbits(uint val, int n) { assert(n < 32); assert(!(val & (0xffffffffU << n))); while (unlikely(n >= outbitcnt)) { wbuf[0] = (outbitbuf << outbitcnt ) | (val >> (n - outbitcnt)); SEEKW(1); n -= outbitcnt; outbitbuf = 0; val &= ~(0xffffffffU << n); outbitcnt = BITS_IN_BUF; } if (likely(n)) { outbitbuf = (outbitbuf << n) | val; outbitcnt -= n; } assert(outbitcnt > 0); assert(outbitcnt <= BITS_IN_BUF); } static MINLINE void Refill_bits(void) { assert((rbuf - cbuf) >= 1); inbitbuf |= cbuf[0] << (24 - inbitcnt); inbitcnt += 8; SEEKR(1) } static MINLINE void Flush_Bits(uint n) { assert(inbitcnt >= n); inbitbuf <<= n; inbitcnt -= n; assert( (!n) || ((n>0) && !(inbitbuf & 0x1)) ); while (unlikely(inbitcnt < 24)) Refill_bits(); } static MINLINE uint Show_Bits(uint n) { return ((unsigned int)inbitbuf) >> (32 - n); } static MINLINE uint Get_Bits(uint n) { uint Val = Show_Bits(n); Flush_Bits(n); return Val; } static MINLINE uint Copy_Bits(uint n) { uint Val = Get_Bits(n); putbits(Val, n); return Val; } static MINLINE void flush_read_buffer() { int i = inbitcnt & 0x7; if (i) { if (inbitbuf >> (32 - i)) { DEBF("illegal inbitbuf: 0x%08X, %i, 0x%02X, %i\n", inbitbuf, inbitcnt, (inbitbuf >> (32 - i)), i); sliceError++; } inbitbuf <<= i; inbitcnt -= i; } SEEKR(-1 * (inbitcnt >> 3)); inbitcnt = 0; } static MINLINE void flush_write_buffer() { if (outbitcnt != 8) putbits(0, outbitcnt); } /////---- begin ext mpeg code const uint8 non_linear_mquant_table[32] = { 0, 1, 2, 3, 4, 5, 6, 7, 8,10,12,14,16,18,20,22, 24,28,32,36,40,44,48,52, 56,64,72,80,88,96,104,112 }; const uint8 map_non_linear_mquant[113] = { 0,1,2,3,4,5,6,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16, 16,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,22,22, 22,22,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26, 26,26,26,26,26,26,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,29, 29,29,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31,31,31,31,31 }; static int scale_quant(double quant ) { int iquant; if (q_scale_type) { iquant = (int) floor(quant+0.5); /* clip mquant to legal (linear) range */ if (iquant<1) iquant = 1; if (iquant>112) iquant = 112; iquant = non_linear_mquant_table[map_non_linear_mquant[iquant]]; } else { /* clip mquant to legal (linear) range */ iquant = (int)floor(quant+0.5); if (iquant<2) iquant = 2; if (iquant>62) iquant = 62; iquant = (iquant/2)*2; // Must be *even* } return iquant; } static int increment_quant(int quant) { if (q_scale_type) { if (quant < 1 || quant > 112) { DEBF("illegal quant: %d\n", quant); if (quant > 112) quant = 112; else if (quant < 1) quant = 1; DEBF("illegal quant changed to : %d\n", quant); sliceError++; } quant = map_non_linear_mquant[quant] + 1; if (quant > 31) quant = 31; quant = non_linear_mquant_table[quant]; } else { if ((quant & 1) || (quant < 2) || (quant > 62)) { DEBF("illegal quant: %d\n", quant); if (quant & 1) quant--; if (quant > 62) quant = 62; else if (quant < 2) quant = 2; DEBF("illegal quant changed to : %d\n", quant); sliceError++; } quant += 2; if (quant > 62) quant = 62; } return quant; } static MINLINE int intmax( register int x, register int y ) { return x < y ? y : x; } static MINLINE int intmin( register int x, register int y ) { return x < y ? x : y; } static int getNewQuant(int curQuant, int intra) { #ifdef CHANGE_BRIGHTNESS return curQuant; #else int mquant = 0; double cStress; switch (picture_coding_type) { case I_TYPE: cStress = (stress_factor - i_min_stress) / (1.0 - i_min_stress); mquant = intmax(scale_quant(curQuant + i_factor*cStress), increment_quant(curQuant)); break; case P_TYPE: cStress = (stress_factor - p_min_stress) / (1.0 - p_min_stress); if (intra) // since it might be used as a ref, treat it as an I frame block mquant = intmax(scale_quant(curQuant + i_factor*cStress), increment_quant(curQuant)); else mquant = intmax(scale_quant(curQuant + p_factor*cStress), increment_quant(curQuant)); break; case B_TYPE: cStress = (stress_factor - b_min_stress) / (1.0 - b_min_stress); mquant = intmax(scale_quant(curQuant + b_factor*cStress), increment_quant(curQuant)); break; default: assert(0); break; } assert(mquant >= curQuant); return mquant; #endif } static MINLINE int isNotEmpty(RunLevel *blk) { return (blk->level); } #include "putvlc.h" // return != 0 if error int putAC(int run, int signed_level, int vlcformat) { int level, len; const VLCtable *ptab = NULL; level = (signed_level<0) ? -signed_level : signed_level; /* abs(signed_level) */ // assert(!(run<0 || run>63 || level==0 || level>2047)); if(run<0 || run>63) { DEBF("illegal run: %d\n", run); sliceError++; return 1; } if(level==0 || level>2047) { DEBF("illegal level: %d\n", level); sliceError++; return 1; } len = 0; if (run<2 && level<41) { if (vlcformat) ptab = &dct_code_tab1a[run][level-1]; else ptab = &dct_code_tab1[run][level-1]; len = ptab->len; } else if (run<32 && level<6) { if (vlcformat) ptab = &dct_code_tab2a[run-2][level-1]; else ptab = &dct_code_tab2[run-2][level-1]; len = ptab->len; } if (len) /* a VLC code exists */ { putbits(ptab->code, len); putbits(signed_level<0, 1); /* sign */ } else { putbits(1l, 6); /* Escape */ putbits(run, 6); /* 6 bit code for run */ putbits(((uint)signed_level) & 0xFFF, 12); } return 0; } // return != 0 if error static MINLINE int putACfirst(int run, int val) { if (run==0 && (val==1 || val==-1)) { putbits(2|((val<0) ? 1 : 0), 2); return 0; } else return putAC(run,val,0); } void putnonintrablk(RunLevel *blk) { assert(blk->level); if (putACfirst(blk->run, blk->level)) return; blk++; while(blk->level) { if (putAC(blk->run, blk->level, 0)) return; blk++; } putbits(2,2); } static MINLINE void putcbp(int cbp) { assert(cbp > 0 && cbp < 64); putbits(cbptable[cbp].code,cbptable[cbp].len); } static void putmbtype(int mb_type) { putbits(mbtypetab[picture_coding_type-1][mb_type].code, mbtypetab[picture_coding_type-1][mb_type].len); } #ifndef WIN #include #else typedef uint8 uint8_t; typedef int8 int8_t; typedef uint32 uint32_t; typedef int32 int32_t; #endif #include "getvlc.h" static int non_linear_quantizer_scale [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 18, 20, 22, 24, 28, 32, 36, 40, 44, 48, 52, 56, 64, 72, 80, 88, 96, 104, 112 }; static MINLINE int get_macroblock_modes () { int macroblock_modes; const MBtab * tab; switch (picture_coding_type) { case I_TYPE: tab = MB_I + UBITS (bit_buf, 1); DUMPBITS (bit_buf, bits, tab->len); macroblock_modes = tab->modes; if ((! (frame_pred_frame_dct)) && (picture_structure == FRAME_PICTURE)) { macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; DUMPBITS (bit_buf, bits, 1); } return macroblock_modes; case P_TYPE: tab = MB_P + UBITS (bit_buf, 5); DUMPBITS (bit_buf, bits, tab->len); macroblock_modes = tab->modes; if (picture_structure != FRAME_PICTURE) { if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) { macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE; DUMPBITS (bit_buf, bits, 2); } return macroblock_modes; } else if (frame_pred_frame_dct) { if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) macroblock_modes |= MC_FRAME; return macroblock_modes; } else { if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) { macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE; DUMPBITS (bit_buf, bits, 2); } if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) { macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; DUMPBITS (bit_buf, bits, 1); } return macroblock_modes; } case B_TYPE: tab = MB_B + UBITS (bit_buf, 6); DUMPBITS (bit_buf, bits, tab->len); macroblock_modes = tab->modes; if (picture_structure != FRAME_PICTURE) { if (! (macroblock_modes & MACROBLOCK_INTRA)) { macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE; DUMPBITS (bit_buf, bits, 2); } return macroblock_modes; } else if (frame_pred_frame_dct) { /* if (! (macroblock_modes & MACROBLOCK_INTRA)) */ macroblock_modes |= MC_FRAME; return macroblock_modes; } else { if (macroblock_modes & MACROBLOCK_INTRA) goto intra; macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE; DUMPBITS (bit_buf, bits, 2); if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) { intra: macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; DUMPBITS (bit_buf, bits, 1); } return macroblock_modes; } default: return 0; } } static MINLINE int get_quantizer_scale () { int quantizer_scale_code; quantizer_scale_code = UBITS (bit_buf, 5); DUMPBITS (bit_buf, bits, 5); if (!quantizer_scale_code) { DEBF("illegal quant scale code: %d\n", quantizer_scale_code); sliceError++; quantizer_scale_code++; } if (q_scale_type) return non_linear_quantizer_scale[quantizer_scale_code]; else return quantizer_scale_code << 1; } static MINLINE void get_motion_delta (const int f_code) { #define bit_buf (inbitbuf) const MVtab * tab; if (bit_buf & 0x80000000) { COPYBITS (bit_buf, bits, 1); return; } else if (bit_buf >= 0x0c000000) { tab = MV_4 + UBITS (bit_buf, 4); COPYBITS (bit_buf, bits, tab->len + 1); if (f_code) COPYBITS (bit_buf, bits, f_code); return; } else { tab = MV_10 + UBITS (bit_buf, 10); COPYBITS (bit_buf, bits, tab->len + 1); if (f_code) COPYBITS (bit_buf, bits, f_code); return; } } static MINLINE void get_dmv () { const DMVtab * tab; tab = DMV_2 + UBITS (bit_buf, 2); COPYBITS (bit_buf, bits, tab->len); return; } static MINLINE int get_coded_block_pattern () { #define bit_buf (inbitbuf) const CBPtab * tab; if (bit_buf >= 0x20000000) { tab = CBP_7 + (UBITS (bit_buf, 7) - 16); DUMPBITS (bit_buf, bits, tab->len); return tab->cbp; } else { tab = CBP_9 + UBITS (bit_buf, 9); DUMPBITS (bit_buf, bits, tab->len); return tab->cbp; } } static MINLINE int get_luma_dc_dct_diff () { #define bit_buf (inbitbuf) #ifdef CHANGE_BRIGHTNESS #define DOBITS(x, y, z) DUMPBITS(x, y, z) #else #define DOBITS(x, y, z) COPYBITS(x, y, z) #endif const DCtab * tab; int size; int dc_diff; if (bit_buf < 0xf8000000) { tab = DC_lum_5 + UBITS (bit_buf, 5); size = tab->size; if (size) { DOBITS (bit_buf, bits, tab->len); //dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size); dc_diff = UBITS (bit_buf, size); if (!(dc_diff >> (size - 1))) dc_diff = (dc_diff + 1) - (1 << size); DOBITS (bit_buf, bits, size); return dc_diff; } else { DOBITS (bit_buf, bits, 3); return 0; } } else { tab = DC_long + (UBITS (bit_buf, 9) - 0x1e0); size = tab->size; DOBITS (bit_buf, bits, tab->len); //dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size); dc_diff = UBITS (bit_buf, size); if (!(dc_diff >> (size - 1))) dc_diff = (dc_diff + 1) - (1 << size); DOBITS (bit_buf, bits, size); return dc_diff; } } static MINLINE int get_chroma_dc_dct_diff () { #define bit_buf (inbitbuf) const DCtab * tab; int size; int dc_diff; if (bit_buf < 0xf8000000) { tab = DC_chrom_5 + UBITS (bit_buf, 5); size = tab->size; if (size) { COPYBITS (bit_buf, bits, tab->len); //dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size); dc_diff = UBITS (bit_buf, size); if (!(dc_diff >> (size - 1))) dc_diff = (dc_diff + 1) - (1 << size); COPYBITS (bit_buf, bits, size); return dc_diff; } else { COPYBITS (bit_buf, bits, 2); return 0; } } else { tab = DC_long + (UBITS (bit_buf, 10) - 0x3e0); size = tab->size; COPYBITS (bit_buf, bits, tab->len + 1); //dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size); dc_diff = UBITS (bit_buf, size); if (!(dc_diff >> (size - 1))) dc_diff = (dc_diff + 1) - (1 << size); COPYBITS (bit_buf, bits, size); return dc_diff; } } #define UPDATE_VAL \ val = curTable[val]; static void get_intra_block_B14 () { #define bit_buf (inbitbuf) int i, li; int val; const DCTtab * tab; li = i = 0; while (1) { if (bit_buf >= 0x28000000) { tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); i += tab->run; if (i >= 64) break; /* end of block */ normal_code: DUMPBITS (bit_buf, bits, tab->len); val = tab->level; val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); UPDATE_VAL if (val) { if (putAC(i - li - 1, val, 0)) break; li = i; } DUMPBITS (bit_buf, bits, 1); continue; } else if (bit_buf >= 0x04000000) { tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); i += tab->run; if (i < 64) goto normal_code; /* escape code */ i += (UBITS (bit_buf, 12) & 0x3F) - 64; if (i >= 64) { sliceError++; break; /* illegal, check needed to avoid buffer overflow */ } DUMPBITS (bit_buf, bits, 12); val = SBITS (bit_buf, 12); UPDATE_VAL if (val) { if (putAC(i - li - 1, val, 0)) break; li = i; } DUMPBITS (bit_buf, bits, 12); continue; } else if (bit_buf >= 0x02000000) { tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); i += tab->run; if (i < 64) goto normal_code; } else if (bit_buf >= 0x00800000) { tab = DCT_13 + (UBITS (bit_buf, 13) - 16); i += tab->run; if (i < 64) goto normal_code; } else if (bit_buf >= 0x00200000) { tab = DCT_15 + (UBITS (bit_buf, 15) - 16); i += tab->run; if (i < 64) goto normal_code; } else { tab = DCT_16 + UBITS (bit_buf, 16); DUMPBITS (bit_buf, bits, 16); i += tab->run; if (i < 64) goto normal_code; } sliceError++; break; /* illegal, check needed to avoid buffer overflow */ } COPYBITS (bit_buf, bits, 2); /* end of block code */ } static void get_intra_block_B15 () { #define bit_buf (inbitbuf) int i, li; int val; const DCTtab * tab; li = i = 0; while (1) { if (bit_buf >= 0x04000000) { tab = DCT_B15_8 + (UBITS (bit_buf, 8) - 4); i += tab->run; if (i < 64) { normal_code: DUMPBITS (bit_buf, bits, tab->len); val = tab->level; val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); UPDATE_VAL if (val) { if (putAC(i - li - 1, val, 1)) break; li = i; } DUMPBITS (bit_buf, bits, 1); continue; } else { if (i >= 128) break; /* end of block */ i += (UBITS (bit_buf, 12) & 0x3F) - 64; if (i >= 64) { sliceError++; break; /* illegal, check against buffer overflow */ } DUMPBITS (bit_buf, bits, 12); val = SBITS (bit_buf, 12); UPDATE_VAL if (val) { if (putAC(i - li - 1, val, 1)) break; li = i; } DUMPBITS (bit_buf, bits, 12); continue; } } else if (bit_buf >= 0x02000000) { tab = DCT_B15_10 + (UBITS (bit_buf, 10) - 8); i += tab->run; if (i < 64) goto normal_code; } else if (bit_buf >= 0x00800000) { tab = DCT_13 + (UBITS (bit_buf, 13) - 16); i += tab->run; if (i < 64) goto normal_code; } else if (bit_buf >= 0x00200000) { tab = DCT_15 + (UBITS (bit_buf, 15) - 16); i += tab->run; if (i < 64) goto normal_code; } else { tab = DCT_16 + UBITS (bit_buf, 16); DUMPBITS (bit_buf, bits, 16); i += tab->run; if (i < 64) goto normal_code; } sliceError++; break; /* illegal, check needed to avoid buffer overflow */ } COPYBITS (bit_buf, bits, 4); /* end of block code */ } static int get_non_intra_block_rq (RunLevel *blk) { #define bit_buf (inbitbuf) //int q = quantizer_scale; //int nq = new_quantizer_scale, tst = (nq / q) + ((nq % q) ? 1 : 0); int i, li; int val; const DCTtab * tab; li = i = -1; if (bit_buf >= 0x28000000) { tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5); goto entry_1; } else goto entry_2; while (1) { if (bit_buf >= 0x28000000) { tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); entry_1: i += tab->run; if (i >= 64) break; /* end of block */ normal_code: DUMPBITS (bit_buf, bits, tab->len); val = tab->level; val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); UPDATE_VAL if (val) { blk->level = val; blk->run = i - li - 1; li = i; blk++; } DUMPBITS (bit_buf, bits, 1); continue; } entry_2: if (bit_buf >= 0x04000000) { tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); i += tab->run; if (i < 64) goto normal_code; /* escape code */ i += (UBITS (bit_buf, 12) & 0x3F) - 64; if (i >= 64) { sliceError++; break; /* illegal, check needed to avoid buffer overflow */ } DUMPBITS (bit_buf, bits, 12); val = SBITS (bit_buf, 12); UPDATE_VAL if (val) { blk->level = val; blk->run = i - li - 1; li = i; blk++; } DUMPBITS (bit_buf, bits, 12); continue; } else if (bit_buf >= 0x02000000) { tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); i += tab->run; if (i < 64) goto normal_code; } else if (bit_buf >= 0x00800000) { tab = DCT_13 + (UBITS (bit_buf, 13) - 16); i += tab->run; if (i < 64) goto normal_code; } else if (bit_buf >= 0x00200000) { tab = DCT_15 + (UBITS (bit_buf, 15) - 16); i += tab->run; if (i < 64) goto normal_code; } else { tab = DCT_16 + UBITS (bit_buf, 16); DUMPBITS (bit_buf, bits, 16); i += tab->run; if (i < 64) goto normal_code; } sliceError++; break; /* illegal, check needed to avoid buffer overflow */ } DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ blk->level = 0; return i; } #ifdef P_FRAME_NON_INTRA_DROP #if (P_FRAME_NON_INTRA_DROP < 0) #undef UPDATE_VAL #define UPDATE_VAL #define SAVE_VAL #define WRITE_VAL \ blk->level = val; \ blk->run = i - li - 1; \ li = i; \ blk++; #else #define SAVE_VAL oval = val; #define WRITE_VAL \ if ((val) || (i < P_FRAME_NON_INTRA_DROP)) \ { \ blk->level = oval; \ blk->run = i - li - 1; \ li = i; \ blk++; \ } #endif #else #define SAVE_VAL #define WRITE_VAL \ if (val) \ { \ blk->level = val; \ blk->run = i - li - 1; \ li = i; \ blk++; \ } #endif static int get_non_intra_block_sav (RunLevel *blk, int cc) { #define bit_buf (inbitbuf) int i, li; int val; const DCTtab * tab; #ifdef P_FRAME_NON_INTRA_DROP #if (P_FRAME_NON_INTRA_DROP < 0) RunLevel *oblk = blk; #else int oval; #endif #endif li = i = -1; if (bit_buf >= 0x28000000) { tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5); goto entry_1; } else goto entry_2; while (1) { if (bit_buf >= 0x28000000) { tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); entry_1: i += tab->run; if (i >= 64) break; /* end of block */ normal_code: DUMPBITS (bit_buf, bits, tab->len); val = tab->level; val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); SAVE_VAL if (li == -1) { if (abs(val) < abs(mb_sav_lev)) { mb_sav_c = cc; mb_sav_lev = val; mb_sav_run = i - li - 1; } } UPDATE_VAL WRITE_VAL DUMPBITS (bit_buf, bits, 1); continue; } entry_2: if (bit_buf >= 0x04000000) { tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); i += tab->run; if (i < 64) goto normal_code; /* escape code */ i += (UBITS (bit_buf, 12) & 0x3F) - 64; if (i >= 64) { sliceError++; break; /* illegal, check needed to avoid buffer overflow */ } DUMPBITS (bit_buf, bits, 12); val = SBITS (bit_buf, 12); SAVE_VAL if (li == -1) { if (abs(val) < abs(mb_sav_lev)) { mb_sav_c = cc; mb_sav_lev = val; mb_sav_run = i - li - 1; } } UPDATE_VAL WRITE_VAL DUMPBITS (bit_buf, bits, 12); continue; } else if (bit_buf >= 0x02000000) { tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); i += tab->run; if (i < 64) goto normal_code; } else if (bit_buf >= 0x00800000) { tab = DCT_13 + (UBITS (bit_buf, 13) - 16); i += tab->run; if (i < 64) goto normal_code; } else if (bit_buf >= 0x00200000) { tab = DCT_15 + (UBITS (bit_buf, 15) - 16); i += tab->run; if (i < 64) goto normal_code; } else { tab = DCT_16 + UBITS (bit_buf, 16); DUMPBITS (bit_buf, bits, 16); i += tab->run; if (i < 64) goto normal_code; } sliceError++; break; /* illegal, check needed to avoid buffer overflow */ } DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ #ifdef P_FRAME_NON_INTRA_DROP #if (P_FRAME_NON_INTRA_DROP < 0) blk -= (int)((blk - oblk) * (stress_factor / P_FRAME_NON_INTRA_DROP)); #ifdef DEMO // P_FRAME_NON_INTRA_DROP if ((gopCount & 0x7F) < 10) blk = oblk; #endif #endif #endif blk->level = 0; return i; } #ifdef P_FRAME_NON_INTRA_DROP static int get_non_intra_block_drop (RunLevel *blk, int cc) { #define bit_buf (inbitbuf) int i, li; int val; const DCTtab * tab; #if (P_FRAME_NON_INTRA_DROP < 0) RunLevel *oblk = blk; #else int oval; #endif li = i = -1; if (bit_buf >= 0x28000000) { tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5); goto entry_1; } else goto entry_2; while (1) { if (bit_buf >= 0x28000000) { tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); entry_1: i += tab->run; if (i >= 64) break; /* end of block */ normal_code: DUMPBITS (bit_buf, bits, tab->len); val = tab->level; val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); SAVE_VAL UPDATE_VAL WRITE_VAL DUMPBITS (bit_buf, bits, 1); continue; } entry_2: if (bit_buf >= 0x04000000) { tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); i += tab->run; if (i < 64) goto normal_code; /* escape code */ i += (UBITS (bit_buf, 12) & 0x3F) - 64; if (i >= 64) { sliceError++; break; /* illegal, check needed to avoid buffer overflow */ } DUMPBITS (bit_buf, bits, 12); val = SBITS (bit_buf, 12); SAVE_VAL UPDATE_VAL WRITE_VAL DUMPBITS (bit_buf, bits, 12); continue; } else if (bit_buf >= 0x02000000) { tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); i += tab->run; if (i < 64) goto normal_code; } else if (bit_buf >= 0x00800000) { tab = DCT_13 + (UBITS (bit_buf, 13) - 16); i += tab->run; if (i < 64) goto normal_code; } else if (bit_buf >= 0x00200000) { tab = DCT_15 + (UBITS (bit_buf, 15) - 16); i += tab->run; if (i < 64) goto normal_code; } else { tab = DCT_16 + UBITS (bit_buf, 16); DUMPBITS (bit_buf, bits, 16); i += tab->run; if (i < 64) goto normal_code; } sliceError++; break; /* illegal, check needed to avoid buffer overflow */ } DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ #if (P_FRAME_NON_INTRA_DROP < 0) blk -= (int)((blk - oblk) * (stress_factor / P_FRAME_NON_INTRA_DROP)); #ifdef DEMO // P_FRAME_NON_INTRA_DROP if ((gopCount & 0x7F) < 10) blk = oblk; #endif #endif blk->level = 0; return i; } #endif #ifdef CHANGE_BRIGHTNESS static void putDC(const sVLCtable *tab, int val) { int absval, size; absval = abs(val); size = 0; while (absval) { absval >>= 1; size++; } putbits(tab[size].code,tab[size].len); if (size!=0) { if (val>=0) absval = val; else absval = val + (1< (255 << intra_dc_precision)) val = 255 << intra_dc_precision; else if (val < 0) val = 0; bri = val - (128 << intra_dc_precision); new_dc_pred = val; dc_reset = 0; } else { val = bri + old_dc_pred; old_dc_pred = val; val += delta_bright << intra_dc_precision; if (val > (255 << intra_dc_precision)) val = 255 << intra_dc_precision; else if (val < 0) val = 0; bri = val - new_dc_pred; new_dc_pred = val; } putDC(DClumtab, bri); } #else if (cc == 0) get_luma_dc_dct_diff (); #endif else get_chroma_dc_dct_diff (); if (intra_vlc_format) get_intra_block_B15 (); else get_intra_block_B14 (); } static MINLINE void slice_non_intra_DCT (int cur_block) { #ifdef P_FRAME_NON_INTRA_DROP if (picture_coding_type == P_TYPE) { if ((h_offset == 0) || (h_offset == horizontal_size_value - 16)) get_non_intra_block_sav(block[cur_block], cur_block); else get_non_intra_block_drop(block[cur_block], cur_block); } else get_non_intra_block_rq(block[cur_block]); #else if ((picture_coding_type == P_TYPE) && ((h_offset == 0) || (h_offset == horizontal_size_value - 16))) get_non_intra_block_sav(block[cur_block], cur_block); else get_non_intra_block_rq(block[cur_block]); #endif } static void motion_fr_frame ( uint f_code[2] ) { get_motion_delta (f_code[0]); get_motion_delta (f_code[1]); } static void motion_fr_field ( uint f_code[2] ) { COPYBITS (bit_buf, bits, 1); get_motion_delta (f_code[0]); get_motion_delta (f_code[1]); COPYBITS (bit_buf, bits, 1); get_motion_delta (f_code[0]); get_motion_delta (f_code[1]); } static void motion_fr_dmv ( uint f_code[2] ) { get_motion_delta (f_code[0]); get_dmv (); get_motion_delta (f_code[1]); get_dmv (); } static void motion_fr_conceal ( ) { get_motion_delta (f_code[0][0]); get_motion_delta (f_code[0][1]); COPYBITS (bit_buf, bits, 1); } static void motion_fi_field ( uint f_code[2] ) { COPYBITS (bit_buf, bits, 1); get_motion_delta (f_code[0]); get_motion_delta (f_code[1]); } static void motion_fi_16x8 ( uint f_code[2] ) { COPYBITS (bit_buf, bits, 1); get_motion_delta (f_code[0]); get_motion_delta (f_code[1]); COPYBITS (bit_buf, bits, 1); get_motion_delta (f_code[0]); get_motion_delta (f_code[1]); } static void motion_fi_dmv ( uint f_code[2] ) { get_motion_delta (f_code[0]); get_dmv (); get_motion_delta (f_code[1]); get_dmv (); } static void motion_fi_conceal () { COPYBITS (bit_buf, bits, 1); get_motion_delta (f_code[0][0]); get_motion_delta (f_code[0][1]); COPYBITS (bit_buf, bits, 1); } #define MOTION_CALL(routine,direction) \ do { \ if ((direction) & MACROBLOCK_MOTION_FORWARD) \ routine (f_code[0]); \ if ((direction) & MACROBLOCK_MOTION_BACKWARD) \ routine (f_code[1]); \ } while (0) #define NEXT_MACROBLOCK \ do { \ h_offset += 16; \ if (h_offset == horizontal_size_value) \ { \ v_offset += 16; \ if (v_offset > (vertical_size_value - 16)) return; \ h_offset = 0; \ } \ } while (0) void putmbdata(int macroblock_modes) { putmbtype(macroblock_modes & 0x1F); /*switch (picture_coding_type) { case I_TYPE: if ((! (frame_pred_frame_dct)) && (picture_structure == FRAME_PICTURE)) putbits(macroblock_modes & DCT_TYPE_INTERLACED ? 1 : 0, 1); break; case P_TYPE: if (picture_structure != FRAME_PICTURE) { if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) putbits((macroblock_modes & MOTION_TYPE_MASK) / MOTION_TYPE_BASE, 2); break; } else if (frame_pred_frame_dct) break; else { if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) putbits((macroblock_modes & MOTION_TYPE_MASK) / MOTION_TYPE_BASE, 2); if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) putbits(macroblock_modes & DCT_TYPE_INTERLACED ? 1 : 0, 1); break; } case B_TYPE: if (picture_structure != FRAME_PICTURE) { if (! (macroblock_modes & MACROBLOCK_INTRA)) putbits((macroblock_modes & MOTION_TYPE_MASK) / MOTION_TYPE_BASE, 2); break; } else if (frame_pred_frame_dct) break; else { if (macroblock_modes & MACROBLOCK_INTRA) goto intra; putbits((macroblock_modes & MOTION_TYPE_MASK) / MOTION_TYPE_BASE, 2); if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) { intra: putbits(macroblock_modes & DCT_TYPE_INTERLACED ? 1 : 0, 1); } break; } }*/ if (macroblock_modes & (MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD)) { if (picture_structure == FRAME_PICTURE) { if (frame_pred_frame_dct == 0) { putbits((macroblock_modes & MOTION_TYPE_MASK) / MOTION_TYPE_BASE, 2); } } else { putbits((macroblock_modes & MOTION_TYPE_MASK) / MOTION_TYPE_BASE, 2); } } if ((picture_structure == FRAME_PICTURE) && (frame_pred_frame_dct == 0) && (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN))) { putbits(macroblock_modes & DCT_TYPE_INTERLACED ? 1 : 0, 1); } } static MINLINE void put_quantiser(int quantiser) { putbits(q_scale_type ? map_non_linear_mquant[quantiser] : quantiser >> 1, 5); last_coded_scale = quantiser; } static void putaddrinc(int addrinc) { mb_out += addrinc; //LOGF("mb_out: %i\n", mb_out); if (mb_out > (horizontal_size_value >> 4)) { sliceError++; //LOGF("mb_out: %i, hsv: %i, curo: %i\n", mb_out, horizontal_size_value, (int)outbytecnt + (wbuf - owbuf)); } while (addrinc>33) { putbits(0x08,11); /* macroblock_escape */ addrinc-= 33; } assert( addrinc >= 1 && addrinc <= 33 ); putbits(addrinctab[addrinc-1].code,addrinctab[addrinc-1].len); } static MINLINE int slice_init (int code) { #define bit_buf (inbitbuf) int offset; const MBAtab * mba; mb_out = 0; v_offset = (code - 1) * 16; quantizer_scale = get_quantizer_scale (); new_quantizer_scale = getNewQuant(quantizer_scale, 0); put_quantiser(new_quantizer_scale); /* ignore intra_slice and all the extra data */ while (bit_buf & 0x80000000) { DUMPBITS (bit_buf, bits, 9); } /* decode initial macroblock address increment */ offset = 0; while (1) { if (bit_buf >= 0x08000000) { mba = MBA_5 + (UBITS (bit_buf, 6) - 2); break; } else if (bit_buf >= 0x01800000) { mba = MBA_11 + (UBITS (bit_buf, 12) - 24); break; } else switch (UBITS (bit_buf, 12)) { case 8: /* macroblock_escape */ offset += 33; DUMPBITS (bit_buf, bits, 11); continue; default: /* error */ sliceError++; return 1; } } mb_add = offset + mba->mba + 1; mb_skip = 0; COPYBITS (bit_buf, bits, 1); DUMPBITS(bit_buf, bits, mba->len); h_offset = (offset + mba->mba) << 4; while (h_offset - (int)horizontal_size_value >= 0) { h_offset -= horizontal_size_value; v_offset += 16; } if (v_offset > (vertical_size_value - 16)) return 1; return 0; } void mpeg2_slice ( const int code ) { #define bit_buf (inbitbuf) #ifdef CHANGE_BRIGHTNESS dc_reset = 1; #endif if (slice_init (code)) return; while (1) { int macroblock_modes; int mba_inc; const MBAtab * mba; macroblock_modes = get_macroblock_modes (); if (macroblock_modes & MACROBLOCK_QUANT) quantizer_scale = get_quantizer_scale (); if (macroblock_modes & MACROBLOCK_INTRA) { #ifdef STAT if (picture_coding_type == P_TYPE) cnt_p_i++; else if (picture_coding_type == B_TYPE) cnt_b_i++; #endif new_quantizer_scale = getNewQuant(quantizer_scale, 1); if (last_coded_scale == new_quantizer_scale) macroblock_modes &= 0xFFFFFFEF; // remove MACROBLOCK_QUANT else macroblock_modes |= MACROBLOCK_QUANT; //add MACROBLOCK_QUANT putaddrinc(mb_add + mb_skip); mb_skip = 0; putmbdata(macroblock_modes); if (macroblock_modes & MACROBLOCK_QUANT) put_quantiser(new_quantizer_scale); if (concealment_motion_vectors) { if (picture_structure == FRAME_PICTURE) motion_fr_conceal (); else motion_fi_conceal (); } curTable = quant_tables[quant_equ[quantizer_scale]][quant_equ[new_quantizer_scale]]; if (!curTable) { /*DEBF("Inv. curTable: qs: %i nqs: %i qe_qs: %i qe_nqs: %i\n", quantizer_scale, new_quantizer_scale, quant_equ[quantizer_scale], quant_equ[new_quantizer_scale]);*/ curTable = quant_table_id; } slice_intra_DCT ( 0); slice_intra_DCT ( 0); slice_intra_DCT ( 0); slice_intra_DCT ( 0); #ifdef DEMO if ((gopCount & 0x7F) < 10) { // save write state uint8 *savedWbuf = wbuf; int savedOutbitcnt = outbitcnt; uint32 savedOutbitbuf = outbitbuf; // process u block slice_intra_DCT ( 1); //int dump = (wbuf - owbuf == 201); //if (dump) fprintf(stderr, "=====\nbyte 0x%02X, cnt %i, outbitbuf 0x%02X, outbitcnt %i\n", // wbuf[-1], wbuf - savedWbuf, outbitbuf, outbitcnt); // remember how much data was converted int bitsToSkip = BITS_IN_BUF - savedOutbitcnt; int postBitsWritten = BITS_IN_BUF - outbitcnt; int bitsWritten = (wbuf - savedWbuf) * 8 + postBitsWritten - bitsToSkip; if (postBitsWritten) putbits(0, outbitcnt); int bytesToCopy = wbuf - savedWbuf; // copy the bytes into temp buffer uint8 tempBuf[1024]; memcpy(tempBuf, savedWbuf, bytesToCopy); //if (dump) fprintf(stderr, "pos %i, byte 0x%02X, bitsToSkip %i, postBitsWritten %i, bitsWritten %i, bytesToCopy %i\n", // wbuf - owbuf, savedWbuf[0], bitsToSkip, postBitsWritten, bitsWritten, bytesToCopy); // reset write buffer { wbuf = savedWbuf; outbitcnt = savedOutbitcnt; outbitbuf = savedOutbitbuf; } // process v block slice_intra_DCT ( 2); // copy bits back from temp buffer { int bi = bitsToSkip, bm = bi + bitsWritten, p = 0; while(bi < bm) { int to = bm - bi; int bmod = bi % 8; if (bmod) { if (to > 8 - bmod) to = 8 - bmod; putbits((tempBuf[p] & ((1 << to) - 1)) >> (8 - bmod - to), to); bi += to; p++; continue; } if (to >= 8) { putbits(tempBuf[p], 8); bi += 8; p++; continue; } putbits(tempBuf[p] >> (8 - to), to); bi += to; p++; continue; } } //if (dump) fprintf(stderr, "byte 0x%02X, cnt %i, outbitbuf 0x%02X, outbitcnt %i\n", // wbuf[-1], wbuf - savedWbuf, outbitbuf, outbitcnt); } else #endif { slice_intra_DCT ( 1); slice_intra_DCT ( 2); } } else { int new_coded_block_pattern = 0; // begin saving data int batb; uint8 n_owbuf[32], *n_wbuf, *o_owbuf, *o_wbuf; uint32 n_outbitcnt, n_outbitbuf, o_outbitcnt, o_outbitbuf; #ifdef CHANGE_BRIGHTNESS dc_reset = 1; #endif #define PUSH_BIT_IO \ o_owbuf = owbuf; o_wbuf = wbuf; \ o_outbitcnt = outbitcnt; o_outbitbuf = outbitbuf; \ owbuf = wbuf = n_owbuf; \ outbitcnt = BITS_IN_BUF; outbitbuf = 0; #define POP_BIT_IO \ n_wbuf = wbuf; \ n_outbitcnt = outbitcnt; n_outbitbuf = outbitbuf; \ owbuf = o_owbuf; wbuf = o_wbuf; \ outbitcnt = o_outbitcnt; outbitbuf = o_outbitbuf; PUSH_BIT_IO if (picture_structure == FRAME_PICTURE) switch (macroblock_modes & MOTION_TYPE_MASK) { case MC_FRAME: MOTION_CALL (motion_fr_frame, macroblock_modes); break; case MC_FIELD: MOTION_CALL (motion_fr_field, macroblock_modes); break; case MC_DMV: MOTION_CALL (motion_fr_dmv, MACROBLOCK_MOTION_FORWARD); break; } else switch (macroblock_modes & MOTION_TYPE_MASK) { case MC_FIELD: MOTION_CALL (motion_fi_field, macroblock_modes); break; case MC_16X8: MOTION_CALL (motion_fi_16x8, macroblock_modes); break; case MC_DMV: MOTION_CALL (motion_fi_dmv, MACROBLOCK_MOTION_FORWARD); break; } POP_BIT_IO // end saving data #ifdef STAT if (picture_coding_type == P_TYPE) cnt_p_ni++; else if (picture_coding_type == B_TYPE) cnt_b_ni++; #endif new_quantizer_scale = getNewQuant(quantizer_scale, 0); if (macroblock_modes & MACROBLOCK_PATTERN) { int coded_block_pattern = get_coded_block_pattern (); mb_sav_lev = 0xFFFF; curTable = quant_tables[quant_equ[quantizer_scale]][quant_equ[new_quantizer_scale]]; if (!curTable) { /*DEBF("Inv. curTable: qs: %i nqs: %i qe_qs: %i qe_nqs: %i\n", quantizer_scale, new_quantizer_scale, quant_equ[quantizer_scale], quant_equ[new_quantizer_scale]);*/ curTable = quant_table_id; } if (coded_block_pattern & 0x20) { slice_non_intra_DCT(0); if (isNotEmpty(block[0])) new_coded_block_pattern |= 0x20; } if (coded_block_pattern & 0x10) { slice_non_intra_DCT(1); if (isNotEmpty(block[1])) new_coded_block_pattern |= 0x10; } if (coded_block_pattern & 0x08) { slice_non_intra_DCT(2); if (isNotEmpty(block[2])) new_coded_block_pattern |= 0x08; } if (coded_block_pattern & 0x04) { slice_non_intra_DCT(3); if (isNotEmpty(block[3])) new_coded_block_pattern |= 0x04; } if (coded_block_pattern & 0x02) { slice_non_intra_DCT(4); if (isNotEmpty(block[4])) new_coded_block_pattern |= 0x02; } if (coded_block_pattern & 0x01) { slice_non_intra_DCT(5); if (isNotEmpty(block[5])) new_coded_block_pattern |= 0x01; } #ifdef P_FRAME_NON_INTRA_DROP if (picture_coding_type == P_TYPE) new_quantizer_scale = quantizer_scale; #endif if (!new_coded_block_pattern) { macroblock_modes &= 0xFFFFFFED; // remove MACROBLOCK_PATTERN and MACROBLOCK_QUANT flag if ( (picture_coding_type == P_TYPE) && !(macroblock_modes & MACROBLOCK_MOTION_FORWARD)) { assert(n_wbuf == n_owbuf); assert(n_outbitcnt == BITS_IN_BUF); if ((h_offset == 0) || (h_offset == horizontal_size_value - 16)) // can't skip last mb { // we can't transmit mv (0,0) since PMV could be different than 0 for last block // so we transmit the single smallest coeff. instead unrequantised // anyway this is likely to take no more bit than transmiting a null mv.... assert((mb_sav_lev) && (mb_sav_lev != 0xFFFF)); new_coded_block_pattern = 1 << (5 - mb_sav_c); macroblock_modes |= MACROBLOCK_PATTERN; new_quantizer_scale = quantizer_scale; block[mb_sav_c][0].run = mb_sav_run; block[mb_sav_c][0].level = mb_sav_lev; block[mb_sav_c][1].run = 0; block[mb_sav_c][1].level = 0; } else { mb_skip += mb_add; goto skip_mb; } } } } if (last_coded_scale == new_quantizer_scale) macroblock_modes &= 0xFFFFFFEF; // remove MACROBLOCK_QUANT else if (macroblock_modes & MACROBLOCK_PATTERN) macroblock_modes |= MACROBLOCK_QUANT; //add MACROBLOCK_QUANT assert( (macroblock_modes & MACROBLOCK_PATTERN) || !(macroblock_modes & MACROBLOCK_QUANT) ); putaddrinc(mb_add + mb_skip); mb_skip = 0; putmbdata(macroblock_modes); if (macroblock_modes & MACROBLOCK_QUANT) put_quantiser(new_quantizer_scale); // put saved motion data... for (batb = 0; batb < (n_wbuf - n_owbuf); batb++) putbits(n_owbuf[batb], 8); putbits(n_outbitbuf, BITS_IN_BUF - n_outbitcnt); // end saved motion data... if (macroblock_modes & MACROBLOCK_PATTERN) { putcbp(new_coded_block_pattern); if (new_coded_block_pattern & 0x20) putnonintrablk(block[0]); if (new_coded_block_pattern & 0x10) putnonintrablk(block[1]); if (new_coded_block_pattern & 0x08) putnonintrablk(block[2]); if (new_coded_block_pattern & 0x04) putnonintrablk(block[3]); if (new_coded_block_pattern & 0x02) putnonintrablk(block[4]); if (new_coded_block_pattern & 0x01) putnonintrablk(block[5]); } } skip_mb: NEXT_MACROBLOCK; mba_inc = 0; while (1) { if (bit_buf >= 0x10000000) { mba = MBA_5 + (UBITS (bit_buf, 5) - 2); break; } else if (bit_buf >= 0x03000000) { mba = MBA_11 + (UBITS (bit_buf, 11) - 24); break; } else switch (UBITS (bit_buf, 11)) { case 8: /* macroblock_escape */ mba_inc += 33; DUMPBITS (bit_buf, bits, 11); continue; default: /* end of slice, or error */ //LOGF("hoffset: %i, hsv: %i, curo: %i\n", h_offset, horizontal_size_value, (int)outbytecnt + (wbuf - owbuf)); if (h_offset != 0) sliceError++; return; } } DUMPBITS (bit_buf, bits, mba->len); //PPP mba_inc += mba->mba; mb_add = mba_inc + 1; #ifdef CHANGE_BRIGHTNESS if (mba_inc) dc_reset = 1; #endif if (mba_inc) do { NEXT_MACROBLOCK; } while (--mba_inc); } } /////---- end ext mpeg code #ifdef CHANGE_BRIGHTNESS #ifdef USE_FD #define USAGE \ fprintf(stderr,\ "\nUsage is :\n"\ "\t%s [ignored_recompression_factor] inputM2Vsize brightness_delta input.m2v output.m2v\n\n", argv[0]);\ return -1; #else #define USAGE \ fprintf(stderr,\ "\nUsage is :\n"\ "\t%s [ignored_recompression_factor] inputM2Vsize brightness_delta\n\n", argv[0]);\ return -1; #endif #else #ifdef USE_FD #define USAGE \ fprintf(stderr,\ "\nUsage is :\n"\ "\t%s recompression_factor inputM2Vsize input.m2v output.m2v\n\n", argv[0]);\ return -1; #else #define USAGE \ fprintf(stderr,\ "\nUsage is :\n"\ "\t%s recompression_factor inputM2Vsize\n\n", argv[0]);\ return -1; #endif #endif int quantisers[42] = { 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 72, 80, 88, 96, 104, 112 }; int main (int argc, const char * argv[]) { uint8 ID, found; int64 greedyFactor, greedyFactor2; int i; #ifdef DEMO // gopCount set to 0 gopCount = 0; #endif #ifdef LOG_RATE_CONTROL { int suffix = 0; char logFileName[256]; do { sprintf(logFileName, "Logfile_%03i.txt", suffix); LOG_FILE = fopen(logFileName, "r"); if (LOG_FILE) { fclose(LOG_FILE); suffix++; } } while(LOG_FILE != 0); LOG_FILE = fopen(logFileName, "w"); } #endif #ifdef STAT ori_i = ori_p = ori_b = 0; new_i = new_p = new_b = 0; cnt_i = cnt_p = cnt_b = 0; cnt_p_i = cnt_p_ni = 0; cnt_b_i = cnt_b_ni = 0; #endif #ifdef USE_FD if (argc < 3) { USAGE } ifd = fopen(argv[argc - 2], "rb"); ofd = fopen(argv[argc - 1], "wb"); if (!ifd) { LOGF("Bad input path! (%s)\n", argv[argc - 2]); return 2; } if (!ofd) { LOGF("Bad output path! (%s)\n", argv[argc - 1]); return 2; } argc -= 2; #endif rbuf = cbuf = orbuf = malloc(BUF_SIZE); wbuf = owbuf = malloc(BUF_SIZE); inbytecnt = outbytecnt = 0; // Progress hack int last_percent; int curr_percent; last_percent = curr_percent = 0; eof = 0; validPicHeader = 0; validSeqHeader = 0; validExtHeader = 0; // argument parsing #ifdef CHANGE_BRIGHTNESS if (argc < 5) { USAGE } delta_bright = atoi(argv[4]); #else if (argc < 2) { USAGE } #endif fact_x = atof(argv[1]); sscanf(argv[2], "%lld", &orim2vsize); greedyFactor = orim2vsize / 100; greedyFactor2 = orim2vsize / 50; if (fact_x <= 1.0) { unsigned char buf[4096]; while(1) { int i = read(0, buf, 4096); if (i > 0) write(1, buf, i); else return 0; } } else if (fact_x > 900.0) fact_x = 900.0; // factor and stresses setting if (fact_x <= 1.0) { i_factor = i_factors[0]; p_factor = p_factors[0]; b_factor = b_factors[0]; i_min_stress = i_min_stresses[0]; p_min_stress = p_min_stresses[0]; b_min_stress = b_min_stresses[0]; } else if (fact_x >= 10.0) { i_factor = i_factors[2]; p_factor = p_factors[2]; b_factor = b_factors[2]; i_min_stress = i_min_stresses[2]; p_min_stress = p_min_stresses[2]; b_min_stress = b_min_stresses[2]; } else if (fact_x <= 3.0) // 1.0 .. 3.0 { double inter = (fact_x - 1.0)/(3.0 - 1.0); i_factor = i_factors[0] + inter * (i_factors[1] - i_factors[0]); p_factor = p_factors[0] + inter * (p_factors[1] - p_factors[0]); b_factor = b_factors[0] + inter * (b_factors[1] - b_factors[0]); i_min_stress = i_min_stresses[0] + inter * (i_min_stresses[1] - i_min_stresses[0]); p_min_stress = p_min_stresses[0] + inter * (p_min_stresses[1] - p_min_stresses[0]); b_min_stress = b_min_stresses[0] + inter * (b_min_stresses[1] - b_min_stresses[0]); } else // 3.0 .. 10.0 { double inter = (fact_x - 3.0)/(10.0 - 3.0); i_factor = i_factors[1] + inter * (i_factors[2] - i_factors[1]); p_factor = p_factors[1] + inter * (p_factors[2] - p_factors[1]); b_factor = b_factors[1] + inter * (b_factors[2] - b_factors[1]); i_min_stress = i_min_stresses[1] + inter * (i_min_stresses[2] - i_min_stresses[1]); p_min_stress = p_min_stresses[1] + inter * (p_min_stresses[2] - p_min_stresses[1]); b_min_stress = b_min_stresses[1] + inter * (b_min_stresses[2] - b_min_stresses[1]); } /*LOGF( "i_factor: %i p_factor: %i b_factor: %i\n" "i_min_stress: %.02f p_min_stress: %.02f b_min_stress: %.02f\n", i_factor, p_factor, b_factor, i_min_stress, p_min_stress, b_min_stress);*/ // fill quant table // id table for (i = -2048; i <= 2047; i++) quant_table_id[i] = i; // other tables for (i = 0; i < 42; i++) { int q = quantisers[i]; int j; for (j = i + 1; j < 42; j++) { int nq = quantisers[j]; int k; short *cTab = quant_tables[quant_equ[q]][quant_equ[nq]]; for (k = -2048; k <= 2047; k++) { int ov = k*q; int t = ov / nq; if (fact_x <= max_alt_table) { int t2, t3; int d, d2, d3; int nv, nv2, nv3; t2 = t + 1; t3 = t - 1; nv = t * nq; nv2 = t2 * nq; nv3 = t3 * nq; d = abs(nv - ov); d2 = abs(nv2 - ov); d3 = abs(nv3 - ov); if (d2 < d) { d = d2; t = t2; } if (d3 < d) t = t3; } if (t > 2047) t = 2047; else if (t < -2048) t = -2048; cTab[k] = t; } } } LOG("M2VRequantiser v1.1. GPLv2 License.\n"); #ifdef WIN fprintf(stderr, "Using %f as factor, %lld as m2v size.\n", fact_x, orim2vsize); #else LOGF("Using %f as factor, %lld as m2v size.\n", fact_x, orim2vsize); #endif // recoding while(1) { // get next start code prefix found = 0; while (!found) { #ifndef REMOVE_BYTE_STUFFING LOCK(3) #else LOCK(8) if ((cbuf[7] == 0) && (cbuf[6] == 0) && (cbuf[5] == 0) && (cbuf[4] == 0) && (cbuf[3] == 0) && (cbuf[2] == 0) && (cbuf[1] == 0) && (cbuf[0] == 0) ) { SEEKR(1) } else #endif if ( (cbuf[0] == 0) && (cbuf[1] == 0) && (cbuf[2] == 1) ) found = 1; // start code ! else { COPY(1) } // continue search } COPY(3) // get start code LOCK(1) ID = cbuf[0]; COPY(1) if (ID == 0x00) // pic header { LOCK(4) picture_coding_type = (cbuf[1] >> 3) & 0x7; if (picture_coding_type < 1 || picture_coding_type > 3) { DEBF("illegal picture_coding_type: %i\n", picture_coding_type); validPicHeader = 0; } else { validPicHeader = 1; cbuf[1] |= 0x7; cbuf[2] = 0xFF; cbuf[3] |= 0xF8; // vbv_delay is now 0xFFFF } validExtHeader = 0; COPY(4) } else if (ID == 0xB3) // seq header { LOCK(8) horizontal_size_value = (cbuf[0] << 4) | (cbuf[1] >> 4); vertical_size_value = ((cbuf[1] & 0xF) << 8) | cbuf[2]; if ( horizontal_size_value > 720 || horizontal_size_value < 352 || vertical_size_value > 576 || vertical_size_value < 480 || (horizontal_size_value & 0xF) || (vertical_size_value & 0xF)) { DEBF("illegal size, hori: %i verti: %i\n", horizontal_size_value, vertical_size_value); validSeqHeader = 0; } else validSeqHeader = 1; validPicHeader = 0; validExtHeader = 0; COPY(8) } else if (ID == 0xB5) // extension { LOCK(1) if ((cbuf[0] >> 4) == 0x8) // pic coding ext { LOCK(5) f_code[0][0] = (cbuf[0] & 0xF) - 1; f_code[0][1] = (cbuf[1] >> 4) - 1; f_code[1][0] = (cbuf[1] & 0xF) - 1; f_code[1][1] = (cbuf[2] >> 4) - 1; intra_dc_precision = (cbuf[2] >> 2) & 0x3; picture_structure = cbuf[2] & 0x3; frame_pred_frame_dct = (cbuf[3] >> 6) & 0x1; concealment_motion_vectors = (cbuf[3] >> 5) & 0x1; q_scale_type = (cbuf[3] >> 4) & 0x1; intra_vlc_format = (cbuf[3] >> 3) & 0x1; alternate_scan = (cbuf[3] >> 2) & 0x1; if ( (f_code[0][0] > 8 && f_code[0][0] < 14) || (f_code[0][1] > 8 && f_code[0][1] < 14) || (f_code[1][0] > 8 && f_code[1][0] < 14) || (f_code[1][1] > 8 && f_code[1][1] < 14) || picture_structure == 0) { DEBF("illegal ext, f_code[0][0]: %i f_code[0][1]: %i f_code[1][0]: %i f_code[1][1]: %i picture_structure:%i\n", f_code[0][0], f_code[0][1], f_code[1][0], f_code[1][1], picture_structure); validExtHeader = 0; } else validExtHeader = 1; COPY(5) } else { COPY(1) } } else if (ID == 0xB8) // gop header { LOCK(4) COPY(4) #ifdef DEMO // gopCount increment gopCount++; #endif } else if ((ID >= 0x01) && (ID <= 0xAF) && validPicHeader && validSeqHeader && validExtHeader) // slice { uint8 *outTemp = wbuf, *inTemp = cbuf; int64 threshold; bytediff = (outbytecnt + (wbuf - owbuf)) - ((inbytecnt - (rbuf - cbuf)) / fact_x); if (inbytecnt < greedyFactor2) threshold = inbytecnt >> 1; else if (orim2vsize - inbytecnt < greedyFactor2) threshold = (orim2vsize - inbytecnt) >> 1; else threshold = greedyFactor; if (threshold < 1024) threshold = 1024; stress_factor = (float)(bytediff + threshold) / (float)(threshold << 1); if (stress_factor > 1.0f) stress_factor = 1.0f; else if (stress_factor < 0.0f) stress_factor = 0.0f; #ifdef LOG_RATE_CONTROL /*fprintf(LOG_FILE, "%f%%: Requested: %f Current: %f Delta: %lld Threshold: %f Stress: %f\n", (float)(100.0f*inbytecnt)/orim2vsize, // percent (float)fact_x, // requested (float)(inbytecnt - (rbuf - cbuf))/(float)(outbytecnt + (wbuf - owbuf)), // current (long long)bytediff, // delta (float)threshold, // threshold stress_factor // Stress );*/ fprintf(LOG_FILE, "inb: %.0f inb_c: %.0f oub: %.0f oub_c: %.0f cur: %.3f dif: %.0f thr: %.0f str: %.03f\n", (float)inbytecnt, (float)(inbytecnt - (rbuf - cbuf)), (float)outbytecnt, (float)(outbytecnt + (wbuf - owbuf)), (float)(inbytecnt - (rbuf - cbuf))/(float)(outbytecnt + (wbuf - owbuf)), (float)bytediff, (float)threshold, (float)stress_factor ); #endif #ifndef CHANGE_BRIGHTNESS if ( ((picture_coding_type == I_TYPE) && ( stress_factor > i_min_stress)) || ((picture_coding_type == P_TYPE) && ( stress_factor > p_min_stress)) || ((picture_coding_type == B_TYPE) && ( stress_factor > b_min_stress)) #ifdef DEMO // force processing || ((gopCount & 0x7F) < 10) #endif ) #endif { // lock all the slice if less than 1 meg in buffer if (rbuf - cbuf < 1*1024*1024) { // try to read more data if (!eof) { mloka2 = MIN_READ; while (mloka2) { assert(rbuf + mloka2 < orbuf + BUF_SIZE); #ifdef USE_FD mloka1 = fread(rbuf, 1, mloka2, ifd); #else mloka1 = read(0, rbuf, mloka2); #endif if (mloka1 <= 0) { eof = 1; break; } inbytecnt += mloka1; rbuf += mloka1; mloka2 -= mloka1; // Progress hack curr_percent = ((float)inbytecnt / (float)orim2vsize) * 100; if (curr_percent != last_percent) { #ifdef WIN fprintf(stderr, "Progress: %d%%\n", curr_percent); #else LOGF("Progress: %d%%\n", curr_percent); #endif } last_percent = curr_percent; } } // lock slice manually if (rbuf - cbuf < 1*1024*1024) { uint8 *nsc = cbuf; int fsc = 0, toLock; while (!fsc) { toLock = nsc - cbuf + 3; LOCK(toLock) if ( (nsc[0] == 0) && (nsc[1] == 0) && (nsc[2] == 1) ) fsc = 1; // start code ! else nsc++; // continue search } } } // init error sliceError = 0; // init bit buffer inbitbuf = 0; inbitcnt = 0; outbitbuf = 0; outbitcnt = BITS_IN_BUF; // get 32 bits Refill_bits(); Refill_bits(); Refill_bits(); Refill_bits(); // begin bit level recoding mpeg2_slice(ID); flush_read_buffer(); flush_write_buffer(); // end bit level recoding #ifndef CHANGE_BRIGHTNESS if ((wbuf - outTemp > cbuf - inTemp) || (sliceError > MAX_ERRORS)) // yes that might happen, rarely { #ifndef NDEBUG if (sliceError > MAX_ERRORS) { DEBF("sliceError (%i) > MAX_ERRORS (%i)\n", sliceError, MAX_ERRORS); } #endif // in this case, we'll just use the original slice ! memcpy(outTemp, inTemp, cbuf - inTemp); wbuf = outTemp + (cbuf - inTemp); // adjust outbytecnt outbytecnt -= (wbuf - outTemp) - (cbuf - inTemp); } #endif #ifdef STAT #ifdef LOG_RATE_CONTROL if (picture_coding_type == I_TYPE) fprintf(LOG_FILE, "-I-\n"); #endif switch(picture_coding_type) { case I_TYPE: ori_i += cbuf - inTemp; new_i += (wbuf - outTemp > cbuf - inTemp) ? (cbuf - inTemp) : (wbuf - outTemp); cnt_i ++; break; case P_TYPE: ori_p += cbuf - inTemp; new_p += (wbuf - outTemp > cbuf - inTemp) ? (cbuf - inTemp) : (wbuf - outTemp); cnt_p ++; break; case B_TYPE: ori_b += cbuf - inTemp; new_b += (wbuf - outTemp > cbuf - inTemp) ? (cbuf - inTemp) : (wbuf - outTemp); cnt_b ++; break; default: assert(0); break; } #endif } } #ifndef NDEBUG if ((ID >= 0x01) && (ID <= 0xAF) && (!validPicHeader || !validSeqHeader || !validExtHeader)) { if (!validPicHeader) DEBF("missing pic header (%02X)\n", ID); if (!validSeqHeader) DEBF("missing seq header (%02X)\n", ID); if (!validExtHeader) DEBF("missing ext header (%02X)\n", ID); } #endif if (rbuf - orbuf > MAX_READ) { MOV_READ } if (wbuf - owbuf > MIN_WRITE) { WRITE } } #ifdef LOG_RATE_CONTROL fclose(LOG_FILE); #endif // keeps gcc happy return 0; } M2VRequantiser-v1.1/putvlc.h0000644000000000000000000002154311422311540016012 0ustar rootroot00000000000000// put blk /* type definitions for variable length code table entries */ typedef struct { unsigned char code; /* right justified */ char len; } VLCtable; /* for codes longer than 8 bits (excluding leading zeroes) */ typedef struct { unsigned short code; /* right justified */ char len; } sVLCtable; /* Table B-2, B-3, B-4 variable length codes for macroblock_type * * indexed by [macroblock_type] */ const static VLCtable mbtypetab[3][32]= { /* I */ { {0,0}, {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}, {1,2}, {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} }, /* P */ { {0,0}, {3,5}, {1,2}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {1,3}, {0,0}, {1,1}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {1,6}, {1,5}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {2,5}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0} }, /* B */ { {0,0}, {3,5}, {0,0}, {0,0}, {2,3}, {0,0}, {3,3}, {0,0}, {2,4}, {0,0}, {3,4}, {0,0}, {2,2}, {0,0}, {3,2}, {0,0}, {0,0}, {1,6}, {0,0}, {0,0}, {0,0}, {0,0}, {2,6}, {0,0}, {0,0}, {0,0}, {3,6}, {0,0}, {0,0}, {0,0}, {2,5}, {0,0} } }; /* Table B-5 ... B-8 variable length codes for macroblock_type in * scalable sequences * * not implemented */ /* Table B-9, variable length codes for coded_block_pattern * * indexed by [coded_block_pattern] */ const static VLCtable cbptable[64]= { {0x01,9}, {0x0b,5}, {0x09,5}, {0x0d,6}, {0x0d,4}, {0x17,7}, {0x13,7}, {0x1f,8}, {0x0c,4}, {0x16,7}, {0x12,7}, {0x1e,8}, {0x13,5}, {0x1b,8}, {0x17,8}, {0x13,8}, {0x0b,4}, {0x15,7}, {0x11,7}, {0x1d,8}, {0x11,5}, {0x19,8}, {0x15,8}, {0x11,8}, {0x0f,6}, {0x0f,8}, {0x0d,8}, {0x03,9}, {0x0f,5}, {0x0b,8}, {0x07,8}, {0x07,9}, {0x0a,4}, {0x14,7}, {0x10,7}, {0x1c,8}, {0x0e,6}, {0x0e,8}, {0x0c,8}, {0x02,9}, {0x10,5}, {0x18,8}, {0x14,8}, {0x10,8}, {0x0e,5}, {0x0a,8}, {0x06,8}, {0x06,9}, {0x12,5}, {0x1a,8}, {0x16,8}, {0x12,8}, {0x0d,5}, {0x09,8}, {0x05,8}, {0x05,9}, {0x0c,5}, {0x08,8}, {0x04,8}, {0x04,9}, {0x07,3}, {0x0a,5}, {0x08,5}, {0x0c,6} }; /* Table B-14, DCT coefficients table zero * * indexed by [run][level-1] * split into two tables (dct_code_tab1, dct_code_tab2) to reduce size * 'first DCT coefficient' condition and 'End of Block' are treated elsewhere * codes do not include s (sign bit) */ const static VLCtable dct_code_tab1[2][40]= { /* run = 0, level = 1...40 */ { {0x03, 2}, {0x04, 4}, {0x05, 5}, {0x06, 7}, {0x26, 8}, {0x21, 8}, {0x0a,10}, {0x1d,12}, {0x18,12}, {0x13,12}, {0x10,12}, {0x1a,13}, {0x19,13}, {0x18,13}, {0x17,13}, {0x1f,14}, {0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14}, {0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14}, {0x16,14}, {0x15,14}, {0x14,14}, {0x13,14}, {0x12,14}, {0x11,14}, {0x10,14}, {0x18,15}, {0x17,15}, {0x16,15}, {0x15,15}, {0x14,15}, {0x13,15}, {0x12,15}, {0x11,15}, {0x10,15} }, /* run = 1, level = 1...18 */ { {0x03, 3}, {0x06, 6}, {0x25, 8}, {0x0c,10}, {0x1b,12}, {0x16,13}, {0x15,13}, {0x1f,15}, {0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15}, {0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16}, {0x11,16}, {0x10,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0} } }; const static VLCtable dct_code_tab2[30][5]= { /* run = 2...31, level = 1...5 */ {{0x05, 4}, {0x04, 7}, {0x0b,10}, {0x14,12}, {0x14,13}}, {{0x07, 5}, {0x24, 8}, {0x1c,12}, {0x13,13}, {0x00, 0}}, {{0x06, 5}, {0x0f,10}, {0x12,12}, {0x00, 0}, {0x00, 0}}, {{0x07, 6}, {0x09,10}, {0x12,13}, {0x00, 0}, {0x00, 0}}, {{0x05, 6}, {0x1e,12}, {0x14,16}, {0x00, 0}, {0x00, 0}}, {{0x04, 6}, {0x15,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x07, 7}, {0x11,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x05, 7}, {0x11,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x27, 8}, {0x10,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x23, 8}, {0x1a,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x22, 8}, {0x19,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x20, 8}, {0x18,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x0e,10}, {0x17,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x0d,10}, {0x16,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x08,10}, {0x15,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1f,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1a,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x19,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x17,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x16,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1f,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1e,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1d,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1c,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1b,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1f,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1e,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1d,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1c,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1b,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}} }; /* Table B-15, DCT coefficients table one * * indexed by [run][level-1] * split into two tables (dct_code_tab1a, dct_code_tab2a) to reduce size * 'End of Block' is treated elsewhere * codes do not include s (sign bit) */ const static VLCtable dct_code_tab1a[2][40]= { /* run = 0, level = 1...40 */ { {0x02, 2}, {0x06, 3}, {0x07, 4}, {0x1c, 5}, {0x1d, 5}, {0x05, 6}, {0x04, 6}, {0x7b, 7}, {0x7c, 7}, {0x23, 8}, {0x22, 8}, {0xfa, 8}, {0xfb, 8}, {0xfe, 8}, {0xff, 8}, {0x1f,14}, {0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14}, {0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14}, {0x16,14}, {0x15,14}, {0x14,14}, {0x13,14}, {0x12,14}, {0x11,14}, {0x10,14}, {0x18,15}, {0x17,15}, {0x16,15}, {0x15,15}, {0x14,15}, {0x13,15}, {0x12,15}, {0x11,15}, {0x10,15} }, /* run = 1, level = 1...18 */ { {0x02, 3}, {0x06, 5}, {0x79, 7}, {0x27, 8}, {0x20, 8}, {0x16,13}, {0x15,13}, {0x1f,15}, {0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15}, {0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16}, {0x11,16}, {0x10,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0} } }; const static VLCtable dct_code_tab2a[30][5]= { /* run = 2...31, level = 1...5 */ {{0x05, 5}, {0x07, 7}, {0xfc, 8}, {0x0c,10}, {0x14,13}}, {{0x07, 5}, {0x26, 8}, {0x1c,12}, {0x13,13}, {0x00, 0}}, {{0x06, 6}, {0xfd, 8}, {0x12,12}, {0x00, 0}, {0x00, 0}}, {{0x07, 6}, {0x04, 9}, {0x12,13}, {0x00, 0}, {0x00, 0}}, {{0x06, 7}, {0x1e,12}, {0x14,16}, {0x00, 0}, {0x00, 0}}, {{0x04, 7}, {0x15,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x05, 7}, {0x11,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x78, 7}, {0x11,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x7a, 7}, {0x10,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x21, 8}, {0x1a,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x25, 8}, {0x19,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x24, 8}, {0x18,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x05, 9}, {0x17,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x07, 9}, {0x16,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x0d,10}, {0x15,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1f,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1a,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x19,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x17,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x16,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1f,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1e,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1d,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1c,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1b,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1f,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1e,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1d,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1c,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}, {{0x1b,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}} }; const static VLCtable addrinctab[33]= { {0x01,1}, {0x03,3}, {0x02,3}, {0x03,4}, {0x02,4}, {0x03,5}, {0x02,5}, {0x07,7}, {0x06,7}, {0x0b,8}, {0x0a,8}, {0x09,8}, {0x08,8}, {0x07,8}, {0x06,8}, {0x17,10}, {0x16,10}, {0x15,10}, {0x14,10}, {0x13,10}, {0x12,10}, {0x23,11}, {0x22,11}, {0x21,11}, {0x20,11}, {0x1f,11}, {0x1e,11}, {0x1d,11}, {0x1c,11}, {0x1b,11}, {0x1a,11}, {0x19,11}, {0x18,11} }; const static sVLCtable DClumtab[12]= { {0x0004,3}, {0x0000,2}, {0x0001,2}, {0x0005,3}, {0x0006,3}, {0x000e,4}, {0x001e,5}, {0x003e,6}, {0x007e,7}, {0x00fe,8}, {0x01fe,9}, {0x01ff,9} }; M2VRequantiser-v1.1/qTable.h0000644000000000000000000017204411422311540015710 0ustar rootroot00000000000000static short quant_equ[113] = { 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 34, 34, 35, 35, 36, 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 39, 39, 40, 40, 40, 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41 }; static short quant_table_1_to_2[4096]; static short quant_table_1_to_3[4096]; static short quant_table_1_to_4[4096]; static short quant_table_1_to_5[4096]; static short quant_table_1_to_6[4096]; static short quant_table_1_to_7[4096]; static short quant_table_1_to_8[4096]; static short quant_table_1_to_10[4096]; static short quant_table_1_to_12[4096]; static short quant_table_1_to_14[4096]; static short quant_table_1_to_16[4096]; static short quant_table_1_to_18[4096]; static short quant_table_1_to_20[4096]; static short quant_table_1_to_22[4096]; static short quant_table_1_to_24[4096]; static short quant_table_1_to_26[4096]; static short quant_table_1_to_28[4096]; static short quant_table_1_to_30[4096]; static short quant_table_1_to_32[4096]; static short quant_table_1_to_34[4096]; static short quant_table_1_to_36[4096]; static short quant_table_1_to_38[4096]; static short quant_table_1_to_40[4096]; static short quant_table_1_to_42[4096]; static short quant_table_1_to_44[4096]; static short quant_table_1_to_46[4096]; static short quant_table_1_to_48[4096]; static short quant_table_1_to_50[4096]; static short quant_table_1_to_52[4096]; static short quant_table_1_to_54[4096]; static short quant_table_1_to_56[4096]; static short quant_table_1_to_58[4096]; static short quant_table_1_to_60[4096]; static short quant_table_1_to_62[4096]; static short quant_table_1_to_64[4096]; static short quant_table_1_to_72[4096]; static short quant_table_1_to_80[4096]; static short quant_table_1_to_88[4096]; static short quant_table_1_to_96[4096]; static short quant_table_1_to_104[4096]; static short quant_table_1_to_112[4096]; static short quant_table_2_to_3[4096]; static short quant_table_2_to_4[4096]; static short quant_table_2_to_5[4096]; static short quant_table_2_to_6[4096]; static short quant_table_2_to_7[4096]; static short quant_table_2_to_8[4096]; static short quant_table_2_to_10[4096]; static short quant_table_2_to_12[4096]; static short quant_table_2_to_14[4096]; static short quant_table_2_to_16[4096]; static short quant_table_2_to_18[4096]; static short quant_table_2_to_20[4096]; static short quant_table_2_to_22[4096]; static short quant_table_2_to_24[4096]; static short quant_table_2_to_26[4096]; static short quant_table_2_to_28[4096]; static short quant_table_2_to_30[4096]; static short quant_table_2_to_32[4096]; static short quant_table_2_to_34[4096]; static short quant_table_2_to_36[4096]; static short quant_table_2_to_38[4096]; static short quant_table_2_to_40[4096]; static short quant_table_2_to_42[4096]; static short quant_table_2_to_44[4096]; static short quant_table_2_to_46[4096]; static short quant_table_2_to_48[4096]; static short quant_table_2_to_50[4096]; static short quant_table_2_to_52[4096]; static short quant_table_2_to_54[4096]; static short quant_table_2_to_56[4096]; static short quant_table_2_to_58[4096]; static short quant_table_2_to_60[4096]; static short quant_table_2_to_62[4096]; static short quant_table_2_to_64[4096]; static short quant_table_2_to_72[4096]; static short quant_table_2_to_80[4096]; static short quant_table_2_to_88[4096]; static short quant_table_2_to_96[4096]; static short quant_table_2_to_104[4096]; static short quant_table_2_to_112[4096]; static short quant_table_3_to_4[4096]; static short quant_table_3_to_5[4096]; static short quant_table_3_to_6[4096]; static short quant_table_3_to_7[4096]; static short quant_table_3_to_8[4096]; static short quant_table_3_to_10[4096]; static short quant_table_3_to_12[4096]; static short quant_table_3_to_14[4096]; static short quant_table_3_to_16[4096]; static short quant_table_3_to_18[4096]; static short quant_table_3_to_20[4096]; static short quant_table_3_to_22[4096]; static short quant_table_3_to_24[4096]; static short quant_table_3_to_26[4096]; static short quant_table_3_to_28[4096]; static short quant_table_3_to_30[4096]; static short quant_table_3_to_32[4096]; static short quant_table_3_to_34[4096]; static short quant_table_3_to_36[4096]; static short quant_table_3_to_38[4096]; static short quant_table_3_to_40[4096]; static short quant_table_3_to_42[4096]; static short quant_table_3_to_44[4096]; static short quant_table_3_to_46[4096]; static short quant_table_3_to_48[4096]; static short quant_table_3_to_50[4096]; static short quant_table_3_to_52[4096]; static short quant_table_3_to_54[4096]; static short quant_table_3_to_56[4096]; static short quant_table_3_to_58[4096]; static short quant_table_3_to_60[4096]; static short quant_table_3_to_62[4096]; static short quant_table_3_to_64[4096]; static short quant_table_3_to_72[4096]; static short quant_table_3_to_80[4096]; static short quant_table_3_to_88[4096]; static short quant_table_3_to_96[4096]; static short quant_table_3_to_104[4096]; static short quant_table_3_to_112[4096]; static short quant_table_4_to_5[4096]; static short quant_table_4_to_6[4096]; static short quant_table_4_to_7[4096]; static short quant_table_4_to_8[4096]; static short quant_table_4_to_10[4096]; static short quant_table_4_to_12[4096]; static short quant_table_4_to_14[4096]; static short quant_table_4_to_16[4096]; static short quant_table_4_to_18[4096]; static short quant_table_4_to_20[4096]; static short quant_table_4_to_22[4096]; static short quant_table_4_to_24[4096]; static short quant_table_4_to_26[4096]; static short quant_table_4_to_28[4096]; static short quant_table_4_to_30[4096]; static short quant_table_4_to_32[4096]; static short quant_table_4_to_34[4096]; static short quant_table_4_to_36[4096]; static short quant_table_4_to_38[4096]; static short quant_table_4_to_40[4096]; static short quant_table_4_to_42[4096]; static short quant_table_4_to_44[4096]; static short quant_table_4_to_46[4096]; static short quant_table_4_to_48[4096]; static short quant_table_4_to_50[4096]; static short quant_table_4_to_52[4096]; static short quant_table_4_to_54[4096]; static short quant_table_4_to_56[4096]; static short quant_table_4_to_58[4096]; static short quant_table_4_to_60[4096]; static short quant_table_4_to_62[4096]; static short quant_table_4_to_64[4096]; static short quant_table_4_to_72[4096]; static short quant_table_4_to_80[4096]; static short quant_table_4_to_88[4096]; static short quant_table_4_to_96[4096]; static short quant_table_4_to_104[4096]; static short quant_table_4_to_112[4096]; static short quant_table_5_to_6[4096]; static short quant_table_5_to_7[4096]; static short quant_table_5_to_8[4096]; static short quant_table_5_to_10[4096]; static short quant_table_5_to_12[4096]; static short quant_table_5_to_14[4096]; static short quant_table_5_to_16[4096]; static short quant_table_5_to_18[4096]; static short quant_table_5_to_20[4096]; static short quant_table_5_to_22[4096]; static short quant_table_5_to_24[4096]; static short quant_table_5_to_26[4096]; static short quant_table_5_to_28[4096]; static short quant_table_5_to_30[4096]; static short quant_table_5_to_32[4096]; static short quant_table_5_to_34[4096]; static short quant_table_5_to_36[4096]; static short quant_table_5_to_38[4096]; static short quant_table_5_to_40[4096]; static short quant_table_5_to_42[4096]; static short quant_table_5_to_44[4096]; static short quant_table_5_to_46[4096]; static short quant_table_5_to_48[4096]; static short quant_table_5_to_50[4096]; static short quant_table_5_to_52[4096]; static short quant_table_5_to_54[4096]; static short quant_table_5_to_56[4096]; static short quant_table_5_to_58[4096]; static short quant_table_5_to_60[4096]; static short quant_table_5_to_62[4096]; static short quant_table_5_to_64[4096]; static short quant_table_5_to_72[4096]; static short quant_table_5_to_80[4096]; static short quant_table_5_to_88[4096]; static short quant_table_5_to_96[4096]; static short quant_table_5_to_104[4096]; static short quant_table_5_to_112[4096]; static short quant_table_6_to_7[4096]; static short quant_table_6_to_8[4096]; static short quant_table_6_to_10[4096]; static short quant_table_6_to_12[4096]; static short quant_table_6_to_14[4096]; static short quant_table_6_to_16[4096]; static short quant_table_6_to_18[4096]; static short quant_table_6_to_20[4096]; static short quant_table_6_to_22[4096]; static short quant_table_6_to_24[4096]; static short quant_table_6_to_26[4096]; static short quant_table_6_to_28[4096]; static short quant_table_6_to_30[4096]; static short quant_table_6_to_32[4096]; static short quant_table_6_to_34[4096]; static short quant_table_6_to_36[4096]; static short quant_table_6_to_38[4096]; static short quant_table_6_to_40[4096]; static short quant_table_6_to_42[4096]; static short quant_table_6_to_44[4096]; static short quant_table_6_to_46[4096]; static short quant_table_6_to_48[4096]; static short quant_table_6_to_50[4096]; static short quant_table_6_to_52[4096]; static short quant_table_6_to_54[4096]; static short quant_table_6_to_56[4096]; static short quant_table_6_to_58[4096]; static short quant_table_6_to_60[4096]; static short quant_table_6_to_62[4096]; static short quant_table_6_to_64[4096]; static short quant_table_6_to_72[4096]; static short quant_table_6_to_80[4096]; static short quant_table_6_to_88[4096]; static short quant_table_6_to_96[4096]; static short quant_table_6_to_104[4096]; static short quant_table_6_to_112[4096]; static short quant_table_7_to_8[4096]; static short quant_table_7_to_10[4096]; static short quant_table_7_to_12[4096]; static short quant_table_7_to_14[4096]; static short quant_table_7_to_16[4096]; static short quant_table_7_to_18[4096]; static short quant_table_7_to_20[4096]; static short quant_table_7_to_22[4096]; static short quant_table_7_to_24[4096]; static short quant_table_7_to_26[4096]; static short quant_table_7_to_28[4096]; static short quant_table_7_to_30[4096]; static short quant_table_7_to_32[4096]; static short quant_table_7_to_34[4096]; static short quant_table_7_to_36[4096]; static short quant_table_7_to_38[4096]; static short quant_table_7_to_40[4096]; static short quant_table_7_to_42[4096]; static short quant_table_7_to_44[4096]; static short quant_table_7_to_46[4096]; static short quant_table_7_to_48[4096]; static short quant_table_7_to_50[4096]; static short quant_table_7_to_52[4096]; static short quant_table_7_to_54[4096]; static short quant_table_7_to_56[4096]; static short quant_table_7_to_58[4096]; static short quant_table_7_to_60[4096]; static short quant_table_7_to_62[4096]; static short quant_table_7_to_64[4096]; static short quant_table_7_to_72[4096]; static short quant_table_7_to_80[4096]; static short quant_table_7_to_88[4096]; static short quant_table_7_to_96[4096]; static short quant_table_7_to_104[4096]; static short quant_table_7_to_112[4096]; static short quant_table_8_to_10[4096]; static short quant_table_8_to_12[4096]; static short quant_table_8_to_14[4096]; static short quant_table_8_to_16[4096]; static short quant_table_8_to_18[4096]; static short quant_table_8_to_20[4096]; static short quant_table_8_to_22[4096]; static short quant_table_8_to_24[4096]; static short quant_table_8_to_26[4096]; static short quant_table_8_to_28[4096]; static short quant_table_8_to_30[4096]; static short quant_table_8_to_32[4096]; static short quant_table_8_to_34[4096]; static short quant_table_8_to_36[4096]; static short quant_table_8_to_38[4096]; static short quant_table_8_to_40[4096]; static short quant_table_8_to_42[4096]; static short quant_table_8_to_44[4096]; static short quant_table_8_to_46[4096]; static short quant_table_8_to_48[4096]; static short quant_table_8_to_50[4096]; static short quant_table_8_to_52[4096]; static short quant_table_8_to_54[4096]; static short quant_table_8_to_56[4096]; static short quant_table_8_to_58[4096]; static short quant_table_8_to_60[4096]; static short quant_table_8_to_62[4096]; static short quant_table_8_to_64[4096]; static short quant_table_8_to_72[4096]; static short quant_table_8_to_80[4096]; static short quant_table_8_to_88[4096]; static short quant_table_8_to_96[4096]; static short quant_table_8_to_104[4096]; static short quant_table_8_to_112[4096]; static short quant_table_10_to_12[4096]; static short quant_table_10_to_14[4096]; static short quant_table_10_to_16[4096]; static short quant_table_10_to_18[4096]; static short quant_table_10_to_20[4096]; static short quant_table_10_to_22[4096]; static short quant_table_10_to_24[4096]; static short quant_table_10_to_26[4096]; static short quant_table_10_to_28[4096]; static short quant_table_10_to_30[4096]; static short quant_table_10_to_32[4096]; static short quant_table_10_to_34[4096]; static short quant_table_10_to_36[4096]; static short quant_table_10_to_38[4096]; static short quant_table_10_to_40[4096]; static short quant_table_10_to_42[4096]; static short quant_table_10_to_44[4096]; static short quant_table_10_to_46[4096]; static short quant_table_10_to_48[4096]; static short quant_table_10_to_50[4096]; static short quant_table_10_to_52[4096]; static short quant_table_10_to_54[4096]; static short quant_table_10_to_56[4096]; static short quant_table_10_to_58[4096]; static short quant_table_10_to_60[4096]; static short quant_table_10_to_62[4096]; static short quant_table_10_to_64[4096]; static short quant_table_10_to_72[4096]; static short quant_table_10_to_80[4096]; static short quant_table_10_to_88[4096]; static short quant_table_10_to_96[4096]; static short quant_table_10_to_104[4096]; static short quant_table_10_to_112[4096]; static short quant_table_12_to_14[4096]; static short quant_table_12_to_16[4096]; static short quant_table_12_to_18[4096]; static short quant_table_12_to_20[4096]; static short quant_table_12_to_22[4096]; static short quant_table_12_to_24[4096]; static short quant_table_12_to_26[4096]; static short quant_table_12_to_28[4096]; static short quant_table_12_to_30[4096]; static short quant_table_12_to_32[4096]; static short quant_table_12_to_34[4096]; static short quant_table_12_to_36[4096]; static short quant_table_12_to_38[4096]; static short quant_table_12_to_40[4096]; static short quant_table_12_to_42[4096]; static short quant_table_12_to_44[4096]; static short quant_table_12_to_46[4096]; static short quant_table_12_to_48[4096]; static short quant_table_12_to_50[4096]; static short quant_table_12_to_52[4096]; static short quant_table_12_to_54[4096]; static short quant_table_12_to_56[4096]; static short quant_table_12_to_58[4096]; static short quant_table_12_to_60[4096]; static short quant_table_12_to_62[4096]; static short quant_table_12_to_64[4096]; static short quant_table_12_to_72[4096]; static short quant_table_12_to_80[4096]; static short quant_table_12_to_88[4096]; static short quant_table_12_to_96[4096]; static short quant_table_12_to_104[4096]; static short quant_table_12_to_112[4096]; static short quant_table_14_to_16[4096]; static short quant_table_14_to_18[4096]; static short quant_table_14_to_20[4096]; static short quant_table_14_to_22[4096]; static short quant_table_14_to_24[4096]; static short quant_table_14_to_26[4096]; static short quant_table_14_to_28[4096]; static short quant_table_14_to_30[4096]; static short quant_table_14_to_32[4096]; static short quant_table_14_to_34[4096]; static short quant_table_14_to_36[4096]; static short quant_table_14_to_38[4096]; static short quant_table_14_to_40[4096]; static short quant_table_14_to_42[4096]; static short quant_table_14_to_44[4096]; static short quant_table_14_to_46[4096]; static short quant_table_14_to_48[4096]; static short quant_table_14_to_50[4096]; static short quant_table_14_to_52[4096]; static short quant_table_14_to_54[4096]; static short quant_table_14_to_56[4096]; static short quant_table_14_to_58[4096]; static short quant_table_14_to_60[4096]; static short quant_table_14_to_62[4096]; static short quant_table_14_to_64[4096]; static short quant_table_14_to_72[4096]; static short quant_table_14_to_80[4096]; static short quant_table_14_to_88[4096]; static short quant_table_14_to_96[4096]; static short quant_table_14_to_104[4096]; static short quant_table_14_to_112[4096]; static short quant_table_16_to_18[4096]; static short quant_table_16_to_20[4096]; static short quant_table_16_to_22[4096]; static short quant_table_16_to_24[4096]; static short quant_table_16_to_26[4096]; static short quant_table_16_to_28[4096]; static short quant_table_16_to_30[4096]; static short quant_table_16_to_32[4096]; static short quant_table_16_to_34[4096]; static short quant_table_16_to_36[4096]; static short quant_table_16_to_38[4096]; static short quant_table_16_to_40[4096]; static short quant_table_16_to_42[4096]; static short quant_table_16_to_44[4096]; static short quant_table_16_to_46[4096]; static short quant_table_16_to_48[4096]; static short quant_table_16_to_50[4096]; static short quant_table_16_to_52[4096]; static short quant_table_16_to_54[4096]; static short quant_table_16_to_56[4096]; static short quant_table_16_to_58[4096]; static short quant_table_16_to_60[4096]; static short quant_table_16_to_62[4096]; static short quant_table_16_to_64[4096]; static short quant_table_16_to_72[4096]; static short quant_table_16_to_80[4096]; static short quant_table_16_to_88[4096]; static short quant_table_16_to_96[4096]; static short quant_table_16_to_104[4096]; static short quant_table_16_to_112[4096]; static short quant_table_18_to_20[4096]; static short quant_table_18_to_22[4096]; static short quant_table_18_to_24[4096]; static short quant_table_18_to_26[4096]; static short quant_table_18_to_28[4096]; static short quant_table_18_to_30[4096]; static short quant_table_18_to_32[4096]; static short quant_table_18_to_34[4096]; static short quant_table_18_to_36[4096]; static short quant_table_18_to_38[4096]; static short quant_table_18_to_40[4096]; static short quant_table_18_to_42[4096]; static short quant_table_18_to_44[4096]; static short quant_table_18_to_46[4096]; static short quant_table_18_to_48[4096]; static short quant_table_18_to_50[4096]; static short quant_table_18_to_52[4096]; static short quant_table_18_to_54[4096]; static short quant_table_18_to_56[4096]; static short quant_table_18_to_58[4096]; static short quant_table_18_to_60[4096]; static short quant_table_18_to_62[4096]; static short quant_table_18_to_64[4096]; static short quant_table_18_to_72[4096]; static short quant_table_18_to_80[4096]; static short quant_table_18_to_88[4096]; static short quant_table_18_to_96[4096]; static short quant_table_18_to_104[4096]; static short quant_table_18_to_112[4096]; static short quant_table_20_to_22[4096]; static short quant_table_20_to_24[4096]; static short quant_table_20_to_26[4096]; static short quant_table_20_to_28[4096]; static short quant_table_20_to_30[4096]; static short quant_table_20_to_32[4096]; static short quant_table_20_to_34[4096]; static short quant_table_20_to_36[4096]; static short quant_table_20_to_38[4096]; static short quant_table_20_to_40[4096]; static short quant_table_20_to_42[4096]; static short quant_table_20_to_44[4096]; static short quant_table_20_to_46[4096]; static short quant_table_20_to_48[4096]; static short quant_table_20_to_50[4096]; static short quant_table_20_to_52[4096]; static short quant_table_20_to_54[4096]; static short quant_table_20_to_56[4096]; static short quant_table_20_to_58[4096]; static short quant_table_20_to_60[4096]; static short quant_table_20_to_62[4096]; static short quant_table_20_to_64[4096]; static short quant_table_20_to_72[4096]; static short quant_table_20_to_80[4096]; static short quant_table_20_to_88[4096]; static short quant_table_20_to_96[4096]; static short quant_table_20_to_104[4096]; static short quant_table_20_to_112[4096]; static short quant_table_22_to_24[4096]; static short quant_table_22_to_26[4096]; static short quant_table_22_to_28[4096]; static short quant_table_22_to_30[4096]; static short quant_table_22_to_32[4096]; static short quant_table_22_to_34[4096]; static short quant_table_22_to_36[4096]; static short quant_table_22_to_38[4096]; static short quant_table_22_to_40[4096]; static short quant_table_22_to_42[4096]; static short quant_table_22_to_44[4096]; static short quant_table_22_to_46[4096]; static short quant_table_22_to_48[4096]; static short quant_table_22_to_50[4096]; static short quant_table_22_to_52[4096]; static short quant_table_22_to_54[4096]; static short quant_table_22_to_56[4096]; static short quant_table_22_to_58[4096]; static short quant_table_22_to_60[4096]; static short quant_table_22_to_62[4096]; static short quant_table_22_to_64[4096]; static short quant_table_22_to_72[4096]; static short quant_table_22_to_80[4096]; static short quant_table_22_to_88[4096]; static short quant_table_22_to_96[4096]; static short quant_table_22_to_104[4096]; static short quant_table_22_to_112[4096]; static short quant_table_24_to_26[4096]; static short quant_table_24_to_28[4096]; static short quant_table_24_to_30[4096]; static short quant_table_24_to_32[4096]; static short quant_table_24_to_34[4096]; static short quant_table_24_to_36[4096]; static short quant_table_24_to_38[4096]; static short quant_table_24_to_40[4096]; static short quant_table_24_to_42[4096]; static short quant_table_24_to_44[4096]; static short quant_table_24_to_46[4096]; static short quant_table_24_to_48[4096]; static short quant_table_24_to_50[4096]; static short quant_table_24_to_52[4096]; static short quant_table_24_to_54[4096]; static short quant_table_24_to_56[4096]; static short quant_table_24_to_58[4096]; static short quant_table_24_to_60[4096]; static short quant_table_24_to_62[4096]; static short quant_table_24_to_64[4096]; static short quant_table_24_to_72[4096]; static short quant_table_24_to_80[4096]; static short quant_table_24_to_88[4096]; static short quant_table_24_to_96[4096]; static short quant_table_24_to_104[4096]; static short quant_table_24_to_112[4096]; static short quant_table_26_to_28[4096]; static short quant_table_26_to_30[4096]; static short quant_table_26_to_32[4096]; static short quant_table_26_to_34[4096]; static short quant_table_26_to_36[4096]; static short quant_table_26_to_38[4096]; static short quant_table_26_to_40[4096]; static short quant_table_26_to_42[4096]; static short quant_table_26_to_44[4096]; static short quant_table_26_to_46[4096]; static short quant_table_26_to_48[4096]; static short quant_table_26_to_50[4096]; static short quant_table_26_to_52[4096]; static short quant_table_26_to_54[4096]; static short quant_table_26_to_56[4096]; static short quant_table_26_to_58[4096]; static short quant_table_26_to_60[4096]; static short quant_table_26_to_62[4096]; static short quant_table_26_to_64[4096]; static short quant_table_26_to_72[4096]; static short quant_table_26_to_80[4096]; static short quant_table_26_to_88[4096]; static short quant_table_26_to_96[4096]; static short quant_table_26_to_104[4096]; static short quant_table_26_to_112[4096]; static short quant_table_28_to_30[4096]; static short quant_table_28_to_32[4096]; static short quant_table_28_to_34[4096]; static short quant_table_28_to_36[4096]; static short quant_table_28_to_38[4096]; static short quant_table_28_to_40[4096]; static short quant_table_28_to_42[4096]; static short quant_table_28_to_44[4096]; static short quant_table_28_to_46[4096]; static short quant_table_28_to_48[4096]; static short quant_table_28_to_50[4096]; static short quant_table_28_to_52[4096]; static short quant_table_28_to_54[4096]; static short quant_table_28_to_56[4096]; static short quant_table_28_to_58[4096]; static short quant_table_28_to_60[4096]; static short quant_table_28_to_62[4096]; static short quant_table_28_to_64[4096]; static short quant_table_28_to_72[4096]; static short quant_table_28_to_80[4096]; static short quant_table_28_to_88[4096]; static short quant_table_28_to_96[4096]; static short quant_table_28_to_104[4096]; static short quant_table_28_to_112[4096]; static short quant_table_30_to_32[4096]; static short quant_table_30_to_34[4096]; static short quant_table_30_to_36[4096]; static short quant_table_30_to_38[4096]; static short quant_table_30_to_40[4096]; static short quant_table_30_to_42[4096]; static short quant_table_30_to_44[4096]; static short quant_table_30_to_46[4096]; static short quant_table_30_to_48[4096]; static short quant_table_30_to_50[4096]; static short quant_table_30_to_52[4096]; static short quant_table_30_to_54[4096]; static short quant_table_30_to_56[4096]; static short quant_table_30_to_58[4096]; static short quant_table_30_to_60[4096]; static short quant_table_30_to_62[4096]; static short quant_table_30_to_64[4096]; static short quant_table_30_to_72[4096]; static short quant_table_30_to_80[4096]; static short quant_table_30_to_88[4096]; static short quant_table_30_to_96[4096]; static short quant_table_30_to_104[4096]; static short quant_table_30_to_112[4096]; static short quant_table_32_to_34[4096]; static short quant_table_32_to_36[4096]; static short quant_table_32_to_38[4096]; static short quant_table_32_to_40[4096]; static short quant_table_32_to_42[4096]; static short quant_table_32_to_44[4096]; static short quant_table_32_to_46[4096]; static short quant_table_32_to_48[4096]; static short quant_table_32_to_50[4096]; static short quant_table_32_to_52[4096]; static short quant_table_32_to_54[4096]; static short quant_table_32_to_56[4096]; static short quant_table_32_to_58[4096]; static short quant_table_32_to_60[4096]; static short quant_table_32_to_62[4096]; static short quant_table_32_to_64[4096]; static short quant_table_32_to_72[4096]; static short quant_table_32_to_80[4096]; static short quant_table_32_to_88[4096]; static short quant_table_32_to_96[4096]; static short quant_table_32_to_104[4096]; static short quant_table_32_to_112[4096]; static short quant_table_34_to_36[4096]; static short quant_table_34_to_38[4096]; static short quant_table_34_to_40[4096]; static short quant_table_34_to_42[4096]; static short quant_table_34_to_44[4096]; static short quant_table_34_to_46[4096]; static short quant_table_34_to_48[4096]; static short quant_table_34_to_50[4096]; static short quant_table_34_to_52[4096]; static short quant_table_34_to_54[4096]; static short quant_table_34_to_56[4096]; static short quant_table_34_to_58[4096]; static short quant_table_34_to_60[4096]; static short quant_table_34_to_62[4096]; static short quant_table_34_to_64[4096]; static short quant_table_34_to_72[4096]; static short quant_table_34_to_80[4096]; static short quant_table_34_to_88[4096]; static short quant_table_34_to_96[4096]; static short quant_table_34_to_104[4096]; static short quant_table_34_to_112[4096]; static short quant_table_36_to_38[4096]; static short quant_table_36_to_40[4096]; static short quant_table_36_to_42[4096]; static short quant_table_36_to_44[4096]; static short quant_table_36_to_46[4096]; static short quant_table_36_to_48[4096]; static short quant_table_36_to_50[4096]; static short quant_table_36_to_52[4096]; static short quant_table_36_to_54[4096]; static short quant_table_36_to_56[4096]; static short quant_table_36_to_58[4096]; static short quant_table_36_to_60[4096]; static short quant_table_36_to_62[4096]; static short quant_table_36_to_64[4096]; static short quant_table_36_to_72[4096]; static short quant_table_36_to_80[4096]; static short quant_table_36_to_88[4096]; static short quant_table_36_to_96[4096]; static short quant_table_36_to_104[4096]; static short quant_table_36_to_112[4096]; static short quant_table_38_to_40[4096]; static short quant_table_38_to_42[4096]; static short quant_table_38_to_44[4096]; static short quant_table_38_to_46[4096]; static short quant_table_38_to_48[4096]; static short quant_table_38_to_50[4096]; static short quant_table_38_to_52[4096]; static short quant_table_38_to_54[4096]; static short quant_table_38_to_56[4096]; static short quant_table_38_to_58[4096]; static short quant_table_38_to_60[4096]; static short quant_table_38_to_62[4096]; static short quant_table_38_to_64[4096]; static short quant_table_38_to_72[4096]; static short quant_table_38_to_80[4096]; static short quant_table_38_to_88[4096]; static short quant_table_38_to_96[4096]; static short quant_table_38_to_104[4096]; static short quant_table_38_to_112[4096]; static short quant_table_40_to_42[4096]; static short quant_table_40_to_44[4096]; static short quant_table_40_to_46[4096]; static short quant_table_40_to_48[4096]; static short quant_table_40_to_50[4096]; static short quant_table_40_to_52[4096]; static short quant_table_40_to_54[4096]; static short quant_table_40_to_56[4096]; static short quant_table_40_to_58[4096]; static short quant_table_40_to_60[4096]; static short quant_table_40_to_62[4096]; static short quant_table_40_to_64[4096]; static short quant_table_40_to_72[4096]; static short quant_table_40_to_80[4096]; static short quant_table_40_to_88[4096]; static short quant_table_40_to_96[4096]; static short quant_table_40_to_104[4096]; static short quant_table_40_to_112[4096]; static short quant_table_42_to_44[4096]; static short quant_table_42_to_46[4096]; static short quant_table_42_to_48[4096]; static short quant_table_42_to_50[4096]; static short quant_table_42_to_52[4096]; static short quant_table_42_to_54[4096]; static short quant_table_42_to_56[4096]; static short quant_table_42_to_58[4096]; static short quant_table_42_to_60[4096]; static short quant_table_42_to_62[4096]; static short quant_table_42_to_64[4096]; static short quant_table_42_to_72[4096]; static short quant_table_42_to_80[4096]; static short quant_table_42_to_88[4096]; static short quant_table_42_to_96[4096]; static short quant_table_42_to_104[4096]; static short quant_table_42_to_112[4096]; static short quant_table_44_to_46[4096]; static short quant_table_44_to_48[4096]; static short quant_table_44_to_50[4096]; static short quant_table_44_to_52[4096]; static short quant_table_44_to_54[4096]; static short quant_table_44_to_56[4096]; static short quant_table_44_to_58[4096]; static short quant_table_44_to_60[4096]; static short quant_table_44_to_62[4096]; static short quant_table_44_to_64[4096]; static short quant_table_44_to_72[4096]; static short quant_table_44_to_80[4096]; static short quant_table_44_to_88[4096]; static short quant_table_44_to_96[4096]; static short quant_table_44_to_104[4096]; static short quant_table_44_to_112[4096]; static short quant_table_46_to_48[4096]; static short quant_table_46_to_50[4096]; static short quant_table_46_to_52[4096]; static short quant_table_46_to_54[4096]; static short quant_table_46_to_56[4096]; static short quant_table_46_to_58[4096]; static short quant_table_46_to_60[4096]; static short quant_table_46_to_62[4096]; static short quant_table_46_to_64[4096]; static short quant_table_46_to_72[4096]; static short quant_table_46_to_80[4096]; static short quant_table_46_to_88[4096]; static short quant_table_46_to_96[4096]; static short quant_table_46_to_104[4096]; static short quant_table_46_to_112[4096]; static short quant_table_48_to_50[4096]; static short quant_table_48_to_52[4096]; static short quant_table_48_to_54[4096]; static short quant_table_48_to_56[4096]; static short quant_table_48_to_58[4096]; static short quant_table_48_to_60[4096]; static short quant_table_48_to_62[4096]; static short quant_table_48_to_64[4096]; static short quant_table_48_to_72[4096]; static short quant_table_48_to_80[4096]; static short quant_table_48_to_88[4096]; static short quant_table_48_to_96[4096]; static short quant_table_48_to_104[4096]; static short quant_table_48_to_112[4096]; static short quant_table_50_to_52[4096]; static short quant_table_50_to_54[4096]; static short quant_table_50_to_56[4096]; static short quant_table_50_to_58[4096]; static short quant_table_50_to_60[4096]; static short quant_table_50_to_62[4096]; static short quant_table_50_to_64[4096]; static short quant_table_50_to_72[4096]; static short quant_table_50_to_80[4096]; static short quant_table_50_to_88[4096]; static short quant_table_50_to_96[4096]; static short quant_table_50_to_104[4096]; static short quant_table_50_to_112[4096]; static short quant_table_52_to_54[4096]; static short quant_table_52_to_56[4096]; static short quant_table_52_to_58[4096]; static short quant_table_52_to_60[4096]; static short quant_table_52_to_62[4096]; static short quant_table_52_to_64[4096]; static short quant_table_52_to_72[4096]; static short quant_table_52_to_80[4096]; static short quant_table_52_to_88[4096]; static short quant_table_52_to_96[4096]; static short quant_table_52_to_104[4096]; static short quant_table_52_to_112[4096]; static short quant_table_54_to_56[4096]; static short quant_table_54_to_58[4096]; static short quant_table_54_to_60[4096]; static short quant_table_54_to_62[4096]; static short quant_table_54_to_64[4096]; static short quant_table_54_to_72[4096]; static short quant_table_54_to_80[4096]; static short quant_table_54_to_88[4096]; static short quant_table_54_to_96[4096]; static short quant_table_54_to_104[4096]; static short quant_table_54_to_112[4096]; static short quant_table_56_to_58[4096]; static short quant_table_56_to_60[4096]; static short quant_table_56_to_62[4096]; static short quant_table_56_to_64[4096]; static short quant_table_56_to_72[4096]; static short quant_table_56_to_80[4096]; static short quant_table_56_to_88[4096]; static short quant_table_56_to_96[4096]; static short quant_table_56_to_104[4096]; static short quant_table_56_to_112[4096]; static short quant_table_58_to_60[4096]; static short quant_table_58_to_62[4096]; static short quant_table_58_to_64[4096]; static short quant_table_58_to_72[4096]; static short quant_table_58_to_80[4096]; static short quant_table_58_to_88[4096]; static short quant_table_58_to_96[4096]; static short quant_table_58_to_104[4096]; static short quant_table_58_to_112[4096]; static short quant_table_60_to_62[4096]; static short quant_table_60_to_64[4096]; static short quant_table_60_to_72[4096]; static short quant_table_60_to_80[4096]; static short quant_table_60_to_88[4096]; static short quant_table_60_to_96[4096]; static short quant_table_60_to_104[4096]; static short quant_table_60_to_112[4096]; static short quant_table_62_to_64[4096]; static short quant_table_62_to_72[4096]; static short quant_table_62_to_80[4096]; static short quant_table_62_to_88[4096]; static short quant_table_62_to_96[4096]; static short quant_table_62_to_104[4096]; static short quant_table_62_to_112[4096]; static short quant_table_64_to_72[4096]; static short quant_table_64_to_80[4096]; static short quant_table_64_to_88[4096]; static short quant_table_64_to_96[4096]; static short quant_table_64_to_104[4096]; static short quant_table_64_to_112[4096]; static short quant_table_72_to_80[4096]; static short quant_table_72_to_88[4096]; static short quant_table_72_to_96[4096]; static short quant_table_72_to_104[4096]; static short quant_table_72_to_112[4096]; static short quant_table_80_to_88[4096]; static short quant_table_80_to_96[4096]; static short quant_table_80_to_104[4096]; static short quant_table_80_to_112[4096]; static short quant_table_88_to_96[4096]; static short quant_table_88_to_104[4096]; static short quant_table_88_to_112[4096]; static short quant_table_96_to_104[4096]; static short quant_table_96_to_112[4096]; static short quant_table_104_to_112[4096]; static short *quant_tables[42][42] = { { 0, &quant_table_1_to_2[2048], &quant_table_1_to_3[2048], &quant_table_1_to_4[2048], &quant_table_1_to_5[2048], &quant_table_1_to_6[2048], &quant_table_1_to_7[2048], &quant_table_1_to_8[2048], &quant_table_1_to_10[2048], &quant_table_1_to_12[2048], &quant_table_1_to_14[2048], &quant_table_1_to_16[2048], &quant_table_1_to_18[2048], &quant_table_1_to_20[2048], &quant_table_1_to_22[2048], &quant_table_1_to_24[2048], &quant_table_1_to_26[2048], &quant_table_1_to_28[2048], &quant_table_1_to_30[2048], &quant_table_1_to_32[2048], &quant_table_1_to_34[2048], &quant_table_1_to_36[2048], &quant_table_1_to_38[2048], &quant_table_1_to_40[2048], &quant_table_1_to_42[2048], &quant_table_1_to_44[2048], &quant_table_1_to_46[2048], &quant_table_1_to_48[2048], &quant_table_1_to_50[2048], &quant_table_1_to_52[2048], &quant_table_1_to_54[2048], &quant_table_1_to_56[2048], &quant_table_1_to_58[2048], &quant_table_1_to_60[2048], &quant_table_1_to_62[2048], &quant_table_1_to_64[2048], &quant_table_1_to_72[2048], &quant_table_1_to_80[2048], &quant_table_1_to_88[2048], &quant_table_1_to_96[2048], &quant_table_1_to_104[2048], &quant_table_1_to_112[2048]}, { 0,0, &quant_table_2_to_3[2048], &quant_table_2_to_4[2048], &quant_table_2_to_5[2048], &quant_table_2_to_6[2048], &quant_table_2_to_7[2048], &quant_table_2_to_8[2048], &quant_table_2_to_10[2048], &quant_table_2_to_12[2048], &quant_table_2_to_14[2048], &quant_table_2_to_16[2048], &quant_table_2_to_18[2048], &quant_table_2_to_20[2048], &quant_table_2_to_22[2048], &quant_table_2_to_24[2048], &quant_table_2_to_26[2048], &quant_table_2_to_28[2048], &quant_table_2_to_30[2048], &quant_table_2_to_32[2048], &quant_table_2_to_34[2048], &quant_table_2_to_36[2048], &quant_table_2_to_38[2048], &quant_table_2_to_40[2048], &quant_table_2_to_42[2048], &quant_table_2_to_44[2048], &quant_table_2_to_46[2048], &quant_table_2_to_48[2048], &quant_table_2_to_50[2048], &quant_table_2_to_52[2048], &quant_table_2_to_54[2048], &quant_table_2_to_56[2048], &quant_table_2_to_58[2048], &quant_table_2_to_60[2048], &quant_table_2_to_62[2048], &quant_table_2_to_64[2048], &quant_table_2_to_72[2048], &quant_table_2_to_80[2048], &quant_table_2_to_88[2048], &quant_table_2_to_96[2048], &quant_table_2_to_104[2048], &quant_table_2_to_112[2048]}, { 0,0,0, &quant_table_3_to_4[2048], &quant_table_3_to_5[2048], &quant_table_3_to_6[2048], &quant_table_3_to_7[2048], &quant_table_3_to_8[2048], &quant_table_3_to_10[2048], &quant_table_3_to_12[2048], &quant_table_3_to_14[2048], &quant_table_3_to_16[2048], &quant_table_3_to_18[2048], &quant_table_3_to_20[2048], &quant_table_3_to_22[2048], &quant_table_3_to_24[2048], &quant_table_3_to_26[2048], &quant_table_3_to_28[2048], &quant_table_3_to_30[2048], &quant_table_3_to_32[2048], &quant_table_3_to_34[2048], &quant_table_3_to_36[2048], &quant_table_3_to_38[2048], &quant_table_3_to_40[2048], &quant_table_3_to_42[2048], &quant_table_3_to_44[2048], &quant_table_3_to_46[2048], &quant_table_3_to_48[2048], &quant_table_3_to_50[2048], &quant_table_3_to_52[2048], &quant_table_3_to_54[2048], &quant_table_3_to_56[2048], &quant_table_3_to_58[2048], &quant_table_3_to_60[2048], &quant_table_3_to_62[2048], &quant_table_3_to_64[2048], &quant_table_3_to_72[2048], &quant_table_3_to_80[2048], &quant_table_3_to_88[2048], &quant_table_3_to_96[2048], &quant_table_3_to_104[2048], &quant_table_3_to_112[2048]}, { 0,0,0,0, &quant_table_4_to_5[2048], &quant_table_4_to_6[2048], &quant_table_4_to_7[2048], &quant_table_4_to_8[2048], &quant_table_4_to_10[2048], &quant_table_4_to_12[2048], &quant_table_4_to_14[2048], &quant_table_4_to_16[2048], &quant_table_4_to_18[2048], &quant_table_4_to_20[2048], &quant_table_4_to_22[2048], &quant_table_4_to_24[2048], &quant_table_4_to_26[2048], &quant_table_4_to_28[2048], &quant_table_4_to_30[2048], &quant_table_4_to_32[2048], &quant_table_4_to_34[2048], &quant_table_4_to_36[2048], &quant_table_4_to_38[2048], &quant_table_4_to_40[2048], &quant_table_4_to_42[2048], &quant_table_4_to_44[2048], &quant_table_4_to_46[2048], &quant_table_4_to_48[2048], &quant_table_4_to_50[2048], &quant_table_4_to_52[2048], &quant_table_4_to_54[2048], &quant_table_4_to_56[2048], &quant_table_4_to_58[2048], &quant_table_4_to_60[2048], &quant_table_4_to_62[2048], &quant_table_4_to_64[2048], &quant_table_4_to_72[2048], &quant_table_4_to_80[2048], &quant_table_4_to_88[2048], &quant_table_4_to_96[2048], &quant_table_4_to_104[2048], &quant_table_4_to_112[2048]}, { 0,0,0,0,0, &quant_table_5_to_6[2048], &quant_table_5_to_7[2048], &quant_table_5_to_8[2048], &quant_table_5_to_10[2048], &quant_table_5_to_12[2048], &quant_table_5_to_14[2048], &quant_table_5_to_16[2048], &quant_table_5_to_18[2048], &quant_table_5_to_20[2048], &quant_table_5_to_22[2048], &quant_table_5_to_24[2048], &quant_table_5_to_26[2048], &quant_table_5_to_28[2048], &quant_table_5_to_30[2048], &quant_table_5_to_32[2048], &quant_table_5_to_34[2048], &quant_table_5_to_36[2048], &quant_table_5_to_38[2048], &quant_table_5_to_40[2048], &quant_table_5_to_42[2048], &quant_table_5_to_44[2048], &quant_table_5_to_46[2048], &quant_table_5_to_48[2048], &quant_table_5_to_50[2048], &quant_table_5_to_52[2048], &quant_table_5_to_54[2048], &quant_table_5_to_56[2048], &quant_table_5_to_58[2048], &quant_table_5_to_60[2048], &quant_table_5_to_62[2048], &quant_table_5_to_64[2048], &quant_table_5_to_72[2048], &quant_table_5_to_80[2048], &quant_table_5_to_88[2048], &quant_table_5_to_96[2048], &quant_table_5_to_104[2048], &quant_table_5_to_112[2048]}, { 0,0,0,0,0,0, &quant_table_6_to_7[2048], &quant_table_6_to_8[2048], &quant_table_6_to_10[2048], &quant_table_6_to_12[2048], &quant_table_6_to_14[2048], &quant_table_6_to_16[2048], &quant_table_6_to_18[2048], &quant_table_6_to_20[2048], &quant_table_6_to_22[2048], &quant_table_6_to_24[2048], &quant_table_6_to_26[2048], &quant_table_6_to_28[2048], &quant_table_6_to_30[2048], &quant_table_6_to_32[2048], &quant_table_6_to_34[2048], &quant_table_6_to_36[2048], &quant_table_6_to_38[2048], &quant_table_6_to_40[2048], &quant_table_6_to_42[2048], &quant_table_6_to_44[2048], &quant_table_6_to_46[2048], &quant_table_6_to_48[2048], &quant_table_6_to_50[2048], &quant_table_6_to_52[2048], &quant_table_6_to_54[2048], &quant_table_6_to_56[2048], &quant_table_6_to_58[2048], &quant_table_6_to_60[2048], &quant_table_6_to_62[2048], &quant_table_6_to_64[2048], &quant_table_6_to_72[2048], &quant_table_6_to_80[2048], &quant_table_6_to_88[2048], &quant_table_6_to_96[2048], &quant_table_6_to_104[2048], &quant_table_6_to_112[2048]}, { 0,0,0,0,0,0,0, &quant_table_7_to_8[2048], &quant_table_7_to_10[2048], &quant_table_7_to_12[2048], &quant_table_7_to_14[2048], &quant_table_7_to_16[2048], &quant_table_7_to_18[2048], &quant_table_7_to_20[2048], &quant_table_7_to_22[2048], &quant_table_7_to_24[2048], &quant_table_7_to_26[2048], &quant_table_7_to_28[2048], &quant_table_7_to_30[2048], &quant_table_7_to_32[2048], &quant_table_7_to_34[2048], &quant_table_7_to_36[2048], &quant_table_7_to_38[2048], &quant_table_7_to_40[2048], &quant_table_7_to_42[2048], &quant_table_7_to_44[2048], &quant_table_7_to_46[2048], &quant_table_7_to_48[2048], &quant_table_7_to_50[2048], &quant_table_7_to_52[2048], &quant_table_7_to_54[2048], &quant_table_7_to_56[2048], &quant_table_7_to_58[2048], &quant_table_7_to_60[2048], &quant_table_7_to_62[2048], &quant_table_7_to_64[2048], &quant_table_7_to_72[2048], &quant_table_7_to_80[2048], &quant_table_7_to_88[2048], &quant_table_7_to_96[2048], &quant_table_7_to_104[2048], &quant_table_7_to_112[2048]}, { 0,0,0,0,0,0,0,0, &quant_table_8_to_10[2048], &quant_table_8_to_12[2048], &quant_table_8_to_14[2048], &quant_table_8_to_16[2048], &quant_table_8_to_18[2048], &quant_table_8_to_20[2048], &quant_table_8_to_22[2048], &quant_table_8_to_24[2048], &quant_table_8_to_26[2048], &quant_table_8_to_28[2048], &quant_table_8_to_30[2048], &quant_table_8_to_32[2048], &quant_table_8_to_34[2048], &quant_table_8_to_36[2048], &quant_table_8_to_38[2048], &quant_table_8_to_40[2048], &quant_table_8_to_42[2048], &quant_table_8_to_44[2048], &quant_table_8_to_46[2048], &quant_table_8_to_48[2048], &quant_table_8_to_50[2048], &quant_table_8_to_52[2048], &quant_table_8_to_54[2048], &quant_table_8_to_56[2048], &quant_table_8_to_58[2048], &quant_table_8_to_60[2048], &quant_table_8_to_62[2048], &quant_table_8_to_64[2048], &quant_table_8_to_72[2048], &quant_table_8_to_80[2048], &quant_table_8_to_88[2048], &quant_table_8_to_96[2048], &quant_table_8_to_104[2048], &quant_table_8_to_112[2048]}, { 0,0,0,0,0,0,0,0,0, &quant_table_10_to_12[2048], &quant_table_10_to_14[2048], &quant_table_10_to_16[2048], &quant_table_10_to_18[2048], &quant_table_10_to_20[2048], &quant_table_10_to_22[2048], &quant_table_10_to_24[2048], &quant_table_10_to_26[2048], &quant_table_10_to_28[2048], &quant_table_10_to_30[2048], &quant_table_10_to_32[2048], &quant_table_10_to_34[2048], &quant_table_10_to_36[2048], &quant_table_10_to_38[2048], &quant_table_10_to_40[2048], &quant_table_10_to_42[2048], &quant_table_10_to_44[2048], &quant_table_10_to_46[2048], &quant_table_10_to_48[2048], &quant_table_10_to_50[2048], &quant_table_10_to_52[2048], &quant_table_10_to_54[2048], &quant_table_10_to_56[2048], &quant_table_10_to_58[2048], &quant_table_10_to_60[2048], &quant_table_10_to_62[2048], &quant_table_10_to_64[2048], &quant_table_10_to_72[2048], &quant_table_10_to_80[2048], &quant_table_10_to_88[2048], &quant_table_10_to_96[2048], &quant_table_10_to_104[2048], &quant_table_10_to_112[2048]}, { 0,0,0,0,0,0,0,0,0,0, &quant_table_12_to_14[2048], &quant_table_12_to_16[2048], &quant_table_12_to_18[2048], &quant_table_12_to_20[2048], &quant_table_12_to_22[2048], &quant_table_12_to_24[2048], &quant_table_12_to_26[2048], &quant_table_12_to_28[2048], &quant_table_12_to_30[2048], &quant_table_12_to_32[2048], &quant_table_12_to_34[2048], &quant_table_12_to_36[2048], &quant_table_12_to_38[2048], &quant_table_12_to_40[2048], &quant_table_12_to_42[2048], &quant_table_12_to_44[2048], &quant_table_12_to_46[2048], &quant_table_12_to_48[2048], &quant_table_12_to_50[2048], &quant_table_12_to_52[2048], &quant_table_12_to_54[2048], &quant_table_12_to_56[2048], &quant_table_12_to_58[2048], &quant_table_12_to_60[2048], &quant_table_12_to_62[2048], &quant_table_12_to_64[2048], &quant_table_12_to_72[2048], &quant_table_12_to_80[2048], &quant_table_12_to_88[2048], &quant_table_12_to_96[2048], &quant_table_12_to_104[2048], &quant_table_12_to_112[2048]}, { 0,0,0,0,0,0,0,0,0,0,0, &quant_table_14_to_16[2048], &quant_table_14_to_18[2048], &quant_table_14_to_20[2048], &quant_table_14_to_22[2048], &quant_table_14_to_24[2048], &quant_table_14_to_26[2048], &quant_table_14_to_28[2048], &quant_table_14_to_30[2048], &quant_table_14_to_32[2048], &quant_table_14_to_34[2048], &quant_table_14_to_36[2048], &quant_table_14_to_38[2048], &quant_table_14_to_40[2048], &quant_table_14_to_42[2048], &quant_table_14_to_44[2048], &quant_table_14_to_46[2048], &quant_table_14_to_48[2048], &quant_table_14_to_50[2048], &quant_table_14_to_52[2048], &quant_table_14_to_54[2048], &quant_table_14_to_56[2048], &quant_table_14_to_58[2048], &quant_table_14_to_60[2048], &quant_table_14_to_62[2048], &quant_table_14_to_64[2048], &quant_table_14_to_72[2048], &quant_table_14_to_80[2048], &quant_table_14_to_88[2048], &quant_table_14_to_96[2048], &quant_table_14_to_104[2048], &quant_table_14_to_112[2048]}, { 0,0,0,0,0,0,0,0,0,0,0,0, &quant_table_16_to_18[2048], &quant_table_16_to_20[2048], &quant_table_16_to_22[2048], &quant_table_16_to_24[2048], &quant_table_16_to_26[2048], &quant_table_16_to_28[2048], &quant_table_16_to_30[2048], &quant_table_16_to_32[2048], &quant_table_16_to_34[2048], &quant_table_16_to_36[2048], &quant_table_16_to_38[2048], &quant_table_16_to_40[2048], &quant_table_16_to_42[2048], &quant_table_16_to_44[2048], &quant_table_16_to_46[2048], &quant_table_16_to_48[2048], &quant_table_16_to_50[2048], &quant_table_16_to_52[2048], &quant_table_16_to_54[2048], &quant_table_16_to_56[2048], &quant_table_16_to_58[2048], &quant_table_16_to_60[2048], &quant_table_16_to_62[2048], &quant_table_16_to_64[2048], &quant_table_16_to_72[2048], &quant_table_16_to_80[2048], &quant_table_16_to_88[2048], &quant_table_16_to_96[2048], &quant_table_16_to_104[2048], &quant_table_16_to_112[2048]}, { 0,0,0,0,0,0,0,0,0,0,0,0,0, &quant_table_18_to_20[2048], &quant_table_18_to_22[2048], &quant_table_18_to_24[2048], &quant_table_18_to_26[2048], &quant_table_18_to_28[2048], &quant_table_18_to_30[2048], &quant_table_18_to_32[2048], &quant_table_18_to_34[2048], &quant_table_18_to_36[2048], &quant_table_18_to_38[2048], &quant_table_18_to_40[2048], &quant_table_18_to_42[2048], &quant_table_18_to_44[2048], &quant_table_18_to_46[2048], &quant_table_18_to_48[2048], &quant_table_18_to_50[2048], &quant_table_18_to_52[2048], &quant_table_18_to_54[2048], &quant_table_18_to_56[2048], &quant_table_18_to_58[2048], &quant_table_18_to_60[2048], &quant_table_18_to_62[2048], &quant_table_18_to_64[2048], &quant_table_18_to_72[2048], &quant_table_18_to_80[2048], &quant_table_18_to_88[2048], &quant_table_18_to_96[2048], &quant_table_18_to_104[2048], &quant_table_18_to_112[2048]}, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0, &quant_table_20_to_22[2048], &quant_table_20_to_24[2048], &quant_table_20_to_26[2048], &quant_table_20_to_28[2048], &quant_table_20_to_30[2048], &quant_table_20_to_32[2048], &quant_table_20_to_34[2048], &quant_table_20_to_36[2048], &quant_table_20_to_38[2048], &quant_table_20_to_40[2048], &quant_table_20_to_42[2048], &quant_table_20_to_44[2048], &quant_table_20_to_46[2048], &quant_table_20_to_48[2048], &quant_table_20_to_50[2048], &quant_table_20_to_52[2048], &quant_table_20_to_54[2048], &quant_table_20_to_56[2048], &quant_table_20_to_58[2048], &quant_table_20_to_60[2048], &quant_table_20_to_62[2048], &quant_table_20_to_64[2048], &quant_table_20_to_72[2048], &quant_table_20_to_80[2048], &quant_table_20_to_88[2048], &quant_table_20_to_96[2048], &quant_table_20_to_104[2048], &quant_table_20_to_112[2048]}, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, &quant_table_22_to_24[2048], &quant_table_22_to_26[2048], &quant_table_22_to_28[2048], &quant_table_22_to_30[2048], &quant_table_22_to_32[2048], &quant_table_22_to_34[2048], &quant_table_22_to_36[2048], &quant_table_22_to_38[2048], &quant_table_22_to_40[2048], &quant_table_22_to_42[2048], &quant_table_22_to_44[2048], &quant_table_22_to_46[2048], &quant_table_22_to_48[2048], &quant_table_22_to_50[2048], &quant_table_22_to_52[2048], &quant_table_22_to_54[2048], &quant_table_22_to_56[2048], &quant_table_22_to_58[2048], &quant_table_22_to_60[2048], &quant_table_22_to_62[2048], &quant_table_22_to_64[2048], &quant_table_22_to_72[2048], &quant_table_22_to_80[2048], &quant_table_22_to_88[2048], &quant_table_22_to_96[2048], &quant_table_22_to_104[2048], &quant_table_22_to_112[2048]}, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, &quant_table_24_to_26[2048], &quant_table_24_to_28[2048], &quant_table_24_to_30[2048], &quant_table_24_to_32[2048], &quant_table_24_to_34[2048], &quant_table_24_to_36[2048], &quant_table_24_to_38[2048], &quant_table_24_to_40[2048], &quant_table_24_to_42[2048], &quant_table_24_to_44[2048], &quant_table_24_to_46[2048], &quant_table_24_to_48[2048], &quant_table_24_to_50[2048], &quant_table_24_to_52[2048], &quant_table_24_to_54[2048], &quant_table_24_to_56[2048], &quant_table_24_to_58[2048], &quant_table_24_to_60[2048], &quant_table_24_to_62[2048], &quant_table_24_to_64[2048], &quant_table_24_to_72[2048], &quant_table_24_to_80[2048], &quant_table_24_to_88[2048], &quant_table_24_to_96[2048], &quant_table_24_to_104[2048], &quant_table_24_to_112[2048]}, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, &quant_table_26_to_28[2048], &quant_table_26_to_30[2048], &quant_table_26_to_32[2048], &quant_table_26_to_34[2048], &quant_table_26_to_36[2048], &quant_table_26_to_38[2048], &quant_table_26_to_40[2048], &quant_table_26_to_42[2048], &quant_table_26_to_44[2048], &quant_table_26_to_46[2048], &quant_table_26_to_48[2048], &quant_table_26_to_50[2048], &quant_table_26_to_52[2048], &quant_table_26_to_54[2048], &quant_table_26_to_56[2048], &quant_table_26_to_58[2048], &quant_table_26_to_60[2048], &quant_table_26_to_62[2048], &quant_table_26_to_64[2048], &quant_table_26_to_72[2048], &quant_table_26_to_80[2048], &quant_table_26_to_88[2048], &quant_table_26_to_96[2048], &quant_table_26_to_104[2048], &quant_table_26_to_112[2048]}, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, &quant_table_28_to_30[2048], &quant_table_28_to_32[2048], &quant_table_28_to_34[2048], &quant_table_28_to_36[2048], &quant_table_28_to_38[2048], &quant_table_28_to_40[2048], &quant_table_28_to_42[2048], &quant_table_28_to_44[2048], &quant_table_28_to_46[2048], &quant_table_28_to_48[2048], &quant_table_28_to_50[2048], &quant_table_28_to_52[2048], &quant_table_28_to_54[2048], &quant_table_28_to_56[2048], &quant_table_28_to_58[2048], &quant_table_28_to_60[2048], &quant_table_28_to_62[2048], &quant_table_28_to_64[2048], &quant_table_28_to_72[2048], &quant_table_28_to_80[2048], &quant_table_28_to_88[2048], &quant_table_28_to_96[2048], &quant_table_28_to_104[2048], &quant_table_28_to_112[2048]}, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, &quant_table_30_to_32[2048], &quant_table_30_to_34[2048], &quant_table_30_to_36[2048], &quant_table_30_to_38[2048], &quant_table_30_to_40[2048], &quant_table_30_to_42[2048], &quant_table_30_to_44[2048], &quant_table_30_to_46[2048], &quant_table_30_to_48[2048], &quant_table_30_to_50[2048], &quant_table_30_to_52[2048], &quant_table_30_to_54[2048], &quant_table_30_to_56[2048], &quant_table_30_to_58[2048], &quant_table_30_to_60[2048], &quant_table_30_to_62[2048], &quant_table_30_to_64[2048], &quant_table_30_to_72[2048], &quant_table_30_to_80[2048], &quant_table_30_to_88[2048], &quant_table_30_to_96[2048], &quant_table_30_to_104[2048], &quant_table_30_to_112[2048]}, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, &quant_table_32_to_34[2048], &quant_table_32_to_36[2048], &quant_table_32_to_38[2048], &quant_table_32_to_40[2048], &quant_table_32_to_42[2048], &quant_table_32_to_44[2048], &quant_table_32_to_46[2048], &quant_table_32_to_48[2048], &quant_table_32_to_50[2048], &quant_table_32_to_52[2048], &quant_table_32_to_54[2048], &quant_table_32_to_56[2048], &quant_table_32_to_58[2048], &quant_table_32_to_60[2048], &quant_table_32_to_62[2048], &quant_table_32_to_64[2048], &quant_table_32_to_72[2048], &quant_table_32_to_80[2048], &quant_table_32_to_88[2048], &quant_table_32_to_96[2048], &quant_table_32_to_104[2048], &quant_table_32_to_112[2048]}, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, &quant_table_34_to_36[2048], &quant_table_34_to_38[2048], &quant_table_34_to_40[2048], &quant_table_34_to_42[2048], &quant_table_34_to_44[2048], &quant_table_34_to_46[2048], &quant_table_34_to_48[2048], &quant_table_34_to_50[2048], &quant_table_34_to_52[2048], &quant_table_34_to_54[2048], &quant_table_34_to_56[2048], &quant_table_34_to_58[2048], &quant_table_34_to_60[2048], &quant_table_34_to_62[2048], &quant_table_34_to_64[2048], &quant_table_34_to_72[2048], &quant_table_34_to_80[2048], &quant_table_34_to_88[2048], &quant_table_34_to_96[2048], &quant_table_34_to_104[2048], &quant_table_34_to_112[2048]}, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, &quant_table_36_to_38[2048], &quant_table_36_to_40[2048], &quant_table_36_to_42[2048], &quant_table_36_to_44[2048], &quant_table_36_to_46[2048], &quant_table_36_to_48[2048], &quant_table_36_to_50[2048], &quant_table_36_to_52[2048], &quant_table_36_to_54[2048], &quant_table_36_to_56[2048], &quant_table_36_to_58[2048], &quant_table_36_to_60[2048], &quant_table_36_to_62[2048], &quant_table_36_to_64[2048], &quant_table_36_to_72[2048], &quant_table_36_to_80[2048], &quant_table_36_to_88[2048], &quant_table_36_to_96[2048], &quant_table_36_to_104[2048], &quant_table_36_to_112[2048]}, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, &quant_table_38_to_40[2048], &quant_table_38_to_42[2048], &quant_table_38_to_44[2048], &quant_table_38_to_46[2048], &quant_table_38_to_48[2048], &quant_table_38_to_50[2048], &quant_table_38_to_52[2048], &quant_table_38_to_54[2048], &quant_table_38_to_56[2048], &quant_table_38_to_58[2048], &quant_table_38_to_60[2048], &quant_table_38_to_62[2048], &quant_table_38_to_64[2048], &quant_table_38_to_72[2048], &quant_table_38_to_80[2048], &quant_table_38_to_88[2048], &quant_table_38_to_96[2048], &quant_table_38_to_104[2048], &quant_table_38_to_112[2048]}, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, &quant_table_40_to_42[2048], &quant_table_40_to_44[2048], &quant_table_40_to_46[2048], &quant_table_40_to_48[2048], &quant_table_40_to_50[2048], &quant_table_40_to_52[2048], &quant_table_40_to_54[2048], &quant_table_40_to_56[2048], &quant_table_40_to_58[2048], &quant_table_40_to_60[2048], &quant_table_40_to_62[2048], &quant_table_40_to_64[2048], &quant_table_40_to_72[2048], &quant_table_40_to_80[2048], &quant_table_40_to_88[2048], &quant_table_40_to_96[2048], &quant_table_40_to_104[2048], &quant_table_40_to_112[2048]}, { 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, &quant_table_42_to_44[2048], &quant_table_42_to_46[2048], &quant_table_42_to_48[2048], &quant_table_42_to_50[2048], &quant_table_42_to_52[2048], &quant_table_42_to_54[2048], &quant_table_42_to_56[2048], &quant_table_42_to_58[2048], &quant_table_42_to_60[2048], &quant_table_42_to_62[2048], &quant_table_42_to_64[2048], &quant_table_42_to_72[2048], &quant_table_42_to_80[2048], &quant_table_42_to_88[2048], &quant_table_42_to_96[2048], &quant_table_42_to_104[2048], &quant_table_42_to_112[2048]}, { 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, &quant_table_44_to_46[2048], &quant_table_44_to_48[2048], &quant_table_44_to_50[2048], &quant_table_44_to_52[2048], &quant_table_44_to_54[2048], &quant_table_44_to_56[2048], &quant_table_44_to_58[2048], &quant_table_44_to_60[2048], &quant_table_44_to_62[2048], &quant_table_44_to_64[2048], &quant_table_44_to_72[2048], &quant_table_44_to_80[2048], &quant_table_44_to_88[2048], &quant_table_44_to_96[2048], &quant_table_44_to_104[2048], &quant_table_44_to_112[2048]}, { 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, &quant_table_46_to_48[2048], &quant_table_46_to_50[2048], &quant_table_46_to_52[2048], &quant_table_46_to_54[2048], &quant_table_46_to_56[2048], &quant_table_46_to_58[2048], &quant_table_46_to_60[2048], &quant_table_46_to_62[2048], &quant_table_46_to_64[2048], &quant_table_46_to_72[2048], &quant_table_46_to_80[2048], &quant_table_46_to_88[2048], &quant_table_46_to_96[2048], &quant_table_46_to_104[2048], &quant_table_46_to_112[2048]}, { 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, &quant_table_48_to_50[2048], &quant_table_48_to_52[2048], &quant_table_48_to_54[2048], &quant_table_48_to_56[2048], &quant_table_48_to_58[2048], &quant_table_48_to_60[2048], &quant_table_48_to_62[2048], &quant_table_48_to_64[2048], &quant_table_48_to_72[2048], &quant_table_48_to_80[2048], &quant_table_48_to_88[2048], &quant_table_48_to_96[2048], &quant_table_48_to_104[2048], &quant_table_48_to_112[2048]}, { 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, &quant_table_50_to_52[2048], &quant_table_50_to_54[2048], &quant_table_50_to_56[2048], &quant_table_50_to_58[2048], &quant_table_50_to_60[2048], &quant_table_50_to_62[2048], &quant_table_50_to_64[2048], &quant_table_50_to_72[2048], &quant_table_50_to_80[2048], &quant_table_50_to_88[2048], &quant_table_50_to_96[2048], &quant_table_50_to_104[2048], &quant_table_50_to_112[2048]}, { 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, &quant_table_52_to_54[2048], &quant_table_52_to_56[2048], &quant_table_52_to_58[2048], &quant_table_52_to_60[2048], &quant_table_52_to_62[2048], &quant_table_52_to_64[2048], &quant_table_52_to_72[2048], &quant_table_52_to_80[2048], &quant_table_52_to_88[2048], &quant_table_52_to_96[2048], &quant_table_52_to_104[2048], &quant_table_52_to_112[2048]}, { 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, &quant_table_54_to_56[2048], &quant_table_54_to_58[2048], &quant_table_54_to_60[2048], &quant_table_54_to_62[2048], &quant_table_54_to_64[2048], &quant_table_54_to_72[2048], &quant_table_54_to_80[2048], &quant_table_54_to_88[2048], &quant_table_54_to_96[2048], &quant_table_54_to_104[2048], &quant_table_54_to_112[2048]}, { 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, &quant_table_56_to_58[2048], &quant_table_56_to_60[2048], &quant_table_56_to_62[2048], &quant_table_56_to_64[2048], &quant_table_56_to_72[2048], &quant_table_56_to_80[2048], &quant_table_56_to_88[2048], &quant_table_56_to_96[2048], &quant_table_56_to_104[2048], &quant_table_56_to_112[2048]}, { 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, &quant_table_58_to_60[2048], &quant_table_58_to_62[2048], &quant_table_58_to_64[2048], &quant_table_58_to_72[2048], &quant_table_58_to_80[2048], &quant_table_58_to_88[2048], &quant_table_58_to_96[2048], &quant_table_58_to_104[2048], &quant_table_58_to_112[2048]}, { 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, &quant_table_60_to_62[2048], &quant_table_60_to_64[2048], &quant_table_60_to_72[2048], &quant_table_60_to_80[2048], &quant_table_60_to_88[2048], &quant_table_60_to_96[2048], &quant_table_60_to_104[2048], &quant_table_60_to_112[2048]}, { 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, &quant_table_62_to_64[2048], &quant_table_62_to_72[2048], &quant_table_62_to_80[2048], &quant_table_62_to_88[2048], &quant_table_62_to_96[2048], &quant_table_62_to_104[2048], &quant_table_62_to_112[2048]}, { 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, &quant_table_64_to_72[2048], &quant_table_64_to_80[2048], &quant_table_64_to_88[2048], &quant_table_64_to_96[2048], &quant_table_64_to_104[2048], &quant_table_64_to_112[2048]}, { 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, &quant_table_72_to_80[2048], &quant_table_72_to_88[2048], &quant_table_72_to_96[2048], &quant_table_72_to_104[2048], &quant_table_72_to_112[2048]}, { 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, &quant_table_80_to_88[2048], &quant_table_80_to_96[2048], &quant_table_80_to_104[2048], &quant_table_80_to_112[2048]}, { 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, &quant_table_88_to_96[2048], &quant_table_88_to_104[2048], &quant_table_88_to_112[2048]}, { 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, &quant_table_96_to_104[2048], &quant_table_96_to_112[2048]}, { 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, &quant_table_104_to_112[2048]}, { 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} };