Skip to content

Commit 3b48dab

Browse files
committed
Modify encoding flags
1 parent 956998a commit 3b48dab

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/transform/LZCodec.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -252,21 +252,21 @@ bool LZXCodec<T>::forward(SliceArray<byte>& input, SliceArray<byte>& output, int
252252
// or 3 bits litLen + 3 bits flag + 2 bits mLen (LLLFFFMM)
253253
// LLL : <= 7 --> LLL == literal length (if 7, remainder encoded outside of token)
254254
// MMM : <= 7 --> MMM == match length (if 7, remainder encoded outside of token)
255-
// FF = 00 --> 1 byte dist
256-
// FF = 01 --> 2 byte dist
257-
// FF = 10 --> 3 byte dist
258-
// FFF = 110 --> dist == repd0
259-
// FFF = 111 --> dist == repd1
255+
// FF = 01 --> 1 byte dist
256+
// FF = 10 --> 2 byte dist
257+
// FF = 11 --> 3 byte dist
258+
// FFF = 000 --> dist == repd0
259+
// FFF = 001 --> dist == repd1
260260
const int dist = srcIdx - ref;
261261
const int mLen = bestLen - minMatch;
262262
int token, mLenTh;
263263

264264
if (dist == repd[0]) {
265-
token = 0x18;
265+
token = 0x00;
266266
mLenTh = 3;
267267
}
268268
else if (dist == repd[1]) {
269-
token = 0x1C;
269+
token = 0x04;
270270
mLenTh = 3;
271271
}
272272
else {
@@ -275,13 +275,13 @@ bool LZXCodec<T>::forward(SliceArray<byte>& input, SliceArray<byte>& output, int
275275
_mBuf[mIdx] = byte(dist >> 16);
276276
_mBuf[mIdx + 1] = byte(dist >> 8);
277277
mIdx += 2;
278-
token = 0x10;
278+
token = 0x18;
279279
}
280280
else {
281281
_mBuf[mIdx] = byte(dist >> 8);
282282
const int inc = (dist >= 256 ? 1 : 0);
283283
mIdx += inc;
284-
token = inc << 3;
284+
token = (inc + 1) << 3;
285285
}
286286

287287
_mBuf[mIdx++] = byte(dist);
@@ -465,7 +465,7 @@ bool LZXCodec<T>::inverseV6(SliceArray<byte>& input, SliceArray<byte>& output, i
465465
// Get match length and distance
466466
int mLen, dist;
467467

468-
if ((token & 0x18) == 0x18) {
468+
if ((token & 0x18) == 0) {
469469
// Repetition distance, read mLen remainder (if any) outside of token
470470
mLen = token & 0x03;
471471
mLen += (mLen == 3) ? minMatch + readLength(src, mLenIdx) : minMatch;
@@ -476,8 +476,8 @@ bool LZXCodec<T>::inverseV6(SliceArray<byte>& input, SliceArray<byte>& output, i
476476
mLen = token & 0x07;
477477
mLen += (mLen == 7) ? minMatch + readLength(src, mLenIdx) : minMatch;
478478
dist = int(src[mIdx++]);
479-
const int f2 = (token >> 4) & 1;
480-
const int f1 = f2 | ((token >> 3) & 1);
479+
const int f1 = (token >> 4) & 1;
480+
const int f2 = (token >> 3) & f1;
481481
dist = (dist << (8 * f1)) | (-f1 & int(src[mIdx]));
482482
mIdx += f1;
483483
dist = (dist << (8 * f2)) | (-f2 & int(src[mIdx]));

0 commit comments

Comments
 (0)