removed [[nodiscard]] and changed chunk binary format

This commit is contained in:
Phuntsok Drak-pa 2018-06-11 21:26:05 +02:00
parent 67a88aaf91
commit 6c3fb8b6a7
5 changed files with 22 additions and 26 deletions

View File

@ -14,7 +14,7 @@ using ustring = std::basic_string<unsigned char>;
// packing // // packing //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
[[nodiscard]] vuchar pack(const vuint16 &t_input) { vuchar pack(const vuint16 &t_input) {
return pack_n(t_input.begin(), t_input.end(), 9); return pack_n(t_input.begin(), t_input.end(), 9);
} }
@ -27,8 +27,7 @@ using ustring = std::basic_string<unsigned char>;
* \param t_n maximum size of an input value in bits \return Returns a * \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 * vector of unsigned char containing the packed values from t_input
*/ */
[[nodiscard]] vuchar vuchar pack_n(const vuint16::const_iterator t_input_begin,
pack_n(const vuint16::const_iterator t_input_begin,
const vuint16::const_iterator t_input_end, const int t_n) { const vuint16::const_iterator t_input_end, const int t_n) {
#ifdef Debug #ifdef Debug
std::printf("%d bits!\n", t_n); std::printf("%d bits!\n", t_n);
@ -87,7 +86,7 @@ pack_n(const vuint16::const_iterator t_input_begin,
return ret; return ret;
} }
[[nodiscard]] vuchar pack_16(const vuint16::const_iterator t_input_begin, vuchar pack_16(const vuint16::const_iterator t_input_begin,
const vuint16::const_iterator t_input_end) { const vuint16::const_iterator t_input_end) {
vuchar ret{}; vuchar ret{};
std::for_each(t_input_begin, t_input_end, [&](const auto value) { std::for_each(t_input_begin, t_input_end, [&](const auto value) {
@ -111,13 +110,12 @@ uint16_t mask_n(int t_nb_bits) {
return mask; return mask;
} }
[[nodiscard]] vuint16 unpack(ustring &&t_input) { vuint16 unpack(ustring &&t_input) {
return unpack_n(t_input.begin(), t_input.end(), 9); return unpack_n(t_input.begin(), t_input.end(), 9);
} }
[[nodiscard]] vuint16 unpack_n(const ustring::const_iterator t_begin, vuint16 unpack_n(const ustring::const_iterator t_begin,
const ustring::const_iterator t_end, const ustring::const_iterator t_end, const int t_n) {
const int t_n) {
int step = t_n / 8; int step = t_n / 8;
int left_shift = 0; int left_shift = 0;
int right_shift = 0; int right_shift = 0;
@ -155,7 +153,7 @@ uint16_t mask_n(int t_nb_bits) {
return ret; return ret;
} }
[[nodiscard]] vuint16 unpack_16(const ustring::const_iterator t_begin, vuint16 unpack_16(const ustring::const_iterator t_begin,
const ustring::const_iterator t_end) { const ustring::const_iterator t_end) {
vuint16 ret{}; vuint16 ret{};
for (auto it = t_begin; it < t_end; ++it) { for (auto it = t_begin; it < t_end; ++it) {

View File

@ -11,27 +11,25 @@
#include <vector> #include <vector>
/// \brief Bat-packs the input dynamically /// \brief Bat-packs the input dynamically
[[nodiscard]] std::vector<unsigned char> std::vector<unsigned char> pack(const std::vector<std::uint16_t> &);
pack(const std::vector<std::uint16_t> &);
/// \brief Packs std::uint16_t of n bits into unsigned char /// \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, pack_n(const std::vector<std::uint16_t>::const_iterator,
const std::vector<std::uint16_t>::const_iterator, const int); const std::vector<std::uint16_t>::const_iterator, const int);
/// \brief Specialization of \ref pack_n for 16bits /// \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, pack_16(const std::vector<std::uint16_t>::const_iterator,
const std::vector<std::uint16_t>::const_iterator); const std::vector<std::uint16_t>::const_iterator);
[[nodiscard]] std::vector<std::uint16_t> std::vector<std::uint16_t> unpack(std::basic_string<unsigned char> &&);
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, unpack_n(const std::basic_string<unsigned char>::const_iterator,
const std::basic_string<unsigned char>::const_iterator, const int t_n); 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, unpack_16(const std::basic_string<unsigned char>::const_iterator,
const std::basic_string<unsigned char>::const_iterator); const std::basic_string<unsigned char>::const_iterator);

View File

@ -29,7 +29,7 @@ using vvuint16 = vector<vuint16>;
* taille des chunks\n * taille des chunks\n
* \n * \n
* Un chunk est composé de la manière qui suit :\n * Un chunk est composé de la manière qui suit :\n
* - Sur deux octets sont écrit un `uint16_t` déterminant le nombre doctets * - Sur deux octets sont écrit un `uint32_t` déterminant le nombre doctets
* composant le chunk\n * composant le chunk\n
* - Sur le nombre doctets précisés par le header du chunk se trouvent les * - Sur le nombre doctets précisés par le header du chunk se trouvent les
* données compressées par lalgorithme lzw puis via bit-packing.\n * données compressées par lalgorithme 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) { void write_chunk(FILE *const t_out, const vuint16 &t_chunk) {
const auto output = pack(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(&chunk_size, sizeof(chunk_size), 1, t_out);
fwrite(output.data(), sizeof(output[0]), output.size(), t_out); fwrite(output.data(), sizeof(output[0]), output.size(), t_out);
} }

View File

@ -14,7 +14,7 @@ using std::vector;
using ustring = std::basic_string<unsigned char>; using ustring = std::basic_string<unsigned char>;
using vuint16 = vector<uint16_t>; using vuint16 = vector<uint16_t>;
[[nodiscard]] ustring lzw_uncompress(vuint16 &&t_compressed) { ustring lzw_uncompress(vuint16 &&t_compressed) {
ustring ret{}; ustring ret{};
uint16_t old = 0; uint16_t old = 0;

View File

@ -5,7 +5,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
[[nodiscard]] std::basic_string<unsigned char> std::basic_string<unsigned char>
lzw_uncompress(std::vector<std::uint16_t> &&); lzw_uncompress(std::vector<std::uint16_t> &&);
void uncompress(const std::string &, const char*); void uncompress(const std::string &, const char*);