removed [[nodiscard]] and changed chunk binary format
This commit is contained in:
parent
67a88aaf91
commit
6c3fb8b6a7
@ -14,7 +14,7 @@ using ustring = std::basic_string<unsigned char>;
|
||||
// packing //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
[[nodiscard]] vuchar pack(const vuint16 &t_input) {
|
||||
vuchar pack(const vuint16 &t_input) {
|
||||
return pack_n(t_input.begin(), t_input.end(), 9);
|
||||
}
|
||||
|
||||
@ -27,9 +27,8 @@ using ustring = std::basic_string<unsigned char>;
|
||||
* \param t_n maximum size of an input value in bits \return Returns a
|
||||
* vector of unsigned char containing the packed values from t_input
|
||||
*/
|
||||
[[nodiscard]] vuchar
|
||||
pack_n(const vuint16::const_iterator t_input_begin,
|
||||
const vuint16::const_iterator t_input_end, const int t_n) {
|
||||
vuchar pack_n(const vuint16::const_iterator t_input_begin,
|
||||
const vuint16::const_iterator t_input_end, const int t_n) {
|
||||
#ifdef Debug
|
||||
std::printf("%d bits!\n", t_n);
|
||||
#endif
|
||||
@ -87,8 +86,8 @@ pack_n(const vuint16::const_iterator t_input_begin,
|
||||
return ret;
|
||||
}
|
||||
|
||||
[[nodiscard]] vuchar pack_16(const vuint16::const_iterator t_input_begin,
|
||||
const vuint16::const_iterator t_input_end) {
|
||||
vuchar pack_16(const vuint16::const_iterator t_input_begin,
|
||||
const vuint16::const_iterator t_input_end) {
|
||||
vuchar ret{};
|
||||
std::for_each(t_input_begin, t_input_end, [&](const auto value) {
|
||||
ret.push_back((value >> 8) & 0xFF);
|
||||
@ -102,7 +101,7 @@ pack_n(const vuint16::const_iterator t_input_begin,
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
uint16_t mask_n(int t_nb_bits) {
|
||||
if(t_nb_bits == 0) {
|
||||
if (t_nb_bits == 0) {
|
||||
return 0;
|
||||
}
|
||||
uint16_t mask = mask_n(t_nb_bits - 1);
|
||||
@ -111,13 +110,12 @@ uint16_t mask_n(int t_nb_bits) {
|
||||
return mask;
|
||||
}
|
||||
|
||||
[[nodiscard]] vuint16 unpack(ustring &&t_input) {
|
||||
vuint16 unpack(ustring &&t_input) {
|
||||
return unpack_n(t_input.begin(), t_input.end(), 9);
|
||||
}
|
||||
|
||||
[[nodiscard]] vuint16 unpack_n(const ustring::const_iterator t_begin,
|
||||
const ustring::const_iterator t_end,
|
||||
const int t_n) {
|
||||
vuint16 unpack_n(const ustring::const_iterator t_begin,
|
||||
const ustring::const_iterator t_end, const int t_n) {
|
||||
int step = t_n / 8;
|
||||
int left_shift = 0;
|
||||
int right_shift = 0;
|
||||
@ -143,7 +141,7 @@ uint16_t mask_n(int t_nb_bits) {
|
||||
current_char |= *(++it) >> right_shift;
|
||||
// char made!
|
||||
ret.push_back(current_char &= mask);
|
||||
if(right_shift == 0) {
|
||||
if (right_shift == 0) {
|
||||
++it;
|
||||
}
|
||||
if (current_char >= max_value) {
|
||||
@ -155,8 +153,8 @@ uint16_t mask_n(int t_nb_bits) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
[[nodiscard]] vuint16 unpack_16(const ustring::const_iterator t_begin,
|
||||
const ustring::const_iterator t_end) {
|
||||
vuint16 unpack_16(const ustring::const_iterator t_begin,
|
||||
const ustring::const_iterator t_end) {
|
||||
vuint16 ret{};
|
||||
for (auto it = t_begin; it < t_end; ++it) {
|
||||
ret.push_back(static_cast<uint16_t>((*it << 8) | *(++it)));
|
||||
|
@ -11,27 +11,25 @@
|
||||
#include <vector>
|
||||
|
||||
/// \brief Bat-packs the input dynamically
|
||||
[[nodiscard]] std::vector<unsigned char>
|
||||
pack(const std::vector<std::uint16_t> &);
|
||||
std::vector<unsigned char> pack(const std::vector<std::uint16_t> &);
|
||||
|
||||
/// \brief Packs std::uint16_t of n bits into unsigned char
|
||||
[[nodiscard]] std::vector<unsigned char>
|
||||
std::vector<unsigned char>
|
||||
pack_n(const std::vector<std::uint16_t>::const_iterator,
|
||||
const std::vector<std::uint16_t>::const_iterator, const int);
|
||||
|
||||
/// \brief Specialization of \ref pack_n for 16bits
|
||||
[[nodiscard]] std::vector<unsigned char>
|
||||
std::vector<unsigned char>
|
||||
pack_16(const std::vector<std::uint16_t>::const_iterator,
|
||||
const std::vector<std::uint16_t>::const_iterator);
|
||||
|
||||
[[nodiscard]] std::vector<std::uint16_t>
|
||||
unpack(std::basic_string<unsigned char> &&);
|
||||
std::vector<std::uint16_t> unpack(std::basic_string<unsigned char> &&);
|
||||
|
||||
[[nodiscard]] std::vector<std::uint16_t>
|
||||
std::vector<std::uint16_t>
|
||||
unpack_n(const std::basic_string<unsigned char>::const_iterator,
|
||||
const std::basic_string<unsigned char>::const_iterator, const int t_n);
|
||||
|
||||
[[nodiscard]] std::vector<std::uint16_t>
|
||||
std::vector<std::uint16_t>
|
||||
unpack_16(const std::basic_string<unsigned char>::const_iterator,
|
||||
const std::basic_string<unsigned char>::const_iterator);
|
||||
|
||||
|
@ -29,7 +29,7 @@ using vvuint16 = vector<vuint16>;
|
||||
* taille des chunks\n
|
||||
* \n
|
||||
* Un chunk est composé de la manière qui suit :\n
|
||||
* - Sur deux octets sont écrit un `uint16_t` déterminant le nombre d’octets
|
||||
* - Sur deux octets sont écrit un `uint32_t` déterminant le nombre d’octets
|
||||
* composant le chunk\n
|
||||
* - Sur le nombre d’octets précisés par le header du chunk se trouvent les
|
||||
* données compressées par l’algorithme lzw puis via bit-packing.\n
|
||||
@ -59,7 +59,7 @@ void write_file(FILE *const t_out, const vvuint16 &t_text) {
|
||||
*/
|
||||
void write_chunk(FILE *const t_out, const vuint16 &t_chunk) {
|
||||
const auto output = pack(t_chunk);
|
||||
const auto chunk_size = static_cast<uint16_t>(output.size());
|
||||
const auto chunk_size = static_cast<uint32_t>(output.size());
|
||||
fwrite(&chunk_size, sizeof(chunk_size), 1, t_out);
|
||||
fwrite(output.data(), sizeof(output[0]), output.size(), t_out);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ using std::vector;
|
||||
using ustring = std::basic_string<unsigned char>;
|
||||
using vuint16 = vector<uint16_t>;
|
||||
|
||||
[[nodiscard]] ustring lzw_uncompress(vuint16 &&t_compressed) {
|
||||
ustring lzw_uncompress(vuint16 &&t_compressed) {
|
||||
ustring ret{};
|
||||
uint16_t old = 0;
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
[[nodiscard]] std::basic_string<unsigned char>
|
||||
std::basic_string<unsigned char>
|
||||
lzw_uncompress(std::vector<std::uint16_t> &&);
|
||||
|
||||
void uncompress(const std::string &, const char*);
|
||||
|
Loading…
Reference in New Issue
Block a user