mirror of
https://github.com/pdewacht/brlaser
synced 2024-12-28 00:08:21 +01:00
Revert "Do not use delta-encoding across block boundaries"
This reverts commit 7ed0d6f2e8
.
This was intended as a possible fix for problems with the HL-L2300D
(#4), but it didn't help. And it worsens compression.
This commit is contained in:
parent
7ed0d6f2e8
commit
41c56264a8
21
src/block.h
21
src/block.h
@ -24,38 +24,35 @@
|
|||||||
|
|
||||||
class block {
|
class block {
|
||||||
public:
|
public:
|
||||||
block(): block_size_(0) {
|
block(): line_bytes_(0) {
|
||||||
lines_.reserve(max_lines_per_block_);
|
lines_.reserve(max_lines_per_block_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool empty() const {
|
bool empty() const {
|
||||||
return block_size_ == 0;
|
return line_bytes_ == 0;
|
||||||
}
|
|
||||||
|
|
||||||
bool full() const {
|
|
||||||
return lines_.size() == max_lines_per_block_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_line(std::vector<uint8_t> &&line) {
|
void add_line(std::vector<uint8_t> &&line) {
|
||||||
assert(!line.empty());
|
assert(!line.empty());
|
||||||
assert(line_fits(line.size()));
|
assert(line_fits(line.size()));
|
||||||
block_size_ += line.size();
|
line_bytes_ += line.size();
|
||||||
lines_.emplace_back(line);
|
lines_.emplace_back(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool line_fits(unsigned line_size) const {
|
bool line_fits(unsigned size) {
|
||||||
return !full() && block_size_ + line_size < max_block_size_;
|
return lines_.size() != max_lines_per_block_
|
||||||
|
&& line_bytes_ + size < max_block_size_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void flush(FILE *f) {
|
void flush(FILE *f) {
|
||||||
if (!empty()) {
|
if (!empty()) {
|
||||||
fprintf(f, "%dw%c%c",
|
fprintf(f, "%dw%c%c",
|
||||||
block_size_ + 2, 0,
|
line_bytes_ + 2, 0,
|
||||||
static_cast<int>(lines_.size()));
|
static_cast<int>(lines_.size()));
|
||||||
for (auto &line : lines_) {
|
for (auto &line : lines_) {
|
||||||
fwrite(line.data(), 1, line.size(), f);
|
fwrite(line.data(), 1, line.size(), f);
|
||||||
}
|
}
|
||||||
block_size_ = 0;
|
line_bytes_ = 0;
|
||||||
lines_.clear();
|
lines_.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,7 +62,7 @@ class block {
|
|||||||
static const unsigned max_lines_per_block_ = 128;
|
static const unsigned max_lines_per_block_ = 128;
|
||||||
|
|
||||||
std::vector<std::vector<uint8_t>> lines_;
|
std::vector<std::vector<uint8_t>> lines_;
|
||||||
int block_size_;
|
int line_bytes_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BLOCK_H
|
#endif // BLOCK_H
|
||||||
|
29
src/job.cc
29
src/job.cc
@ -91,31 +91,24 @@ void job::encode_page(const page_params &page_params,
|
|||||||
write_page_header();
|
write_page_header();
|
||||||
}
|
}
|
||||||
|
|
||||||
fputs("\033*b1030m", out_);
|
|
||||||
|
|
||||||
std::vector<uint8_t> line(linesize);
|
std::vector<uint8_t> line(linesize);
|
||||||
std::vector<uint8_t> reference(linesize);
|
std::vector<uint8_t> reference(linesize);
|
||||||
block block;
|
block block;
|
||||||
|
|
||||||
for (int i = 0; i < lines && nextline(line); ++i) {
|
if (!nextline(line)) {
|
||||||
if (block.empty()) {
|
return;
|
||||||
// Beginning of a new block, do not apply delta-encoding.
|
}
|
||||||
block.add_line(encode_line(line));
|
block.add_line(encode_line(line));
|
||||||
} else {
|
std::swap(line, reference);
|
||||||
// In the middle of a block, try delta-encoding.
|
|
||||||
|
fputs("\033*b1030m", out_);
|
||||||
|
|
||||||
|
for (int i = 1; i < lines && nextline(line); ++i) {
|
||||||
std::vector<uint8_t> encoded = encode_line(line, reference);
|
std::vector<uint8_t> encoded = encode_line(line, reference);
|
||||||
if (block.line_fits(encoded.size())) {
|
if (!block.line_fits(encoded.size())) {
|
||||||
// Ok, there's enough room for another line.
|
block.flush(out_);
|
||||||
|
}
|
||||||
block.add_line(std::move(encoded));
|
block.add_line(std::move(encoded));
|
||||||
} else {
|
|
||||||
// Oops, the line didn't fit. Start a new block.
|
|
||||||
block.flush(out_);
|
|
||||||
block.add_line(encode_line(line));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (block.full()) {
|
|
||||||
block.flush(out_);
|
|
||||||
}
|
|
||||||
std::swap(line, reference);
|
std::swap(line, reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user