Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
930 B

  1. //
  2. // defmisc.c
  3. //
  4. #include "deflate.h"
  5. #include <string.h>
  6. #include <stdio.h>
  7. #include <crtdbg.h>
  8. //
  9. // Fix the frequency data of the provided literal and distance trees such that no
  10. // element has a zero frequency. We must never allow the cumulative frequency of
  11. // either tree to be >= 65536, so we divide all of the frequencies by two to make
  12. // sure.
  13. //
  14. void NormaliseFrequencies(USHORT *literal_tree_freq, USHORT *dist_tree_freq)
  15. {
  16. int i;
  17. // don't allow any zero frequency items to exist
  18. // also make sure we don't overflow 65535 cumulative frequency
  19. for (i = 0; i < MAX_DIST_TREE_ELEMENTS; i++)
  20. {
  21. // avoid overflow
  22. dist_tree_freq[i] >>= 1;
  23. if (dist_tree_freq[i] == 0)
  24. dist_tree_freq[i] = 1;
  25. }
  26. for (i = 0; i < MAX_LITERAL_TREE_ELEMENTS; i++)
  27. {
  28. // avoid overflow
  29. literal_tree_freq[i] >>= 1;
  30. if (literal_tree_freq[i] == 0)
  31. literal_tree_freq[i] = 1;
  32. }
  33. }