lzma_encoder_presets.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. /// \file lzma_encoder_presets.c
  4. /// \brief Encoder presets
  5. /// \note xz needs this even when only decoding is enabled.
  6. //
  7. // Author: Lasse Collin
  8. //
  9. // This file has been put into the public domain.
  10. // You can do whatever you want with this file.
  11. //
  12. ///////////////////////////////////////////////////////////////////////////////
  13. #include "common.h"
  14. extern LZMA_API(lzma_bool)
  15. lzma_lzma_preset(lzma_options_lzma *options, uint32_t preset)
  16. {
  17. const uint32_t level = preset & LZMA_PRESET_LEVEL_MASK;
  18. const uint32_t flags = preset & ~LZMA_PRESET_LEVEL_MASK;
  19. const uint32_t supported_flags = LZMA_PRESET_EXTREME;
  20. if (level > 9 || (flags & ~supported_flags))
  21. return true;
  22. options->preset_dict = NULL;
  23. options->preset_dict_size = 0;
  24. options->lc = LZMA_LC_DEFAULT;
  25. options->lp = LZMA_LP_DEFAULT;
  26. options->pb = LZMA_PB_DEFAULT;
  27. static const uint8_t dict_pow2[]
  28. = { 18, 20, 21, 22, 22, 23, 23, 24, 25, 26 };
  29. options->dict_size = UINT32_C(1) << dict_pow2[level];
  30. if (level <= 3) {
  31. options->mode = LZMA_MODE_FAST;
  32. options->mf = level == 0 ? LZMA_MF_HC3 : LZMA_MF_HC4;
  33. options->nice_len = level <= 1 ? 128 : 273;
  34. static const uint8_t depths[] = { 4, 8, 24, 48 };
  35. options->depth = depths[level];
  36. } else {
  37. options->mode = LZMA_MODE_NORMAL;
  38. options->mf = LZMA_MF_BT4;
  39. options->nice_len = level == 4 ? 16 : level == 5 ? 32 : 64;
  40. options->depth = 0;
  41. }
  42. if (flags & LZMA_PRESET_EXTREME) {
  43. options->mode = LZMA_MODE_NORMAL;
  44. options->mf = LZMA_MF_BT4;
  45. if (level == 3 || level == 5) {
  46. options->nice_len = 192;
  47. options->depth = 0;
  48. } else {
  49. options->nice_len = 273;
  50. options->depth = 512;
  51. }
  52. }
  53. return false;
  54. }