home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / Asuka / source / maketables.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-14  |  2.8 KB  |  91 lines

  1. //    Asuka - VirtualDub Build/Post-Mortem Utility
  2. //    Copyright (C) 2005-2008 Avery Lee
  3. //
  4. //    This program is free software; you can redistribute it and/or modify
  5. //    it under the terms of the GNU General Public License as published by
  6. //    the Free Software Foundation; either version 2 of the License, or
  7. //    (at your option) any later version.
  8. //
  9. //    This program is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. //    GNU General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU General Public License
  15. //    along with this program; if not, write to the Free Software
  16. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #include "stdafx.h"
  19. #include <math.h>
  20. #include <vd2/system/vdtypes.h>
  21. #include <vd2/system/vdstl.h>
  22.  
  23. #include "utils.h"
  24.  
  25. void tool_maketables(const vdfastvector<const char *>& args, const vdfastvector<const char *>& switches) {
  26.     if (args.size() < 1) {
  27.         printf("usage: maketables <C++ output file>\n");
  28.         exit(5);
  29.     }
  30.  
  31.     FILE *f = fopen(args[0], "w");
  32.     if (!f)
  33.         fail("    couldn't open: %s\n", args[1]);
  34.  
  35.     fputs("// Automatically generated by Asuka 'maketables.'\" DO NOT EDIT!\n", f);
  36.     fputs("\n", f);
  37.     fputs("#include <vd2/system/vdtypes.h>\n", f);
  38.     fputs("\n", f);
  39.  
  40.     fputs("extern \"C\" const sint32 kVDCubicInterpTableFX14_075[256][4]={\n", f);
  41.     {
  42.         static const double A = -0.75;
  43.  
  44.         for(int i=0; i<256; ++i) {
  45.             double d = (double)i / 256.0f;
  46.  
  47.             double c1 = ((+      A*d -  2.0*A     )*d + A)*d;
  48.             double c3 = ((-(A+2.0)*d + (2.0*A+3.0))*d - A)*d;
  49.             double c4 = ((-      A*d +      A     )*d    )*d;
  50.  
  51.             int ic1 = (int)floor(0.5 + 16384.0 * c1);
  52.             int ic3 = (int)floor(0.5 + 16384.0 * c3);
  53.             int ic4 = (int)floor(0.5 + 16384.0 * c4);
  54.  
  55.             fprintf(f, "\t{ %6d, %6d, %6d, %6d },", ic1, 16384 - (ic1+ic3+ic4), ic3, ic4);
  56.  
  57.             if ((i&3) == 3) fputc('\n', f);
  58.         }
  59.     }
  60.     fputs("};\n", f);
  61.     fputs("\n", f);
  62.  
  63.     fputs("#ifdef _M_IX86\n", f);
  64.     fputs("extern \"C\" const __declspec(align(16)) sint16 kVDCubicInterpTableFX14_075_MMX[256][8]={\n", f);
  65.     {
  66.         static const double A = -0.75;
  67.  
  68.         for(int i=0; i<256; ++i) {
  69.             double d = (double)i / 256.0f;
  70.  
  71.             double c1 = ((+      A*d -  2.0*A     )*d + A)*d;
  72.             double c3 = ((-(A+2.0)*d + (2.0*A+3.0))*d - A)*d;
  73.             double c4 = ((-      A*d +      A     )*d    )*d;
  74.  
  75.             int ic1 = (int)floor(0.5 + 16384.0 * c1);
  76.             int ic3 = (int)floor(0.5 + 16384.0 * c3);
  77.             int ic4 = (int)floor(0.5 + 16384.0 * c4);
  78.             int ic2 = 16384 - (ic1 + ic3 + ic4);
  79.  
  80.             fprintf(f, "\t{ %6d, %6d, %6d, %6d, %6d, %6d, %6d, %6d },", ic1, ic2, ic1, ic2, ic3, ic4, ic3, ic4);
  81.  
  82.             if ((i&1) == 1) fputc('\n', f);
  83.         }
  84.     }
  85.     fputs("};\n", f);
  86.     fputs("\n", f);
  87.     fputs("#endif\n", f);
  88.  
  89.     fclose(f);
  90. }
  91.