1
0
mirror of https://github.com/pdewacht/brlaser synced 2024-12-26 07:28:21 +01:00
This commit is contained in:
Peter De Wachter 2018-01-26 23:51:10 +01:00
parent 4209526ef0
commit 39ed3c5708
3 changed files with 16 additions and 15 deletions

View File

@ -95,7 +95,7 @@ void job::encode_page(const page_params &page_params,
std::vector<uint8_t> reference(linesize);
block block;
if (!nextline(line.data())) {
if (!nextline(line)) {
return;
}
block.add_line(encode_line(line));
@ -103,7 +103,7 @@ void job::encode_page(const page_params &page_params,
fputs("\033*b1030m", out_);
for (int i = 1; i < lines && nextline(line.data()); ++i) {
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.flush(out_);

View File

@ -21,6 +21,7 @@
#include <stdint.h>
#include <stdio.h>
#include <string>
#include <vector>
struct page_params {
int num_copies;
@ -44,7 +45,7 @@ struct page_params {
class job {
public:
typedef bool (*nextline_fn)(uint8_t *buf);
typedef bool (*nextline_fn)(std::vector<uint8_t> &buf);
explicit job(FILE *out, const std::string &job_name);
~job();

View File

@ -29,26 +29,26 @@
#include "job.h"
#include "debug.h"
namespace {
cups_raster_t *ras;
volatile sig_atomic_t interrupted = 0;
void sigterm_handler(int sig) {
interrupted = 1;
}
cups_raster_t *ras;
cups_page_header2_t header;
bool next_line(uint8_t *buf) {
bool next_line(std::vector<uint8_t> &buf) {
if (interrupted) {
return false;
}
unsigned bytes = header.cupsBytesPerLine;
return cupsRasterReadPixels(ras, buf, bytes) == bytes;
return cupsRasterReadPixels(ras, buf.data(), buf.size()) == buf.size();
}
bool plain_ascii_string(const char *str) {
bool result = true;
for (; result && *str; str++) {
@ -82,7 +82,7 @@ std::string ascii_job_name(const char *job_id, const char *job_user, const char
return result;
}
page_params build_page_params() {
page_params build_page_params(const cups_page_header2_t &header) {
static const std::array<std::string, 6> sources = {{
"AUTO", "T1", "T2", "T3", "MP", "MANUAL"
}};
@ -125,12 +125,11 @@ page_params build_page_params() {
} // namespace
int main(int argc, char *argv[]) {
fprintf(stderr, "INFO: %s version %s\n", PACKAGE, VERSION);
if (argc != 6 && argc != 7) {
fprintf(stderr, "ERROR: %s job-id user title copies options [file]\n", argv[0]);
fprintf(stderr, "ERROR: rastertobrlaser job-id user title copies options [file]\n");
fprintf(stderr, "INFO: This program is a CUPS filter. It is not intended to be run manually.\n");
return 1;
}
@ -145,7 +144,7 @@ int main(int argc, char *argv[]) {
signal(SIGTERM, sigterm_handler);
signal(SIGPIPE, SIG_IGN);
int fd = 0;
int fd = STDIN_FILENO;
if (job_filename) {
fd = open(job_filename, O_RDONLY);
if (fd < 0) {
@ -163,6 +162,7 @@ int main(int argc, char *argv[]) {
int pages = 0;
{
job job(stdout, ascii_job_name(job_id, job_user, job_name));
cups_page_header2_t header;
while (!interrupted && cupsRasterReadHeader2(ras, &header)) {
if (header.cupsBitsPerPixel != 1
|| header.cupsBitsPerColor != 1
@ -176,7 +176,7 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "DEBUG: " PACKAGE ": Page header of first page\n");
dump_page_header(header);
}
job.encode_page(build_page_params(),
job.encode_page(build_page_params(header),
header.cupsHeight,
header.cupsBytesPerLine,
next_line);
@ -191,7 +191,7 @@ int main(int argc, char *argv[]) {
fflush(stdout);
if (ferror(stdout)) {
fprintf(stderr, "ERROR: " PACKAGE ": Could not write print data\n");
fprintf(stderr, "DEBUG: " PACKAGE ": Could not write print data. Most likely the CUPS backend failed.\n");
return 1;
}
return 0;