1
0
mirror of https://github.com/pdewacht/brlaser synced 2024-12-26 15:38:20 +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); std::vector<uint8_t> reference(linesize);
block block; block block;
if (!nextline(line.data())) { if (!nextline(line)) {
return; return;
} }
block.add_line(encode_line(line)); block.add_line(encode_line(line));
@ -103,7 +103,7 @@ void job::encode_page(const page_params &page_params,
fputs("\033*b1030m", out_); 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); std::vector<uint8_t> encoded = encode_line(line, reference);
if (!block.line_fits(encoded.size())) { if (!block.line_fits(encoded.size())) {
block.flush(out_); block.flush(out_);

View File

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

View File

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