prevent compressor blowing up short repetitions

http-comm
Ondřej Hruška 7 years ago
parent 2e004b6048
commit bd43c4d9c3
  1. 19
      user/screen.c

@ -1371,6 +1371,7 @@ struct ScreenSerializeState {
Color lastBg; Color lastBg;
bool lastAttrs; bool lastAttrs;
char lastChar[4]; char lastChar[4];
u8 lastCharLen;
int index; int index;
}; };
@ -1456,6 +1457,7 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, void **data)
ss->lastBg = 0; ss->lastBg = 0;
ss->lastFg = 0; ss->lastFg = 0;
ss->lastAttrs = 0; ss->lastAttrs = 0;
ss->lastCharLen = 0;
memset(ss->lastChar, 0, 4); // this ensures the first char is never "repeat" memset(ss->lastChar, 0, 4); // this ensures the first char is never "repeat"
bufput_c('S'); bufput_c('S');
@ -1526,10 +1528,12 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, void **data)
// copy the symbol, until first 0 or reached 4 bytes // copy the symbol, until first 0 or reached 4 bytes
char c; char c;
ss->lastCharLen = 0;
for(int j=0; j<4; j++) { for(int j=0; j<4; j++) {
c = cell->c[j]; c = cell->c[j];
if(!c) break; if(!c) break;
bufput_c(c); bufput_c(c);
ss->lastCharLen++;
} }
ss->lastFg = cell0->fg; ss->lastFg = cell0->fg;
@ -1539,8 +1543,19 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, void **data)
i++; i++;
} else { } else {
// Repeat count // last character was repeated repCnt times
bufput_t2B('\x02', repCnt); int savings = ss->lastCharLen*repCnt;
if (savings > 3) {
// Repeat count
bufput_t2B('\x02', repCnt);
} else {
// repeat it manually
for(int k=0; k<repCnt; k++) {
for (int j = 0; j < ss->lastCharLen; j++) {
bufput_c(ss->lastChar[j]);
}
}
}
} }
} }

Loading…
Cancel
Save