home *** CD-ROM | disk | FTP | other *** search
/ Compressed Image File Formats / CompressedImageFileFormatsJohnMiano.iso / pc / Examples / c10 / src / jpenquan.cpp < prev   
Encoding:
C/C++ Source or Header  |  1998-12-17  |  3.0 KB  |  81 lines

  1. //
  2. // Copyright (c) 1997,1998 Colosseum Builders, Inc.
  3. // All rights reserved.
  4. //
  5. // Colosseum Builders, Inc. makes no warranty, expressed or implied
  6. // with regards to this software. It is provided as is.
  7. //
  8. // See the README.TXT file that came with this software for restrictions
  9. // on the use and redistribution of this file or send E-mail to
  10. // info@colosseumbuilders.com
  11. //
  12.  
  13. //
  14. // JPEG Encoder Library.
  15. //
  16. // Title:   EncoderQuantizationTable Class Implementation
  17. //
  18. // Author: John M. Miano  miano@colosseumbuilders.com
  19. //
  20. //
  21.  
  22. #include "jpenquan.h"
  23.  
  24. #include "jpegenco.h"
  25. #include "jpgexcep.h"
  26.  
  27. //
  28. // This table consists of the values
  29. //
  30. //   F (i, j) = X (i) X (j) / 8
  31. //
  32. // where
  33. //
  34. //  X (n) = 1, n = 0, 4
  35. //  X (n) = 1 / sqrt(2) / cos (n*PI/16)
  36. //
  37.  
  38. static const double floatscaling [JpegSampleWidth][JpegSampleWidth] =
  39. {
  40. { 0.125,                  0.09011997775086849627, 0.09567085809127244544, 0.1063037618459070632,  0.125,                  0.159094822571604233,  0.2309698831278216846, 0.4530637231764438333, },
  41. { 0.09011997775086849627, 0.0649728831185362593,  0.0689748448207357645,  0.07664074121909414394, 0.09011997775086849627, 0.1147009749634507608, 0.1665200058287998886, 0.3266407412190940884, },
  42. { 0.09567085809127244544, 0.0689748448207357645,  0.0732233047033631207,  0.08136137691302557096, 0.09567085809127244544, 0.1217659055464329343, 0.1767766952966368932, 0.3467599613305368256, },
  43. { 0.1063037618459070632,  0.07664074121909414394, 0.08136137691302557096, 0.09040391826073060355, 0.1063037618459070632,  0.135299025036549253,  0.1964237395967755595, 0.3852990250365491698, },
  44. { 0.125,                  0.09011997775086849627, 0.09567085809127244544, 0.1063037618459070632,  0.125,                  0.159094822571604233,  0.2309698831278216846, 0.4530637231764438333, },
  45. { 0.159094822571604233,   0.1147009749634507608,  0.1217659055464329343,  0.135299025036549253,   0.159094822571604233,   0.2024893005527218515, 0.2939689006048396558, 0.5766407412190940329, },
  46. { 0.2309698831278216846,  0.1665200058287998886,  0.1767766952966368932,  0.1964237395967755595,  0.2309698831278216846,  0.2939689006048396558, 0.4267766952966368654, 0.8371526015321518744, },
  47. { 0.4530637231764438333,  0.3266407412190940884,  0.3467599613305368256,  0.3852990250365491698,  0.4530637231764438333,  0.5766407412190940329, 0.8371526015321518744, 1.642133898068010689,  },
  48. } ;
  49.  
  50. //
  51. //  Description:
  52. //
  53. //    Default Class Constructor
  54. //
  55.  
  56. JpegEncoderQuantizationTable::JpegEncoderQuantizationTable ()
  57. {
  58.   memset (data_values, 0, sizeof (data_values)) ;
  59.   return ;
  60. }
  61.  
  62. //
  63. //  Description:
  64. //
  65. //    This function creates the scaled quantization tables used by the fast
  66. //    FDCT algorithm.
  67. //
  68. void JpegEncoderQuantizationTable::BuildScaledTables ()
  69. {
  70.   for (int ii = 0 ; ii < JpegSampleWidth ; ++ ii)
  71.   {
  72.     for (int jj = 0 ; jj < JpegSampleWidth ; ++ jj)
  73.     {
  74.       float_scaling [ii][jj] = floatscaling [ii][jj] /
  75.                    data_values [JpegZigZagOutputOrder (ii * JpegSampleWidth + jj)] ;
  76.     }
  77.   }
  78.   return ;
  79. }
  80.  
  81.