vamps-0.99.2/0000755000062500000120000000000010420363267011747 5ustar guestwheelvamps-0.99.2/COPYING0000644000062500000120000004313310370444234013004 0ustar guestwheel GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin St, 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 Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. 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 St, 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 Library General Public License instead of this License. vamps-0.99.2/INSTALL0000644000062500000120000000046010333454260012775 0ustar guestwheel1. Ensure you have libdvdread installed. V0.9.4 is known to work Ok. 2. "make" This should not produce any warnings or errors. If you run into any problem - try your best. 3. "make install" as root will copy vamps and play_cell to /usr/local/bin. Modify the Makefile for a different location. vamps-0.99.2/Makefile0000644000062500000120000000141010420121771013373 0ustar guestwheel# 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; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. SUBDIRS = vamps play_cell all install uninstall clean: @for dir in $(SUBDIRS); do \ $(MAKE) -C $$dir $@; \ done vamps-0.99.2/play_cell/0000755000062500000120000000000010420363242013704 5ustar guestwheelvamps-0.99.2/play_cell/play_cell.c0000644000062500000120000003673710420160342016030 0ustar guestwheel/* * play_cell: Read cell from a DVDs VTS program chain and write it to STDOUT. * * Should be used in connection with a tool (e.g. qVamps) * which computes the appropriate numbers. Using play_cell instead * of vamps-play_title avoids this anoying "SCR moves backward" * issue with dvdauthor when authoring streams created by vamps. * * This file is part of Vamps. * * Vamps 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; version 2 of the License. * * Vamps 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 Vamps; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * * Revision history (latest first): * * * 2006/04/15: Fixed some signed/unsigned issues which caused compiler warnings * on some platforms. No funtional changes. * 2006/02/26: Introduced support for detection of cell gaps (-g option). This * enables proper evaporation of some strangely authored DVDs. * 2006/02/10: Wanted to just add tolerance for read errors - ended up with an * almost complete re-write... * 2004/10/03: Initial. */ /*#define DEBUG*/ #define VERSION "V0.99.2" #include #include #include #include #include #include #include #include #include /* defines */ #define BUF_SECS 512 /* * the minimum time for one DVD sector: * 2048 byte = 16384 bit @10.08Mbps * -> 1.625396825396825ms = (146.2857142857143/90000)s * = ((146 + 85.71428571428571/300)/90000)s * ~= ((146 + 86/300)/90000)s */ #define SCR_MIN_FEED ((uint64_t) ((146 << 9) | 86)) /* globals */ uint8_t buf [BUF_SECS * DVD_VIDEO_LB_LEN]; int max_read_retries; int read_error_count; int ignore_read_errors; int report_cell_gaps; const char progname [] = "play_cell"; /* prototypes */ int get_int (const char *); void play_cell (const char *, int, int, int); void usage (void); void warning (const char *, ...); void fatal (const char *, ...); int main (int argc, char *const argv []) { const char *dev; int vts, pgc, i, c; static struct option long_options [] = { { "ignore-errors", 0, NULL, 'i' }, { "max-retries", 1, NULL, 'r' }, { "report-gaps", 0, NULL, 'g' }, { NULL, 0, NULL, 0 } }; opterr = 1; while ((c = getopt_long_only (argc, argv, "ir:g", long_options, NULL)) >= 0) { switch (c) { case 'i': ignore_read_errors = 1; break; case 'r': max_read_retries = get_int (optarg); break; case 'g': report_cell_gaps = 1; break; default: putc ('\n', stderr); usage (); } } if (argc - optind < 4) usage (); i = optind; dev = argv [i++]; vts = get_int (argv [i++]); pgc = get_int (argv [i++]); while (i < argc) { int cell = get_int (argv [i++]); play_cell (dev, vts, pgc, cell); } if (read_error_count) warning ("encountered a total of %d read error(s)", read_error_count); return 0; } /* get integer from string */ int get_int (const char *arg) { char *s; int rv; rv = strtol (arg, &s, 10); if (*s) { fprintf (stderr, "Bad integer value: %s\n", arg); usage (); } return rv; } static inline int dvd_read_blocks (int nav, dvd_file_t *fh, int sector, int count, uint8_t *ptr) { #ifdef DEBUG #define V 3 #define S 10 int offs; static int bad_vobu, bad_offs, nav_sector; if (nav) { nav_sector = sector; if (!(++bad_vobu % V) && --bad_offs < 0) bad_offs = S; } offs = sector - nav_sector; if (!(bad_vobu % V) && offs <= bad_offs && offs + count > bad_offs) return (bad_vobu & 1) * -1; #else nav = nav; #endif return DVDReadBlocks (fh, sector, count, ptr); } /* check if ptr points to nav pack */ static inline int is_nav_pack (uint8_t *ptr) { uint32_t start_code; start_code = (uint32_t) (ptr [0]) << 24; start_code |= (uint32_t) (ptr [1]) << 16; start_code |= (uint32_t) (ptr [2]) << 8; start_code |= (uint32_t) (ptr [3]); if (start_code != 0x000001ba) return 0; if ((ptr [4] & 0xc0) != 0x40) return 0; ptr += 14; start_code = (uint32_t) (ptr [0]) << 24; start_code |= (uint32_t) (ptr [1]) << 16; start_code |= (uint32_t) (ptr [2]) << 8; start_code |= (uint32_t) (ptr [3]); if (start_code != 0x000001bb) return 0; ptr += 24; start_code = (uint32_t) (ptr [0]) << 24; start_code |= (uint32_t) (ptr [1]) << 16; start_code |= (uint32_t) (ptr [2]) << 8; start_code |= (uint32_t) (ptr [3]); if (start_code != 0x000001bf) return 0; ptr += 986; start_code = (uint32_t) (ptr [0]) << 24; start_code |= (uint32_t) (ptr [1]) << 16; start_code |= (uint32_t) (ptr [2]) << 8; start_code |= (uint32_t) (ptr [3]); if (start_code != 0x000001bf) return 0; return 1; } static inline uint64_t extract_scr (const uint8_t *ptr) { uint64_t scr; scr = (uint64_t) (ptr [5] ) >> 1; /* 6..0 */ scr |= (uint64_t) (ptr [4] & 0x03) << 7; /* 8..7 */ scr |= (uint64_t) (ptr [4] & 0xf8) << 6; /* 13..9 */ scr |= (uint64_t) (ptr [3] ) << 14; /* 21..14 */ scr |= (uint64_t) (ptr [2] & 0x03) << 22; /* 23..22 */ scr |= (uint64_t) (ptr [2] & 0xf8) << 21; /* 28..24 */ scr |= (uint64_t) (ptr [1] ) << 29; /* 36..29 */ scr |= (uint64_t) (ptr [0] & 0x03) << 37; /* 38..37 */ scr |= (uint64_t) (ptr [0] & 0x38) << 36; /* 41..39 */ return scr; } static inline void merge_scr (uint8_t *ptr, uint64_t scr) { ptr [0] &= 0xc4; ptr [2] &= 0x04; ptr [4] &= 0x04; ptr [5] &= 0x01; ptr [5] |= (uint8_t) (scr << 1); ptr [4] |= (uint8_t) (scr >> 7) & 0x03; ptr [4] |= (uint8_t) (scr >> 6) & 0xf8; ptr [3] = (uint8_t) (scr >> 14); ptr [2] |= (uint8_t) (scr >> 22) & 0x03; ptr [2] |= (uint8_t) (scr >> 21) & 0xf8; ptr [1] = (uint8_t) (scr >> 29); ptr [0] |= (uint8_t) (scr >> 37) & 0x03; ptr [0] |= (uint8_t) (scr >> 36) & 0x38; } static inline uint64_t add_scr (uint64_t a, uint64_t b) { uint32_t ext; uint64_t bas; bas = (a >> 9) + (b >> 9); ext = (a & 0x1ff) + (b & 0x1ff); if (ext >= 300) { ext -= 300; bas++; } return (bas << 9) | ext; } static inline void insert_nav_pack (uint64_t scr, uint8_t *syshdr) { uint8_t *ptr = buf; static uint8_t nav_pack1 [] = { /* pack header: SCR=0, mux rate=10080000bps, stuffing length=0 */ 0, 0, 1, 0xba, 0x44, 0x00, 0x04, 0x00, 0x04, 0x01, 0x01, 0x89, 0xc3, 0xf8, /* system header */ 0, 0, 1, 0xbb, 0x00, 0x12, /* contents of system header filled in at run time (18 bytes) */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PES header for first private stream 2 packet */ 0, 0, 1, 0xbf, 0x03, 0xd4 }; static uint8_t nav_pack2 [] = { /* PES header for second private stream 2 packet */ 0, 0, 1, 0xbf, 0x03, 0xfa }; memcpy (ptr, nav_pack1, sizeof (nav_pack1)); merge_scr (ptr + 4, scr); memcpy (ptr + 20, syshdr, 18); ptr += sizeof (nav_pack1); memset (ptr, 0, DVD_VIDEO_LB_LEN/2 - sizeof (nav_pack1)); ptr = buf + DVD_VIDEO_LB_LEN/2; memcpy (ptr, nav_pack2, sizeof (nav_pack2)); ptr += sizeof (nav_pack2); memset (ptr, 0, DVD_VIDEO_LB_LEN/2 - sizeof (nav_pack2)); } /* * try to read a nav pack at given sector * if this fails and we are ignoring read errors, scan for next nav pack * if the end of the cell is reached * without having found another nav pack, return -1 * on success return 0 */ static inline int read_nav_pack (dvd_file_t *fh, dsi_t *dsi, unsigned sector, unsigned last_sector, uint64_t last_scr) { int i, n, offs; static uint8_t syshdr [18]; /* try max_read_retries+1 times */ for (i = 0; i <= max_read_retries; i++) { n = dvd_read_blocks (1, fh, sector, 1, buf); if (n == 1) { /* read Ok */ if (!is_nav_pack (buf)) fatal ("not a navigation pack at sector %d", sector); /* parse contained DSI pack */ navRead_DSI (dsi, buf + DSI_START_BYTE); /* sanity check */ if (sector != dsi -> dsi_gi.nv_pck_lbn) fatal ("bad DSI pack at sector %d", sector); /* save contents of system header */ memcpy (syshdr, buf + 20, sizeof (syshdr)); return 0; } } if (!ignore_read_errors) { /* write out an invalid sector to have Vamps fail */ memset (buf, 0, DVD_VIDEO_LB_LEN); fwrite (buf, DVD_VIDEO_LB_LEN, 1, stdout); fatal ("read failed for navigation pack at sector %d", sector); } warning ("read failed for navigation pack at sector %d (ignored)", sector); read_error_count++; /* scan for next nav pack */ for (offs = 1; sector + offs <= last_sector; offs++) { /* again try max_read_retries+1 times for each sector */ for (i = 0; i <= max_read_retries; i++) { n = dvd_read_blocks (0, fh, sector + offs, 1, buf); if (n == 1 && buf [14] == 0 && buf [15] == 0 && buf [16] == 1) { /* read Ok */ switch (buf [17]) { case 0xbd: case 0xbe: case 0xc0: case 0xc1: case 0xc2: case 0xc3: case 0xc4: case 0xc5: case 0xc6: case 0xc7: case 0xe0: dsi -> dsi_gi.vobu_ea = offs; break; case 0xbb: dsi -> vobu_sri.next_vobu = offs; insert_nav_pack (add_scr (last_scr, SCR_MIN_FEED), syshdr); return 0; default: ; } } } } /* reached end of cell without any nav pack found */ return -1; } static inline void insert_dummy_pack (uint64_t scr) { uint8_t *ptr = buf; static uint8_t dummy_pack [] = { /* pack header: SCR=0, mux rate=10080000bps, stuffing length=0 */ 0, 0, 1, 0xba, 0x44, 0x00, 0x04, 0x00, 0x04, 0x01, 0x01, 0x89, 0xc3, 0xf8, /* PES header for dummy video packet */ 0, 0, 1, 0xe0, 0x07, 0xec, 0x81, 0x00, 0x00 }; memcpy (ptr, dummy_pack, sizeof (dummy_pack)); merge_scr (ptr + 4, scr); ptr += sizeof (dummy_pack); memset (ptr, 0xff, DVD_VIDEO_LB_LEN - sizeof (dummy_pack)); } static inline int read_blocks (dvd_file_t *fh, int sector, int count, uint64_t last_scr) { int i, n; /* ensure, we do not read beyond the buffer size */ if (count > BUF_SECS) count = BUF_SECS; /* * try max_read_tries+2 times: * first: try to read count sectors, if that fails: * second: try to read a single sector, * if that fails (due to bad sector): * third to * max_read_retries+2: retry the sector */ for (i = 0; i < max_read_retries + 2; i++) { n = dvd_read_blocks (0, fh, sector, count, buf); if (n == count) /* this is what we want */ return n; /* set sector count to 1 for all retries */ count = 1; } /* all retries did not help */ if (!ignore_read_errors) { /* write out an invalid sector to have Vamps fail */ memset (buf, 0, DVD_VIDEO_LB_LEN); fwrite (buf, DVD_VIDEO_LB_LEN, 1, stdout); fatal ("read failed at sector %d", sector); } warning ("read failed at sector %d (ignored)", sector); read_error_count++; /* insert a dummy video pack instead of bad sector */ insert_dummy_pack (add_scr (last_scr, SCR_MIN_FEED)); return 1; } static inline void insert_private_2_pack (uint64_t scr, int cell_gap) { uint8_t *ptr = buf; static uint8_t private_2_pack [] = { /* pack header: SCR=0, mux rate=10080000bps, stuffing length=0 */ 0, 0, 1, 0xba, 0x44, 0x00, 0x04, 0x00, 0x04, 0x01, 0x01, 0x89, 0xc3, 0xf8, /* PES header for private stream 2 packet */ 0, 0, 1, 0xbf, 0x07, 0xec, /* contents of private stream 2 packet */ 'V', 'a', 'm', 'p', 's', '-', 'd', 'a', 't', 'a', '\0', 0x01, 0, 0 }; memcpy (ptr, private_2_pack, sizeof (private_2_pack)); merge_scr (ptr + 4, scr); ptr += sizeof (private_2_pack) - 2; *ptr++ = (uint8_t) (cell_gap >> 8); *ptr++ = (uint8_t) cell_gap; memset (ptr, 0, DVD_VIDEO_LB_LEN - sizeof (private_2_pack)); } void play_cell (const char *dev, int vts_num, int pgc_num, int cell) { pgc_t * pgc; dvd_reader_t *dvd_handle; ifo_handle_t *vts_handle; dvd_file_t * file_handle; uint64_t last_scr = 0; int sector, first_sector, last_sector, next_vobu = 0; /* open disc */ dvd_handle = DVDOpen (dev); if (!dvd_handle) fatal ("can't open DVD: %s", dev); /* load information for the given VTS */ vts_handle = ifoOpen (dvd_handle, vts_num); if (!vts_handle) fatal ("can't open info file for VTS %d", vts_num); /* open VTS data */ file_handle = DVDOpenFile (dvd_handle, vts_num, DVD_READ_TITLE_VOBS); if (!file_handle) fatal ("can't open VOB for VTS %d", vts_num); /* check program chain number */ if (pgc_num < 1 || pgc_num > vts_handle -> vts_pgcit -> nr_of_pgci_srp) fatal ("bad program chain: %d, VTS only has %d chains", pgc_num, vts_handle -> vts_pgcit -> nr_of_pgci_srp); pgc = vts_handle -> vts_pgcit -> pgci_srp [pgc_num - 1].pgc; /* check cell number */ if (cell < 1 || cell > pgc -> nr_of_cells) fatal ("bad cell: %d, PGC only has %d cells", cell, pgc -> nr_of_cells); first_sector = pgc -> cell_playback [cell - 1].first_sector; last_sector = pgc -> cell_playback [cell - 1].last_sector; /* loop until out of the cell */ for (sector = first_sector; next_vobu != SRI_END_OF_CELL; sector += next_vobu & 0x7fffffff) { dsi_t dsi; unsigned len; int nsectors, offs, cell_gap; /* read nav pack */ if (read_nav_pack (file_handle, &dsi, sector, last_sector, last_scr) < 0) /* * reached end of cell while scanning * for next nav pack (after read error) */ return; /* generate an MPEG2 program stream (including nav packs) */ if (fwrite (buf, DVD_VIDEO_LB_LEN, 1, stdout) != 1) fatal ("write failed: %s", strerror (errno)); last_scr = extract_scr (buf + 4); nsectors = dsi.dsi_gi.vobu_ea; next_vobu = dsi.vobu_sri.next_vobu; /* loop until all sectors of VOBU copied */ for (offs = 1; nsectors; offs += len, nsectors -= len) { /* read VOBU sectors */ len = read_blocks (file_handle, sector + offs, nsectors, last_scr); /* write VOBU sectors */ if (fwrite (buf, DVD_VIDEO_LB_LEN, len, stdout) != len) fatal ("write failed: %s", strerror (errno)); last_scr = extract_scr (buf + (len - 1) * DVD_VIDEO_LB_LEN + 4); } cell_gap = (next_vobu == SRI_END_OF_CELL ? (last_sector - sector + 1) : (next_vobu & 0x7fffffff)) - offs; if (report_cell_gaps && cell_gap) { insert_private_2_pack (last_scr, cell_gap); if (fwrite (buf, DVD_VIDEO_LB_LEN, 1, stdout) != 1) fatal ("write failed: %s", strerror (errno)); } } } void usage (void) { fputs ( "play_cell " VERSION "\n" "\n" "Usage: play_cell [-r max-read-retries] [-i] [-g] dvd-dev vts pgc cell\n" "\n" "-i: ignore read errors\n" "-g: report cell gaps to Vamps\n", stderr); exit (1); } void warning (const char *fmt, ...) { va_list ap; fprintf (stderr, "%s: Warning: ", progname); va_start (ap, fmt); vfprintf (stderr, fmt, ap); va_end (ap); putc ('\n', stderr); } void fatal (const char *fmt, ...) { va_list ap; fprintf (stderr, "%s: Fatal: ", progname); va_start (ap, fmt); vfprintf (stderr, fmt, ap); va_end (ap); putc ('\n', stderr); exit (1); } vamps-0.99.2/play_cell/Makefile0000644000062500000120000000206410420121755015347 0ustar guestwheel# This file is part of Vamps. # # Vamps 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; version 2 of the License. # # Vamps 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 Vamps; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA PREFIX ?= /usr/local CC = gcc CFLAGS ?= -pipe -O2 -fomit-frame-pointer CFLAGS += -Wall -W LDFLAGS += -s #LDFLAGS += -static LOADLIBES += -ldvdread INSTALL ?= install all: play_cell play_cell: play_cell.o install: all $(INSTALL) -d $(PREFIX)/bin $(INSTALL) -m 755 play_cell $(PREFIX)/bin uninstall: rm -f $(PREFIX)/bin/play_cell clean: rm -f play_cell play_cell.o *~ core vamps-0.99.2/vamps/0000755000062500000120000000000010420363242013066 5ustar guestwheelvamps-0.99.2/vamps/requant.c0000644000062500000120000017027710375547264014750 0ustar guestwheel// This file is part of Vamps. // // Vamps 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. // // Vamps 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 Vamps; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, 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 // Released under GPL license, see gnu.org // toggles: #define THREAD // #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 // #define USE_GLOBAL_REGISTER // assign registers to bit buffers #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 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 #ifdef THREAD #include "requant.h" #else #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); #endif 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; #ifdef DEMO if ((gopCount & 0x7F) < 10) // gop is ~ 0.5 sec, so 5 sec every ~minute (127 * 0.5 = 63.5 sec) { if (q_scale_type) return 112; else return 62; } #endif 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) { #ifdef DEMO if ((gopCount & 0x7F) < 10) { if (q_scale_type) return 112; else return 62; } #endif 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 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 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); 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] [ignored_quality_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] [ignored_quality_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 [ignored_quality_factor] inputM2Vsize input.m2v output.m2v\n\n", argv[0]);\ return -1; #else #define USAGE \ fprintf(stderr,\ "\nUsage is :\n"\ "\t%s recompression_factor [ignored_quality_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 }; #ifdef THREAD void *requant_thread (void *p) #else int main (int argc, const char * argv[]) #endif { uint8 ID, found; int64 greedyFactor, greedyFactor2; int i; #ifdef DEMO gopCount = 0; #endif #ifdef LOG_RATE_CONTROL LOG_FILE = fopen("Logfile.txt", "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 #ifndef THREAD rbuf = cbuf = orbuf = malloc(BUF_SIZE); wbuf = owbuf = malloc(BUF_SIZE); inbytecnt = outbytecnt = 0; eof = 0; #endif validPicHeader = 0; validSeqHeader = 0; validExtHeader = 0; #ifndef THREAD // argument parsing #ifdef CHANGE_BRIGHTNESS if (argc < 5) { USAGE } delta_bright = atoi(argv[4]); #else if (argc < 4) { USAGE } #endif fact_x = atof(argv[1]); sscanf(argv[3], "%lld", &orim2vsize); #endif greedyFactor = orim2vsize / 100; greedyFactor2 = orim2vsize / 50; #ifndef THREAD 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; #endif // 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; } } } #ifndef THREAD LOG("M2VRequantiser by Makira.\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 #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++; #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 || ((gopCount & 0x7F) < 10) #endif ) #endif { #ifndef THREAD // 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; } } // 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 } } } #endif // 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; } vamps-0.99.2/vamps/vamps.c0000644000062500000120000010273210420160107014360 0ustar guestwheel// Vamps - eVAporate DVD compliant Mpeg2 Program Stream // // This file is part of Vamps. // // Vamps 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; version 2 of the License. // // Vamps 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 Vamps; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // // // Revision history (latest first): // // 2006/04/15: V0.99.2: Fixed some signed/unsigned issues which caused compiler // warnings on some platforms. No funtional changes. // // 2006/02/26: V0.99.1: Introduced detection of special packets inserted by // play_cell when it encounters a cell gap. This enables // proper evaporation of some strangely authored DVDs. // // 2006/02/14: V0.99: Usage of inttypes.h. No functional changes (however, // play_cell *is* modified). // // 2005/11/06: V0.98: Updated requant module to // latest version from Metakine web site // (http://www.metakine.com/files/M2VRequantiser.tgz). // Since the new version requires the total size of the // unshrinked video elementary stream at start time, the // user *has to* supply the size of the unshrinked PS if // standard input is not redirected from a regular file. // For this purpose the PS-size (-S) option has been added. // Fixed large file support (>2GB). // Introduced preserve option (-p) on user request. If // enabled, the audio and subpicture tracks will keep their // original identifiers. This is required for full DVD // copies, i.e. including control structures, menus, etc. // // 2005/11/02: Fixed support for MPEG audio. Did never work up to now. // Added support for mere padding packets. These actually // should not occur in DVD program streams but they do. At // least mplex *does* spit out such. // // 2004/11/30: V0.97-1: Implemented injection support. This gives us *much* // more reliable results with the targeted size. The // vaporized data size now usually hits within a range of // a few thousand sectors (i.e. <~5MB) only. Don't forget // to remove the injections file with each new disk! // // 2004/11/29: V0.97: Video buffers aren't static any more. This // is needed for streams with multiple adjacent // GOPs not starting on sector boundaries. // // 2004/05/25: V0.96: Now GOPs do not necessarily need to start // on a sector boundary. This gets us rid of // "Bad sequence header code at ...". // // 2003/12/13: V0.95: No more known bugs nor any essential to-dos! // for large file support (>2GB) #define _GNU_SOURCE #define _FILE_OFFSET_BITS 64 #define VERSION "V0.99.2" #include #include #include #include #include #include #include #include #include #include // DVD sector size #define SECT_SIZE 2048 // read buffer size (4MB) #define RBUF_SIZE (0x1000*1024) // write buffer size (4MB) #define WBUF_SIZE (0x1000*1024) // initial video buffer size (1MB) #define VBUF_SIZE (1024*1024) // a lot of global data - we really should use C++... uint8_t rbuf [RBUF_SIZE]; // the PS read buffer uint8_t wbuf [WBUF_SIZE]; // the PS write buffer uint8_t *vibuf; // the video ES requant input buffer uint8_t *vobuf; // the video ES requant output buffer uint8_t *rptr = rbuf; // pointer to current char in read buf uint8_t *rhwp = rbuf; // read buffer high water pointer uint8_t *wptr = wbuf; // pointer to first unused char in wbuf uint64_t bytes_read; // total PS bytes read uint64_t bytes_written; // total PS bytes written uint64_t padding_bytes; // total padding bytes written uint64_t vin_bytes; // total unshrinked video ES bytes uint64_t vout_bytes; // total shrinked video ES bytes uint64_t ps_size; // total PS size in bytes int vbuf_size = VBUF_SIZE; // the video ES requant buffers' size int vilen; // current GOP's unshrinked vidES bytes int volen; // current GOP's shrinked vidES bytes int total_packs; // total no. PS packs int video_packs; // no. video packs in PS int skipped_video_packs; // skipped thereof int aux_packs; // no. audio and subpicture packs in PS int skipped_aux_packs; // skipped thereof int cell_gap_packs; // sectors skipped reported by play_cell int sequence_headers; // no. sequence headers (== #GOPs) int nav_packs; // no. nav packs int eof; // end of file flag uint8_t *rqt_rptr; // ptr to cur char in requant read buf uint8_t *rqt_wptr; // ptr to first unused char in rqt wbuf int rqt_rcnt; // no. bytes in requant read buffer int rqt_wcnt; // no. bytes in requant write buffer uint64_t rqt_inbytes; // total bytes fed into requantization uint64_t rqt_outbytes; // total bytes melt from requantization uint64_t rqt_visize; // calc. total unshrinked vidES bytes float rqt_fact; // video ES vaporization factor (>1) int spu_track_map [32]; // subpicture track# translation map int audio_track_map [8]; // audio track# translation map int verbose; // level of verbosity int calc_ps_vap; // calc vaporization based on PS size int preserve; // preserve audio/spu track numbers float vap_fact = 1.0f; // vaporization factor from cmd line const char *injections_file; // where to inject internal status from const char progname [] = "vamps"; // we're sucking bytes! // injections file stuff #define inject_int(v) { sizeof (v), &v, "%d" } #define inject_uint64(v) { sizeof (v), &v, "%llu" } #define N_INJECTIONS (sizeof (injections) / sizeof (*injections)) struct { int s; // variable size const void *p; // variable pointer const char *f; // printf/scanf format } injections [] = { inject_uint64 (bytes_read), inject_uint64 (bytes_written), inject_uint64 (padding_bytes), inject_uint64 (vin_bytes), inject_uint64 (vout_bytes), inject_int (total_packs), inject_int (video_packs), inject_int (skipped_video_packs), inject_int (aux_packs), inject_int (skipped_aux_packs), inject_int (cell_gap_packs), inject_int (sequence_headers), inject_int (nav_packs) }; // stuff for inter-thread com pthread_cond_t condr = PTHREAD_COND_INITIALIZER; pthread_cond_t condw = PTHREAD_COND_INITIALIZER; pthread_mutex_t mutr = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t mutw = PTHREAD_MUTEX_INITIALIZER; // prototypes void scan_track_map (int *, unsigned); void vaporize (void); void read_injections (const char *); void write_injections (const char *); void usage (void); void fatal (char *, ...); // this one lives in requant.c extern void *requant_thread (void *); int main (int argc, char *const argv []) { int c; char *s; struct stat st; pthread_t thread; static struct option long_options [] = { { "audio", 1, NULL, 'a' }, { "subpictures", 1, NULL, 's' }, { "evaporate", 1, NULL, 'e' }, { "ps-evaporate", 1, NULL, 'E' }, { "verbose", 0, NULL, 'v' }, { "inject", 1, NULL, 'i' }, { "preserve", 0, NULL, 'p' }, { "ps-size", 1, NULL, 'S' }, { NULL, 0, NULL, 0 } }; opterr = 1; while ((c = getopt_long_only (argc, argv, "a:s:e:E:vi:pS:", long_options, NULL)) >= 0) { switch (c) { case 'a': scan_track_map (audio_track_map, 8); break; case 's': scan_track_map (spu_track_map, 32); break; case 'e': calc_ps_vap = 0; vap_fact = strtof (optarg, &s); if (*s) { fprintf (stderr, "%s: Bad factor. You have to supply a floating point number, e.g. `1.5'.\n\n", optarg); usage (); } break; case 'E': calc_ps_vap = 1; vap_fact = strtof (optarg, &s); if (*s) { fprintf (stderr, "%s: Bad factor. You have to supply a floating point number, e.g. `1.5'.\n\n", optarg); usage (); } break; case 'v': verbose++; break; case 'i': injections_file = optarg; break; case 'p': preserve = 1; break; case 'S': ps_size = strtoull (optarg, &s, 10); if (*s || !ps_size) { fprintf (stderr, "%s: Bad program stream size. Please give size in bytes.\n\n", optarg); usage (); } break; default: putc ('\n', stderr); usage (); } } // read injections file - leaves variables untouched if file not present if (injections_file) read_injections (injections_file); // determine total size of input program stream if (!ps_size) { // size not given on command line if (fstat (0, &st) < 0 || !S_ISREG (st.st_mode)) { // no way out fputs ("Standard input is not a regular file and -S option not given.\n\n", stderr); usage (); } ps_size = st.st_size; } // allocate video buffers vibuf = malloc (vbuf_size); vobuf = malloc (vbuf_size); if (vibuf == NULL || vobuf == NULL) fatal ("Allocation of video buffers failed: %s", strerror (errno)); // create requantization thread if (pthread_create (&thread, NULL, requant_thread, NULL)) fatal ("pthread_create: %s", strerror (errno)); // actually do vaporization vaporize (); // save internal status for adjacent run if (injections_file) write_injections (injections_file); // print this run's statistics if wanted if (verbose >= 1) { fprintf (stderr, "Info: Total bytes read: %llu\n", bytes_read); fprintf (stderr, "Info: Total bytes written: %llu\n", bytes_written); fprintf (stderr, "Info: Total sequence headers in video stream: %d\n", sequence_headers); fprintf (stderr, "Info: Total navigation packs (system headers/PCI/DSI): %d\n", nav_packs); fprintf (stderr, "Info: Total bytes vaporized in audio and subpicture streams: %llu (%.2f%%)\n", (uint64_t) skipped_aux_packs * SECT_SIZE, (double) skipped_aux_packs / (double) (bytes_read / SECT_SIZE) * 100.0); fprintf (stderr, "Info: Total bytes vaporized in cell gaps: %llu (%.2f%%)\n", (uint64_t) cell_gap_packs * SECT_SIZE, (double) cell_gap_packs / (double) (bytes_read / SECT_SIZE) * 100.0); fprintf (stderr, "Info: Total bytes vaporized in video stream: %llu (%.2f%%)\n", (uint64_t) skipped_video_packs * SECT_SIZE, (double) skipped_video_packs / (double) (bytes_read / SECT_SIZE) * 100.0); fprintf (stderr, "Info: Total padding bytes in video stream: %llu (%.2f%%)\n", padding_bytes, (double) padding_bytes / (double) bytes_written * 100.0); fprintf (stderr, "Info: Total vaporization factor: %.3f\n", (double) bytes_read / (double) bytes_written); fprintf (stderr, "Info: Average actual video ES vaporization factor: %.3f\n", (double) vin_bytes / (double) vout_bytes); //fprintf (stderr, // "total_packs=%d, video_packs=%d, aux_packs=%d, nav_packs=%d\n", // total_packs, video_packs, aux_packs, nav_packs); } return 0; } // analyze track numbers given in cmd line ("x,y,z") void scan_track_map (int *map, unsigned ntracks) { unsigned i = 1; unsigned track; char *op = optarg; do { track = strtol (op, &op, 10) - 1; if (track >= ntracks) usage (); map [track] = i; } while (i++ <= ntracks && *op++); } // lock `size' bytes in read buffer // i.e. ensure the next `size' input bytes are available in buffer // returns nonzero on EOF static inline int lock (int size) { int avail, n; avail = rhwp - rptr; if (avail >= size) return 0; if (avail) { memcpy (rbuf, rptr, avail); rptr = rbuf; rhwp = rptr + avail; } n = read (0, rhwp, RBUF_SIZE - avail); if (n % SECT_SIZE) fatal ("Premature EOF"); rhwp += n; bytes_read += n; return !n; } // copy `size' bytes from rbuf to wbuf static inline void copy (int size) { if (!size) return; if ((wptr - wbuf) + size > WBUF_SIZE) fatal ("Write buffer overflow"); memcpy (wptr, rptr, size); rptr += size; wptr += size; } // skip `size' bytes in rbuf static inline void skip (int size) { rptr += size; } // flush wbuf static void flush (void) { int size; size = wptr - wbuf; if (!size) return; if (write (1, wbuf, size) != size) fatal ("write to stdout: %s", strerror (errno)); wptr = wbuf; bytes_written += size; } // returns no. bytes read up to where `ptr' points static inline uint64_t rtell (uint8_t *ptr) { return bytes_read - (rhwp - ptr); } // returns no. bytes written up to where `ptr' points // (including those in buffer which are not actually written yet) static inline uint64_t wtell (uint8_t *ptr) { return bytes_written + (ptr - wbuf); } // some pack header consistency checking static inline void check_pack (uint8_t *ptr) { uint32_t pack_start_code; int pack_stuffing_length; pack_start_code = (uint32_t) (ptr [0]) << 24; pack_start_code |= (uint32_t) (ptr [1]) << 16; pack_start_code |= (uint32_t) (ptr [2]) << 8; pack_start_code |= (uint32_t) (ptr [3]); if (pack_start_code != 0x000001ba) fatal ("Bad pack start code at %llu: %08lx", rtell (ptr), pack_start_code); if ((ptr [4] & 0xc0) != 0x40) fatal ("Not an MPEG2 program stream pack at %llu", rtell (ptr)); // we rely on a fixed pack header size of 14 // so better to ensure this is true pack_stuffing_length = ptr [13] & 7; if (pack_stuffing_length) fatal ("Non-zero pack stuffing length at %llu: %d\n", rtell (ptr), pack_stuffing_length); } // video packet consistency checking static inline int check_video_packet (uint8_t *ptr) { int vid_packet_length, pad_packet_length, rc = 0; uint32_t vid_packet_start_code, pad_packet_start_code, sequence_header_code; vid_packet_start_code = (uint32_t) (ptr [0]) << 24; vid_packet_start_code |= (uint32_t) (ptr [1]) << 16; vid_packet_start_code |= (uint32_t) (ptr [2]) << 8; vid_packet_start_code |= (uint32_t) (ptr [3]); if (vid_packet_start_code != 0x000001e0) fatal ("Bad video packet start code at %llu: %08lx", rtell (ptr), vid_packet_start_code); vid_packet_length = ptr [4] << 8; vid_packet_length |= ptr [5]; vid_packet_length += 6; if ((ptr [6] & 0xc0) != 0x80) fatal ("Not an MPEG2 video packet at %llu", rtell (ptr)); if (ptr [7]) { if ((ptr [7] & 0xc0) != 0xc0) fatal ("First video packet in sequence starting at %llu " "misses PTS or DTS, flags=%02x", rtell (ptr), ptr [7]); sequence_header_code = (uint32_t) (ptr [6 + 3 + ptr [8] + 0]) << 24; sequence_header_code |= (uint32_t) (ptr [6 + 3 + ptr [8] + 1]) << 16; sequence_header_code |= (uint32_t) (ptr [6 + 3 + ptr [8] + 2]) << 8; sequence_header_code |= (uint32_t) (ptr [6 + 3 + ptr [8] + 3]); if (sequence_header_code == 0x000001b3) { rc = 1; } else { //fprintf (stderr, "Start of GOP at %llu not on sector boundary\n", // rtell (ptr + 6 + 3 + ptr [8])); sequence_headers++; } } pad_packet_length = 0; if (14 + vid_packet_length < SECT_SIZE - 6) { // video packet does not fill whole sector // check for padding packet ptr += vid_packet_length; pad_packet_start_code = (uint32_t) (ptr [0]) << 24; pad_packet_start_code |= (uint32_t) (ptr [1]) << 16; pad_packet_start_code |= (uint32_t) (ptr [2]) << 8; pad_packet_start_code |= (uint32_t) (ptr [3]); if (pad_packet_start_code != 0x000001be) fatal ("Bad padding packet start code at %llu: %08lx", rtell (ptr + vid_packet_length), pad_packet_start_code); pad_packet_length = ptr [4] << 8; pad_packet_length |= ptr [5]; pad_packet_length += 6; } // length of video packet plus padding packet must always match sector size if (14 + vid_packet_length + pad_packet_length != SECT_SIZE) fatal ("Bad video packet length at %llu: %d", rtell (ptr), vid_packet_length); return rc; } // here we go // this is where we switch to the requantization thread // note that this and the requant thread never run concurrently (apart // from a very short time) so a dual CPU box does not give an advantage // returns size of evaporated GOP static inline int requant (uint8_t *dst, uint8_t *src, int n, float fact) { int rv; // this ensures for the requant thread to stop at this GOP's end memcpy (src + n, "\0\0\1", 3); pthread_mutex_lock (&mutr); rqt_rptr = src; rqt_wptr = dst; rqt_rcnt = n; rqt_wcnt = 0; rqt_fact = fact; rqt_inbytes = vin_bytes; rqt_outbytes = vout_bytes; rqt_visize = (uint64_t) ((float) ps_size * (float) vin_bytes / ((float) total_packs * (float) SECT_SIZE)); pthread_cond_signal (&condr); pthread_mutex_unlock (&mutr); // now the requant thread should be running pthread_mutex_lock (&mutw); // wait for requant thread to finish while (!rqt_wcnt) pthread_cond_wait (&condw, &mutw); rv = rqt_wcnt; pthread_mutex_unlock (&mutw); if (verbose >= 2) fprintf (stderr, "Info: Actual video ES vaporization factor: %.3f\n", (double) n / (double) rv); return rv; } // translate type of private stream 1 packet // according to the track translation maps // returns new track type (e.g. 0x80 for first AC3 audio // track in cmd line) or zero if track is not to be copied static inline int new_private_1_type (uint8_t *ptr) { int type, track, abase; type = ptr [6 + 3 + ptr [8]]; //fprintf (stderr, "type=%02x\n", type); if (type >= 0x20 && type <= 0x3f) { // subpicture track = spu_track_map [type - 0x20]; return track ? track - 1 + 0x20 : 0; } if (type >= 0x80 && type <= 0x87) { // AC3 audio abase = 0x80; } else if (type >= 0x88 && type <= 0x8f) { // DTS audio abase = 0x88; } else if (type >= 0xa0 && type <= 0xa7) { // LPCM audio abase = 0xa0; } else { fatal ("Unknown private stream 1 type at %llu: %02x", rtell (ptr), type); abase = 0; } track = audio_track_map [type - abase]; return track ? track - 1 + abase : 0; } // selectivly copy private stream 1 packs // patches track type to reflect new track // mapping unless user opted to preserve them static inline void copy_private_1 (uint8_t *ptr) { int type; type = new_private_1_type (ptr); if (type) { if (!preserve) ptr [6 + 3 + ptr [8]] = type; copy (SECT_SIZE); return; } skip (SECT_SIZE); } // translate ID of MPEG audio packet // according to the audio track translation map // returns new ID (e.g. 0xc0 for first MPEG audio // track in cmd line) or zero if track is not to be copied static inline int new_mpeg_audio_id (int id) { int track; track = audio_track_map [id - 0xc0]; return track ? track - 1 + 0xc0 : 0; } // selectivly copy MPEG audio packs // patches ID to reflect new track mapping unless user opted to preserve them static inline void copy_mpeg_audio (uint8_t *ptr) { int id; id = new_mpeg_audio_id (ptr [3]); if (id) { if (!preserve) ptr [3] = id; copy (SECT_SIZE); return; } skip (SECT_SIZE); } // process beginning of program stream up to // - but not including - first sequence header // this PS leader is NOT shrunk since the PS may not // necessarily begin at a GOP boundary (although it should?) // nevertheless the unwanted private stream 1 and MPEG audio // packs are skipped since some players could get confused otherwise static void vap_leader (void) { uint8_t *ptr; int id, data_length; while (!lock (SECT_SIZE)) { ptr = rptr; check_pack (ptr); ptr += 14; id = ptr [3]; switch (id) { case 0xe0: // video if (check_video_packet (ptr)) // sequence header return; copy (SECT_SIZE); break; case 0xbd: // private 1: audio/subpicture copy_private_1 (ptr); break; case 0xc0: case 0xc1: case 0xc2: case 0xc3: case 0xc4: case 0xc5: case 0xc6: case 0xc7: // MPEG audio copy_mpeg_audio (ptr); break; case 0xbb: // system header/private 2: PCI/DSI copy (SECT_SIZE); break; case 0xbe: // padding data_length = ptr [4] << 8; data_length |= ptr [5]; if (14 + data_length != SECT_SIZE - 6) fatal ("Bad padding packet length at %llu: %d", rtell (ptr), data_length); break; case 0xbf: // private 2 if (strcmp ((char *) (ptr + 6), "Vamps-data") != 0 || ptr [17] != 0x01) fatal ("Misplaced private stream 2 pack at %llu", rtell (ptr)); skip (SECT_SIZE); break; default: fatal ("Encountered stream ID %02x at %llu, " "probably bad MPEG2 program stream", id, rtell (ptr)); } if (wptr == wbuf + WBUF_SIZE) flush (); } eof = 1; flush (); return; } // process end of program stream // the same counts here as for the PS' beginning static void vap_trailer (int length) { uint8_t *ptr; int i, id, data_length; for (i = 0; i < length; i += SECT_SIZE) { ptr = rptr + 14; id = ptr [3]; if (id == 0xbd) { // private 1: audio/subpicture copy_private_1 (ptr); } else if (id >= 0xc0 && id <= 0xc7) { // MPEG audio copy_mpeg_audio (ptr); } else if (id == 0xbe) { // padding data_length = ptr [4] << 8; data_length |= ptr [5]; if (14 + data_length != SECT_SIZE - 6) fatal ("Bad padding packet length at %llu: %d", rtell (ptr), data_length); } else if (id == 0xbf) { // private 2 if (strcmp ((char *) (ptr + 6), "Vamps-data") != 0 || ptr [17] != 0x01) fatal ("Misplaced private stream 2 pack at %llu", rtell (ptr)); skip (SECT_SIZE); } else { copy (SECT_SIZE); } if (wptr == wbuf + WBUF_SIZE) flush (); } flush (); } // vaporization is split in two phases - this is phase 1 // PS packs are read into rbuf until a sequence header is found. // All video packs are unpacketized and the contained video ES // GOP copied to vibuf. In the same course the private stream 1 // and MPEG audio packs are inspected and the number of packs // not to be copied are counted. This is to forecast the video // vaporization factor in case the user specified a PS shrink factor. // returns GOP length in bytes static inline int vap_phase1 (void) { uint8_t *ptr, *viptr = vibuf; int seq_length, id, data_length, opt_length, seqhdr, cell_gap; for (seq_length = 0; !lock (seq_length + SECT_SIZE); seq_length += SECT_SIZE) { ptr = rptr + seq_length; check_pack (ptr); // avoid duplicate counts for sequence headers if (seq_length) total_packs++; ptr += 14; id = ptr [3]; //fprintf (stderr, "id=%02x\n", id); switch (id) { case 0xe0: // video seqhdr = check_video_packet (ptr); if (seq_length) { video_packs++; if (seqhdr) { sequence_headers++; vilen = viptr - vibuf; return seq_length; } } // copy contained video ES fragment to vibuf data_length = ptr [4] << 8; data_length |= ptr [5]; opt_length = 3 + ptr [8]; data_length -= opt_length; if ((viptr - vibuf) + data_length > vbuf_size - 3) { // reallocate video buffers int i = viptr - vibuf; // grow by another VBUF_SIZE bytes vbuf_size += VBUF_SIZE; vibuf = realloc (vibuf, vbuf_size); vobuf = realloc (vobuf, vbuf_size); if (vibuf == NULL || vobuf == NULL) fatal ("Reallocation of video buffers failed: %s", strerror (errno)); viptr = vibuf + i; } //fprintf (stderr, "data_length=%d\n", data_length); memcpy (viptr, ptr + 6 + opt_length, data_length); viptr += data_length; break; case 0xbd: // private 1: audio/subpicture aux_packs++; if (!new_private_1_type (ptr)) skipped_aux_packs++; break; case 0xc0: case 0xc1: case 0xc2: case 0xc3: case 0xc4: case 0xc5: case 0xc6: case 0xc7: // MPEG audio aux_packs++; if (!new_mpeg_audio_id (id)) skipped_aux_packs++; break; case 0xbb: // system header/private 2: PCI/DSI nav_packs++; break; case 0xbe: // padding skipped_aux_packs++; data_length = ptr [4] << 8; data_length |= ptr [5]; if (14 + data_length != SECT_SIZE - 6) fatal ("Bad padding packet length at %llu: %d", rtell (ptr), data_length); break; case 0xbf: // private 2 if (strcmp ((char *) (ptr + 6), "Vamps-data") != 0 || ptr [17] != 0x01) fatal ("Misplaced private stream 2 pack at %llu", rtell (ptr)); cell_gap = ptr [18] << 8; cell_gap |= ptr [19]; cell_gap_packs += cell_gap--; total_packs += cell_gap; bytes_read += cell_gap * SECT_SIZE; break; default: fatal ("Encountered stream ID %02x at %llu, " "probably bad MPEG2 program stream", id, rtell (ptr)); } } eof = 1; return seq_length; } // re-packetize the video ES // `ptr' points to original PES packet where to put the video data // `voptr' points to first unpacketized byte in vobuf // `avail' specifies number of bytes remaining in vobuf // returns number of ES bytes in generated PES packet static inline int gen_video_packet (uint8_t *ptr, uint8_t *voptr, int avail) { int i, header_data_length, data_length, padding_length; // if original PES holds optional data (e.g. DTS/PTS) we must keep it header_data_length = (ptr [7] & 0xc0) == 0xc0 ? ptr [8] : 0; data_length = SECT_SIZE - (14 + 6 + 3 + header_data_length); if (avail >= data_length) { // write out a full video packet (usually 2025 byte) memcpy (ptr + 6 + 3 + header_data_length, voptr, data_length); ptr [4] = (SECT_SIZE - (14 + 6)) >> 8; ptr [5] = (SECT_SIZE - (14 + 6)) & 0xff; ptr [8] = header_data_length; return data_length; } if (avail < data_length - 6) { // write a short video packet and a padding packet memcpy (ptr + 6 + 3 + header_data_length, voptr, avail); ptr [4] = (3 + header_data_length + avail) >> 8; ptr [5] = 3 + header_data_length + avail; ptr [8] = header_data_length; // generate padding packet ptr += 6 + 3 + header_data_length + avail; padding_length = data_length - (avail + 6); padding_bytes += padding_length + 6; ptr [0] = 0; ptr [1] = 0; ptr [2] = 1; ptr [3] = 0xbe; ptr [4] = padding_length >> 8; ptr [5] = padding_length; for (i = 0; i < padding_length; i++) ptr [6+i] = 0xff; return avail; } // write a padded video packet (1 to 6 padding bytes) padding_length = data_length - avail; padding_bytes += padding_length; memset (ptr + 6 + 3 + header_data_length, 0xff, padding_length); header_data_length += padding_length; memcpy (ptr + 6 + 3 + header_data_length, voptr, avail); ptr [4] = (SECT_SIZE - (14 + 6)) >> 8; ptr [5] = (SECT_SIZE - (14 + 6)) & 0xff; ptr [8] = header_data_length; return avail; } // this is phase 2 of vaporization // the shrunk video ES is re-packetized by using the source PES packets // unused PS packs are skipped // only wanted private stream 1 and MPEG audio packs are copied // all nav packs are copied static inline void vap_phase2 (int seq_length) { int i, id, avail, data_length; uint8_t *ptr, *voptr = vobuf, *vohwp = vobuf + volen; for (i = 0; i < seq_length; i += SECT_SIZE) { ptr = rptr + 14; id = ptr [3]; switch (id) { case 0xe0: // video avail = vohwp - voptr; if (avail) { // still some video output data left voptr += gen_video_packet (ptr, voptr, avail); copy (SECT_SIZE); } else { // no video output data left - skip input sector skip (SECT_SIZE); skipped_video_packs++; } break; case 0xbd: // private 1: audio/subpicture copy_private_1 (ptr); break; case 0xc0: case 0xc1: case 0xc2: case 0xc3: case 0xc4: case 0xc5: case 0xc6: case 0xc7: // MPEG audio copy_mpeg_audio (ptr); break; case 0xbb: // system header/private 2: PCI/DSI copy (SECT_SIZE); break; case 0xbe: // padding data_length = ptr [4] << 8; data_length |= ptr [5]; if (14 + data_length != SECT_SIZE - 6) fatal ("Bad padding packet length at %llu: %d", rtell (ptr), data_length); break; case 0xbf: // private 2 if (strcmp ((char *) (ptr + 6), "Vamps-data") != 0 || ptr [17] != 0x01) fatal ("Misplaced private stream 2 pack at %llu", rtell (ptr)); skip (SECT_SIZE); break; default: fatal ("Encountered stream ID %02x at %llu, " "probably bad MPEG2 program stream", id, rtell (ptr)); } if (wptr == wbuf + WBUF_SIZE) // end of write buffer reached --> flush it to disk flush (); } } // entry point from main() // the requant thread already has been started void vaporize (void) { int seq_length; float fact = vap_fact; // process PS up to but not including first sequence header vap_leader (); // just in case - maybe should spit out a warning/error here if (eof) return; total_packs++; nav_packs++; total_packs++; video_packs++; // main loop while (1) { // do phase 1 of vaporization seq_length = vap_phase1 (); if (eof) { // EOF on source PS // process packs after and including last sequence header vap_trailer (seq_length); // only exit point from main loop return; } //fprintf (stderr, "seq_length=%d\n", seq_length); if (calc_ps_vap && vap_fact > 1.0f) { // forecast video ES vaporization factor // the basic formulars look like: // vap_fact = total_packs/(restpacks+vop) // restpacks = total_packs-(video_packs+skipped_aux_packs+cell_gap_packs) // fact = (video_packs*net-(gops*net/2+10))/(vop*net-(gops*net/2+10)) // net = SECT_SIZE-(14+9) // 14: pack header size // 9: PES header size // 10: PTS+DTS size in PES header of sequence header // You are welcome to double check everything here! float vop, net; net = (float) (SECT_SIZE - (14+9)); vop = video_packs + skipped_aux_packs + cell_gap_packs - (float) total_packs * (1.0f-1.0f/vap_fact); fact = ((float) video_packs * net - ((float) sequence_headers * net/2.0f + 10.0f)) / (vop * net - ((float) sequence_headers * net/2.0f + 10.0f)); // requant seems to get stuck on factors < 1 if (fact < 1.0f) fact = 1.0f; if (verbose >= 2) fprintf (stderr, "Info: Target video ES vaporization factor: %.3f\n", fact); } vin_bytes += vilen; if (fact > 1.0f) { // do requantization volen = requant (vobuf, vibuf, vilen, fact); } else { // don't do requantization memcpy (vobuf, vibuf, vilen); volen = vilen; } vout_bytes += volen; // do phase 2 of vaporization vap_phase2 (seq_length); //fprintf (stderr, // "tot=%d, vid=%d, ps1=%d, nav=%d, sv=%d, sp1=%d, fact=%.3f\n", // total_packs, video_packs, aux_packs, nav_packs, // skipped_video_packs, skipped_aux_packs, fact); } } // inject status from previous run into internal variables void read_injections (const char *filename) { unsigned i; FILE *fp; // lack of injections file is Ok // we will create one at end of this run if ((fp = fopen (filename, "r")) == NULL) return; for (i = 0; i < N_INJECTIONS; i++) { if (fscanf (fp, injections [i].f, injections [i].p) != 1) fatal ("Bad format of injections file: %s", filename); } fclose (fp); } // save status of internal variables to disk void write_injections (const char *filename) { unsigned i; FILE *fp; if ((fp = fopen (filename, "w")) == NULL) fatal ("Failed creating injections file: %s: %s", filename, strerror (errno)); for (i = 0; i < N_INJECTIONS; i++) { switch (injections [i].s) { // case 1: // fprintf (fp, injections [i].f, *((uint8_t *) injections [i].p)); // break; // // case 2: // fprintf (fp, injections [i].f, *((uint16_t *) injections [i].p)); // break; // case 4: fprintf (fp, injections [i].f, *((uint32_t *) injections [i].p)); break; case 8: fprintf (fp, injections [i].f, *((uint64_t *) injections [i].p)); break; default: abort (); } putc ('\n', fp); } if (fclose (fp)) fatal ("Failed writing injections file: %s: %s"); } // let's hope this helps void usage (void) { fputs ( "Vamps " VERSION "\n" "\n" "Usage: vamps [--evaporate|-e factor] [--ps-evaporate|-E factor]\n" " [--audio|-a a-stream,a-stream,...]\n" " [--subpictures|-s s-stream,s-stream,...] [--verbose|-v]\n" " [--inject|-i injections-file]\n" " [--preserve|-p] [--ps-size|-S input-bytes]\n" "\n" "Vamps evaporates DVD compliant MPEG2 program streams by\n" "selectively copying audio and subpicture streams and by re-quantizing\n" "the embedded elementary video stream. The shrink factor may be either\n" "specified for the video ES only (-e) or for the full PS (-E).\n", stderr); exit (1); } // this is a *very* sophisticated kind of error handling :-) void fatal (char *fmt, ...) { va_list ap; fprintf (stderr, "%s: Fatal: ", progname); va_start (ap, fmt); vfprintf (stderr, fmt, ap); va_end (ap); putc ('\n', stderr); exit (1); } vamps-0.99.2/vamps/getvlc.h0000644000062500000120000003742410054711711014536 0ustar guestwheel /* 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} }; vamps-0.99.2/vamps/putvlc.h0000644000062500000120000002154310153162752014567 0ustar guestwheel// 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} }; vamps-0.99.2/vamps/qTable.h0000644000062500000120000017204410153162751014464 0ustar guestwheelstatic 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} }; vamps-0.99.2/vamps/requant.h0000644000062500000120000000515010375547374014742 0ustar guestwheel// vamps requantization thread interfacing // // This file is part of Vamps. // // Vamps 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. // // Vamps 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 Vamps; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include // keep gcc happy #define WRITE \ orbuf = orbuf; \ mloka1 = mloka1; \ mloka2 = mloka2; \ eof = eof; // meaningless #define MIN_WRITE 0 #define MAX_READ 0 #define MOV_READ // this is where we switch threads #define LOCK(x) \ if (unlikely ((x) > (rbuf - cbuf))) \ { \ if (likely (wbuf)) \ { \ pthread_mutex_lock (&mutw); \ rqt_wcnt = wbuf - owbuf; \ pthread_cond_signal (&condw); \ pthread_mutex_unlock (&mutw); \ } \ pthread_mutex_lock (&mutr); \ while (!rqt_rcnt) \ pthread_cond_wait (&condr, &mutr); \ cbuf = rqt_rptr; \ rbuf = cbuf; \ rbuf += rqt_rcnt + 3; \ rqt_rcnt = 0; \ owbuf = rqt_wptr; \ fact_x = rqt_fact; \ inbytecnt = rqt_inbytes; \ outbytecnt = rqt_outbytes; \ orim2vsize = rqt_visize; \ pthread_mutex_unlock (&mutr); \ wbuf = owbuf; \ } #define COPY(x) \ memcpy (wbuf, cbuf, x); \ cbuf += x; \ wbuf += x; #define SEEKR(x) cbuf += x; #define SEEKW(x) wbuf += x; // global data for inter thread com extern float rqt_fact; extern int rqt_rcnt; extern int rqt_wcnt; extern uint64_t rqt_inbytes; extern uint64_t rqt_outbytes; extern uint64_t rqt_visize; extern uint8_t *rqt_rptr; extern uint8_t *rqt_wptr; extern pthread_cond_t condr; extern pthread_cond_t condw; extern pthread_mutex_t mutr; extern pthread_mutex_t mutw; vamps-0.99.2/vamps/Makefile0000644000062500000120000000227610420121632014530 0ustar guestwheel# This file is part of Vamps. # # Vamps 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. # # Vamps 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 Vamps; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA PREFIX ?= /usr/local CC = gcc CFLAGS ?= -pipe -O3 -fomit-frame-pointer -funroll-loops \ -DHAVE_BUILTIN_EXPECT CFLAGS += -Wall LDFLAGS += -s #LDFLAGS += -static LOADLIBES += -lm -lpthread INSTALL ?= install all: vamps vamps: vamps.o requant.o requant.o: requant.h putvlc.h getvlc.h qTable.h install: all $(INSTALL) -d $(PREFIX)/bin $(INSTALL) -m 755 vamps $(PREFIX)/bin uninstall: rm -f $(PREFIX)/bin/vamps clean: rm -f vamps vamps.o requant.o *~ core