4#ifndef _SCENEPIC_COMPRESSION_H_
5#define _SCENEPIC_COMPRESSION_H_
20 template<
typename Derived>
23 const std::uint8_t* source_buf =
24 reinterpret_cast<const std::uint8_t*
>(matrix.data());
25 auto dest_len =
sizeof(
typename Derived::Scalar) * matrix.size();
26 std::vector<std::uint8_t> deflate_bytes =
deflate(source_buf, dest_len);
27 dest_len = deflate_bytes.size();
28 deflate_bytes.resize(deflate_bytes.size() + 5);
29 std::uint32_t* rows_ptr =
30 reinterpret_cast<std::uint32_t*
>(deflate_bytes.data() + dest_len);
31 *rows_ptr =
static_cast<std::uint32_t
>(matrix.rows());
32 deflate_bytes[dest_len + 4] =
static_cast<std::uint8_t
>(matrix.cols());
41 template<
typename Derived>
44 const std::uint32_t* rows_ptr =
45 reinterpret_cast<const std::uint32_t*
>(buffer.data() + buffer.size() - 5);
46 Eigen::Index rows = *rows_ptr;
47 Eigen::Index cols = *buffer.rbegin();
48 std::vector<std::uint8_t> inflate_bytes =
inflate(
51 rows * cols *
sizeof(
typename Derived::Scalar));
52 Eigen::Map<Derived> matrix_map(
53 reinterpret_cast<typename Derived::Scalar*
>(inflate_bytes.data()),
57 Derived matrix = matrix_map;
Definition: audio_track.h:14
std::vector< std::uint8_t > compress_matrix(const Derived &matrix)
Compress a matrix.
Definition: compression.h:21
Derived decompress_matrix(const std::vector< std::uint8_t > &buffer)
Decompress a matrix compressed by the "compress" method.
Definition: compression.h:42
std::vector< std::uint8_t > deflate(const std::uint8_t *data, std::size_t data_length)
Deflate a byte array.
std::vector< std::uint8_t > inflate(const std::uint8_t *data, std::size_t source_length, std::size_t dest_length)
Inflates a byte array created by.