bugfix: fixed writing mask for charsize increase
This commit is contained in:
parent
8777183821
commit
5830f4225c
@ -52,12 +52,6 @@ vuchar pack_n(const vuint16::const_iterator t_input_begin,
|
|||||||
}
|
}
|
||||||
const int max_value = max(t_n); // max value held within t_n bits
|
const int max_value = max(t_n); // max value held within t_n bits
|
||||||
|
|
||||||
#ifdef Debug
|
|
||||||
std::printf("%d bits! %ld chars remaining\n", t_n,
|
|
||||||
std::distance(t_input_begin, t_input_end));
|
|
||||||
std::printf("max: %d\n", max_value);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
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;
|
||||||
@ -66,7 +60,6 @@ vuchar pack_n(const vuint16::const_iterator t_input_begin,
|
|||||||
|
|
||||||
// pour chaque élément
|
// pour chaque élément
|
||||||
for (auto it = t_input_begin; it != t_input_end; ++it) {
|
for (auto it = t_input_begin; it != t_input_end; ++it) {
|
||||||
|
|
||||||
// si on a atteint ou dépassé la valeur maximale, on change de nombre de bits
|
// si on a atteint ou dépassé la valeur maximale, on change de nombre de bits
|
||||||
if (*it >= max_value) {
|
if (*it >= max_value) {
|
||||||
// écriture du masque pour notifier à la décompression du changement de bits
|
// écriture du masque pour notifier à la décompression du changement de bits
|
||||||
@ -77,8 +70,10 @@ vuchar pack_n(const vuint16::const_iterator t_input_begin,
|
|||||||
t_res.push_back(
|
t_res.push_back(
|
||||||
static_cast<uchar>(current_char | mask));
|
static_cast<uchar>(current_char | mask));
|
||||||
bool zero_rs = (right_shift == 0);
|
bool zero_rs = (right_shift == 0);
|
||||||
right_shift -= 0;
|
|
||||||
if(right_shift < 0) {
|
right_shift -= step;
|
||||||
|
if(right_shift < 0) { // si right_shift est inférieur à zéro
|
||||||
|
// si right_shift était différent de zéro, alors extra octet
|
||||||
if (!zero_rs) {
|
if (!zero_rs) {
|
||||||
current_char = static_cast<uchar>(masks[t_n] >> (-right_shift) & 0xffu);
|
current_char = static_cast<uchar>(masks[t_n] >> (-right_shift) & 0xffu);
|
||||||
t_res.push_back(current_char);
|
t_res.push_back(current_char);
|
||||||
@ -88,6 +83,7 @@ vuchar pack_n(const vuint16::const_iterator t_input_begin,
|
|||||||
return pack_n(it, t_input_end, t_res, t_n + 1);
|
return pack_n(it, t_input_end, t_res, t_n + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// écriture normale
|
||||||
if ((left_shift += step) >= t_n) {
|
if ((left_shift += step) >= t_n) {
|
||||||
left_shift = (left_shift - t_n) + step;
|
left_shift = (left_shift - t_n) + step;
|
||||||
}
|
}
|
||||||
@ -122,13 +118,9 @@ vuchar pack_n(const vuint16::const_iterator t_input_begin,
|
|||||||
|
|
||||||
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, vuchar t_res) {
|
const vuint16::const_iterator t_input_end, vuchar t_res) {
|
||||||
#ifdef Debug
|
|
||||||
std::printf("16 bits! %ld chars remaining\n",
|
|
||||||
std::distance(t_input_begin, t_input_end));
|
|
||||||
#endif
|
|
||||||
std::for_each(t_input_begin, t_input_end, [&](const auto value) {
|
std::for_each(t_input_begin, t_input_end, [&](const auto value) {
|
||||||
t_res.push_back((value >> 8) & 0xFFu);
|
t_res.push_back(static_cast<uchar>(value >> 8 & 0xFFu));
|
||||||
t_res.push_back(value & 0xFFu);
|
t_res.push_back(static_cast<uchar>(value & 0xFFu));
|
||||||
});
|
});
|
||||||
return t_res;
|
return t_res;
|
||||||
}
|
}
|
||||||
@ -143,10 +135,6 @@ vuint16 unpack(ustring &&t_input) {
|
|||||||
|
|
||||||
vuint16 unpack_n(const ustring::const_iterator t_begin,
|
vuint16 unpack_n(const ustring::const_iterator t_begin,
|
||||||
const ustring::const_iterator t_end, vuint16 t_res, int t_n) {
|
const ustring::const_iterator t_end, vuint16 t_res, int t_n) {
|
||||||
#ifdef Debug
|
|
||||||
std::printf("Chunk! %d bits, %ld compressed chars\n", t_n,
|
|
||||||
std::distance(t_begin, t_end));
|
|
||||||
#endif
|
|
||||||
if (t_n == 16) {
|
if (t_n == 16) {
|
||||||
return unpack_16(t_begin, t_end, vector<uint16_t>());
|
return unpack_16(t_begin, t_end, vector<uint16_t>());
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,6 @@ ustring lzw_uncompress(vuint16 &&t_compressed) {
|
|||||||
for (auto it = t_compressed.begin() + 1; it != t_compressed.end(); ++it) {
|
for (auto it = t_compressed.begin() + 1; it != t_compressed.end(); ++it) {
|
||||||
v = *it;
|
v = *it;
|
||||||
const auto uncompressed{dico_uncompress(dict, v, old)};
|
const auto uncompressed{dico_uncompress(dict, v, old)};
|
||||||
#ifdef Debug
|
|
||||||
std::printf("%d = %s\n", v, uncompressed.c_str());
|
|
||||||
#endif
|
|
||||||
ret.insert(ret.end(), uncompressed.begin(), uncompressed.end());
|
ret.insert(ret.end(), uncompressed.begin(), uncompressed.end());
|
||||||
old = v;
|
old = v;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user