lz4_compression.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2019 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <vector>
  6. #include "common/common_types.h"
  7. namespace Common::Compression {
  8. /**
  9. * Compresses a source memory region with LZ4 and returns the compressed data in a vector.
  10. *
  11. * @param source the uncompressed source memory region.
  12. * @param source_size the size in bytes of the uncompressed source memory region.
  13. *
  14. * @return the compressed data.
  15. */
  16. std::vector<u8> CompressDataLZ4(const u8* source, std::size_t source_size);
  17. /**
  18. * Utilizes the LZ4 subalgorithm LZ4HC with the specified compression level. Higher compression
  19. * levels result in a smaller compressed size, but require more CPU time for compression. The
  20. * compression level has almost no impact on decompression speed. Data compressed with LZ4HC can
  21. * also be decompressed with the default LZ4 decompression.
  22. *
  23. * @param source the uncompressed source memory region.
  24. * @param source_size the size in bytes of the uncompressed source memory region.
  25. * @param compression_level the used compression level. Should be between 3 and 12.
  26. *
  27. * @return the compressed data.
  28. */
  29. std::vector<u8> CompressDataLZ4HC(const u8* source, std::size_t source_size, s32 compression_level);
  30. /**
  31. * Utilizes the LZ4 subalgorithm LZ4HC with the highest possible compression level.
  32. *
  33. * @param source the uncompressed source memory region.
  34. * @param source_size the size in bytes of the uncompressed source memory region.
  35. *
  36. * @return the compressed data.
  37. */
  38. std::vector<u8> CompressDataLZ4HCMax(const u8* source, std::size_t source_size);
  39. /**
  40. * Decompresses a source memory region with LZ4 and returns the uncompressed data in a vector.
  41. *
  42. * @param compressed the compressed source memory region.
  43. * @param uncompressed_size the size in bytes of the uncompressed data.
  44. *
  45. * @return the decompressed data.
  46. */
  47. std::vector<u8> DecompressDataLZ4(const std::vector<u8>& compressed, std::size_t uncompressed_size);
  48. } // namespace Common::Compression