mirror of
https://github.com/pdewacht/brlaser
synced 2024-12-26 07:28:21 +01:00
Arrange blocks in bands of 128 lines
This is more similar to what the Brother driver does. This might fix #52, #40, etc.
This commit is contained in:
parent
e21f52f437
commit
9d7ddda838
@ -25,7 +25,6 @@
|
||||
class block {
|
||||
public:
|
||||
block(): line_bytes_(0) {
|
||||
lines_.reserve(max_lines_per_block_);
|
||||
}
|
||||
|
||||
bool empty() const {
|
||||
@ -40,8 +39,7 @@ class block {
|
||||
}
|
||||
|
||||
bool line_fits(unsigned size) {
|
||||
return lines_.size() != max_lines_per_block_
|
||||
&& line_bytes_ + size < max_block_size_;
|
||||
return line_bytes_ + size < max_block_size_;
|
||||
}
|
||||
|
||||
void flush(FILE *f) {
|
||||
@ -59,7 +57,6 @@ class block {
|
||||
|
||||
private:
|
||||
static const unsigned max_block_size_ = 16350;
|
||||
static const unsigned max_lines_per_block_ = 64;
|
||||
|
||||
std::vector<std::vector<uint8_t>> lines_;
|
||||
int line_bytes_;
|
||||
|
18
src/job.cc
18
src/job.cc
@ -109,14 +109,22 @@ void job::encode_page(const page_params &page_params,
|
||||
|
||||
fputs("\033*b1030m", out_);
|
||||
|
||||
// XXX brother driver uses 128 lines per band
|
||||
const int lines_per_band = 64;
|
||||
|
||||
for (int i = 1; i < lines && nextline(line); ++i) {
|
||||
std::vector<uint8_t> encoded = encode_line(line, reference);
|
||||
if (block.line_fits(encoded.size())) {
|
||||
block.add_line(std::move(encoded));
|
||||
} else {
|
||||
std::vector<uint8_t> encoded;
|
||||
if (i % lines_per_band == 0) {
|
||||
block.flush(out_);
|
||||
block.add_line(encode_line(line));
|
||||
encoded = encode_line(line);
|
||||
} else {
|
||||
encoded = encode_line(line, reference);
|
||||
if (!block.line_fits(encoded.size())) {
|
||||
block.flush(out_);
|
||||
encoded = encode_line(line);
|
||||
}
|
||||
}
|
||||
block.add_line(std::move(encoded));
|
||||
std::swap(line, reference);
|
||||
}
|
||||
|
||||
|
@ -37,16 +37,6 @@ const lest::test specification[] = {
|
||||
EXPECT(!b.empty());
|
||||
},
|
||||
|
||||
"A block can contain 64 lines",
|
||||
[] {
|
||||
block b;
|
||||
for (int i = 0; i < 64; ++i) {
|
||||
EXPECT(b.line_fits(1));
|
||||
b.add_line(vec(1));
|
||||
}
|
||||
EXPECT(!b.line_fits(1));
|
||||
},
|
||||
|
||||
"A block has a size limit of about 16 kilobyte",
|
||||
[] {
|
||||
block b;
|
||||
|
Loading…
Reference in New Issue
Block a user