Skip to content

Commit

Permalink
Arrange blocks in bands of 128 lines
Browse files Browse the repository at this point in the history
This is more similar to what the Brother driver does. This might
fix #52, #40, etc.
  • Loading branch information
pdewacht committed Apr 20, 2020
1 parent e21f52f commit 9d7ddda
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
5 changes: 1 addition & 4 deletions src/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
class block {
public:
block(): line_bytes_(0) {
lines_.reserve(max_lines_per_block_);
}

bool empty() const {
Expand All @@ -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) {
Expand All @@ -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_;
Expand Down
18 changes: 13 additions & 5 deletions src/job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
10 changes: 0 additions & 10 deletions test/test_block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

2 comments on commit 9d7ddda

@sschoenith
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirming this fixes the print issues on some brothers like Brother HL-L2300D series as referenced in #52 . Note, I was not the submitter, but have been following and just updated to this recent build.

Thanks for all your work!

@karol-kiersnowski
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works on my Brother HL 1210-WE. Thanks

Please sign in to comment.