TABLES.CPP 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include <io.h>
  2. #include <fcntl.h>
  3. #include <math.h>
  4. #include "typedefs.h"
  5. #include "textio.h"
  6. #include "engine.h"
  7. #include "screen.h"
  8. #include "trig.h"
  9. #include "misc.h"
  10. #define kPi 3.141592654
  11. #define kAttrTitle (kColorMagenta * 16 + kColorWhite)
  12. #define kGammaLevels 16
  13. uchar gammaTable[kGammaLevels][256];
  14. long costable[kAngle360];
  15. BOOL FileSave(char *fname, void *buffer, ulong size)
  16. {
  17. int hFile, n;
  18. hFile = open(fname, O_CREAT | O_WRONLY | O_BINARY, S_IWUSR);
  19. if ( hFile == -1 )
  20. return FALSE;
  21. n = write(hFile, buffer, size);
  22. close(hFile);
  23. return n == size;
  24. }
  25. void BuildGammaTable( void )
  26. {
  27. double nGamma;
  28. double nScale;
  29. int i, j;
  30. for (i = 0; tioGauge(i, kGammaLevels); i++)
  31. {
  32. nGamma = 1.0 / (1.0 + i * 0.1);
  33. nScale = (double)255 / pow(255, nGamma);
  34. for (j = 0; j < 256; j++)
  35. {
  36. gammaTable[i][j] = pow(j, nGamma) * nScale;
  37. }
  38. }
  39. }
  40. void BuildCosTable( void )
  41. {
  42. int i;
  43. for (i = 0; tioGauge(i, kAngle90); i++)
  44. {
  45. costable[i] = cos(i * 2 * kPi / kAngle360) * (1 << 30);
  46. }
  47. }
  48. void main( void )
  49. {
  50. tioInit();
  51. tioCenterString(0, 0, tioScreenCols - 1, "Blood math table builder", kAttrTitle);
  52. tioCenterString(tioScreenRows - 1, 0, tioScreenCols - 1,
  53. "Copyright (c) 1994, 1995 Q Studios Corporation", kAttrTitle);
  54. tioWindow(1, 0, tioScreenRows - 2, tioScreenCols - 1);
  55. tioPrint("Building gamma correction table");
  56. BuildGammaTable();
  57. FileSave("gamma.dat", gammaTable, sizeof(gammaTable));
  58. tioPrint("Building cosine table");
  59. BuildCosTable();
  60. FileSave("cosine.dat", costable, kAngle90 * sizeof(costable[0]));
  61. tioTerm();
  62. }