mitsu70x: Move full image procesisng pipeline into read_parse

No need to call main_loop to validate the full flow
This commit is contained in:
Solomon Peachy 2024-01-11 21:34:55 -05:00
parent 69344f821a
commit 81193f9675
1 changed files with 134 additions and 137 deletions

View File

@ -1,7 +1,7 @@
/*
* Mitsubishi CP-D70/D707 Photo Printer CUPS backend
*
* (c) 2013-2023 Solomon Peachy <pizza@shaftnet.org>
* (c) 2013-2024 Solomon Peachy <pizza@shaftnet.org>
*
* The latest version of this program can be found at:
*
@ -1108,55 +1108,53 @@ repeat:
job->datalen += i;
remain -= i;
}
goto bypass_raw;
}
} else { /* Non-RAW mode! */
remain = job->rows * job->cols * 3;
DEBUG("Reading in %d bytes of 8bpp BGR data\n", remain);
/* Non-RAW mode! */
remain = job->rows * job->cols * 3;
DEBUG("Reading in %d bytes of 8bpp BGR data\n", remain);
job->spoolbuflen = 0;
job->spoolbuf = malloc(remain);
if (!job->spoolbuf) {
ERROR("Memory allocation failure!\n");
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_RETRY_CURRENT;
}
job->spoolbuflen = 0;
job->spoolbuf = malloc(remain);
if (!job->spoolbuf) {
ERROR("Memory allocation failure!\n");
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_RETRY_CURRENT;
}
/* Read in the BGR data */
while (remain) {
i = read(data_fd, job->spoolbuf + job->spoolbuflen, remain);
if (i == 0) {
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
if (i < 0) {
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
job->spoolbuflen += i;
remain -= i;
}
/* Read in the BGR data */
while (remain) {
i = read(data_fd, job->spoolbuf + job->spoolbuflen, remain);
if (i == 0) {
if (!ctx->lib.dl_handle) {
ERROR("!!! Image Processing Library not found, aborting!\n");
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
if (i < 0) {
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
job->spoolbuflen += i;
remain -= i;
}
if (!ctx->lib.dl_handle) {
ERROR("!!! Image Processing Library not found, aborting!\n");
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
/* Run through basic LUT, if present and enabled */
if (job->lutfname) {
int ret = mitsu_apply3dlut_packed(&ctx->lib, job->lutfname,
job->spoolbuf, job->cols,
job->rows, job->cols * 3,
COLORCONV_BGR);
if (ret) {
mitsu70x_cleanup_job(job);
return ret;
/* Run through basic LUT, if present and enabled */
if (job->lutfname) {
int ret = mitsu_apply3dlut_packed(&ctx->lib, job->lutfname,
job->spoolbuf, job->cols,
job->rows, job->cols * 3,
COLORCONV_BGR);
if (ret) {
mitsu70x_cleanup_job(job);
return ret;
}
}
}
bypass_raw:
/* Validate size and deck placement */
for (i = 0 ; i < ctx->num_decks ; i++) {
switch (ctx->medias[i]) {
case 0x0: // 4x8 (DS480 only)
@ -1241,6 +1239,101 @@ bypass_raw:
}
}
/* Process RGB data if needed */
if (!job->raw_format) {
struct BandImage input;
uint8_t rew[2] = { 1, 1 }; /* 1 for rewind ok (default!) */
/* Load in the CPC file, if needed */
if (job->cpcfname && job->cpcfname != ctx->last_cpcfname) {
char full[2048];
ctx->last_cpcfname = job->cpcfname;
if (ctx->lib.cpcdata)
ctx->lib.DestroyCPCData(ctx->lib.cpcdata);
snprintf(full, sizeof(full), "%s/%s", corrtable_path, job->cpcfname);
ctx->lib.cpcdata = ctx->lib.GetCPCData(full);
if (!ctx->lib.cpcdata) {
ERROR("Unable to load CPC file '%s'\n", full);
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
}
/* Load in the secondary CPC, if needed */
if (job->ecpcfname != ctx->last_ecpcfname) {
char full[2048];
ctx->last_ecpcfname = job->ecpcfname;
if (ctx->lib.ecpcdata)
ctx->lib.DestroyCPCData(ctx->lib.ecpcdata);
snprintf(full, sizeof(full), "%s/%s", corrtable_path, job->ecpcfname);
if (job->ecpcfname) {
ctx->lib.ecpcdata = ctx->lib.GetCPCData(full);
if (!ctx->lib.ecpcdata) {
ERROR("Unable to load CPC file '%s'\n", full);
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
} else {
ctx->lib.ecpcdata = NULL;
}
}
/* Convert using image processing library */
input.origin_rows = input.origin_cols = 0;
input.rows = job->rows;
input.cols = job->cols;
input.imgbuf = job->spoolbuf;
input.bytes_per_row = job->cols * 3;
ctx->output.origin_rows = ctx->output.origin_cols = 0;
ctx->output.rows = job->rows;
ctx->output.cols = job->cols;
ctx->output.imgbuf = job->databuf + job->datalen;
ctx->output.bytes_per_row = job->cols * 3 * 2;
DEBUG("Running print data through processing library\n");
if (ctx->lib.DoImageEffect(ctx->lib.cpcdata, ctx->lib.ecpcdata,
&input, &ctx->output, job->sharpen, job->reverse, rew)) {
ERROR("Image Processing failed, aborting!\n");
mitsu70x_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
/* Twiddle rewind stuff if needed */
if (ctx->conn->type != P_MITSU_D70X) {
mhdr.rewind[0] = !rew[0];
mhdr.rewind[1] = !rew[1];
DEBUG("Rewind Inhibit? %02x %02x\n", mhdr.rewind[0], mhdr.rewind[1]);
}
/* Move up the pointer to after the image data */
job->datalen += 3*job->planelen;
/* Clean up */
free(job->spoolbuf);
job->spoolbuf = NULL;
job->spoolbuflen = 0;
/* Now that we've filled everything in, read matte from file */
if (job->matte) {
int ret = mitsu_readlamdata(job->laminatefname, LAMINATE_STRIDE,
job->databuf, &job->datalen,
be16_to_cpu(mhdr.lamrows), be16_to_cpu(mhdr.lamcols), 2);
if (ret) {
mitsu70x_cleanup_job(job);
return ret;
}
/* Zero out the tail end of the buffer. */
ret = be16_to_cpu(mhdr.lamcols) * be16_to_cpu(mhdr.lamrows) * 2;
memset(job->databuf + job->datalen, 0, job->matte - ret);
}
}
/* Return what we found */
*vjob = job;
@ -1781,101 +1874,6 @@ static int mitsu70x_main_loop(void *vctx, const void *vjob, int wait_for_return)
/* Keep track of deck requested */
reqdeck = hdr->deck;
if (job->raw_format)
goto bypass;
struct BandImage input;
uint8_t rew[2] = { 1, 1 }; /* 1 for rewind ok (default!) */
/* Load in the CPC file, if needed */
if (job->cpcfname && job->cpcfname != ctx->last_cpcfname) {
char full[2048];
ctx->last_cpcfname = job->cpcfname;
if (ctx->lib.cpcdata)
ctx->lib.DestroyCPCData(ctx->lib.cpcdata);
snprintf(full, sizeof(full), "%s/%s", corrtable_path, job->cpcfname);
ctx->lib.cpcdata = ctx->lib.GetCPCData(full);
if (!ctx->lib.cpcdata) {
ERROR("Unable to load CPC file '%s'\n", full);
return CUPS_BACKEND_CANCEL;
}
}
/* Load in the secondary CPC, if needed */
if (job->ecpcfname != ctx->last_ecpcfname) {
char full[2048];
ctx->last_ecpcfname = job->ecpcfname;
if (ctx->lib.ecpcdata)
ctx->lib.DestroyCPCData(ctx->lib.ecpcdata);
snprintf(full, sizeof(full), "%s/%s", corrtable_path, job->ecpcfname);
if (job->ecpcfname) {
ctx->lib.ecpcdata = ctx->lib.GetCPCData(full);
if (!ctx->lib.ecpcdata) {
ERROR("Unable to load CPC file '%s'\n", full);
return CUPS_BACKEND_CANCEL;
}
} else {
ctx->lib.ecpcdata = NULL;
}
}
/* Convert using image processing library */
input.origin_rows = input.origin_cols = 0;
input.rows = job->rows;
input.cols = job->cols;
input.imgbuf = job->spoolbuf;
input.bytes_per_row = job->cols * 3;
ctx->output.origin_rows = ctx->output.origin_cols = 0;
ctx->output.rows = job->rows;
ctx->output.cols = job->cols;
ctx->output.imgbuf = job->databuf + job->datalen;
ctx->output.bytes_per_row = job->cols * 3 * 2;
DEBUG("Running print data through processing library\n");
if (ctx->lib.DoImageEffect(ctx->lib.cpcdata, ctx->lib.ecpcdata,
&input, &ctx->output, job->sharpen, job->reverse, rew)) {
ERROR("Image Processing failed, aborting!\n");
return CUPS_BACKEND_CANCEL;
}
/* Twiddle rewind stuff if needed */
if (ctx->conn->type != P_MITSU_D70X) {
hdr->rewind[0] = !rew[0];
hdr->rewind[1] = !rew[1];
DEBUG("Rewind Inhibit? %02x %02x\n", hdr->rewind[0], hdr->rewind[1]);
}
/* Move up the pointer to after the image data */
job->datalen += 3*job->planelen;
/* Clean up */
free(job->spoolbuf);
job->spoolbuf = NULL;
job->spoolbuflen = 0;
/* Now that we've filled everything in, read matte from file */
if (job->matte) {
ret = mitsu_readlamdata(job->laminatefname, LAMINATE_STRIDE,
job->databuf, &job->datalen,
be16_to_cpu(hdr->lamrows), be16_to_cpu(hdr->lamcols), 2);
if (ret)
return ret;
/* Zero out the tail end of the buffer. */
ret = be16_to_cpu(hdr->lamcols) * be16_to_cpu(hdr->lamrows) * 2;
memset(job->databuf + job->datalen, 0, job->matte - ret);
}
bypass:
/* Bypass */
if (test_mode >= TEST_MODE_NOPRINT)
return CUPS_BACKEND_OK;
INFO("Waiting for printer idle...\n");
/* Ensure printer is awake */
@ -2618,8 +2616,7 @@ static const char *mitsu70x_prefixes[] = {
/* Exported */
const struct dyesub_backend mitsu70x_backend = {
.name = "Mitsubishi CP-D70 family",
.version = "0.108" " (lib " LIBMITSU_VER ")",
.flags = BACKEND_FLAG_DUMMYPRINT,
.version = "0.109" " (lib " LIBMITSU_VER ")",
.uri_prefixes = mitsu70x_prefixes,
.cmdline_usage = mitsu70x_cmdline,
.cmdline_arg = mitsu70x_cmdline_arg,