lz4_compression.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 <span>
  6. #include <vector>
  7. #include "common/common_types.h"
  8. namespace Common::Compression {
  9. /**
  10. * Compresses a source memory region with LZ4 and returns the compressed data in a vector.
  11. *
  12. * @param source The uncompressed source memory region.
  13. * @param source_size The size of the uncompressed source memory region.
  14. *
  15. * @return the compressed data.
  16. */
  17. [[nodiscard]] std::vector<u8> CompressDataLZ4(const u8* source, std::size_t source_size);
  18. /**
  19. * Utilizes the LZ4 subalgorithm LZ4HC with the specified compression level. Higher compression
  20. * levels result in a smaller compressed size, but require more CPU time for compression. The
  21. * compression level has almost no impact on decompression speed. Data compressed with LZ4HC can
  22. * also be decompressed with the default LZ4 decompression.
  23. *
  24. * @param source The uncompressed source memory region.
  25. * @param source_size The size of the uncompressed source memory region.
  26. * @param compression_level The used compression level. Should be between 3 and 12.
  27. *
  28. * @return the compressed data.
  29. */
  30. [[nodiscard]] std::vector<u8> CompressDataLZ4HC(const u8* source, std::size_t source_size,
  31. s32 compression_level);
  32. /**
  33. * Utilizes the LZ4 subalgorithm LZ4HC with the highest possible compression level.
  34. *
  35. * @param source The uncompressed source memory region.
  36. * @param source_size The size of the uncompressed source memory region
  37. *
  38. * @return the compressed data.
  39. */
  40. [[nodiscard]] std::vector<u8> CompressDataLZ4HCMax(const u8* source, std::size_t source_size);
  41. /**
  42. * Decompresses a source memory region with LZ4 and returns the uncompressed data in a vector.
  43. *
  44. * @param compressed the compressed source memory region.
  45. * @param uncompressed_size the size in bytes of the uncompressed data.
  46. *
  47. * @return the decompressed data.
  48. */
  49. [[nodiscard]] std::vector<u8> DecompressDataLZ4(std::span<const u8> compressed,
  50. std::size_t uncompressed_size);
  51. } // namespace Common::Compression