mitsud90: Move all image processing to before pano splitting

...and out of the main_loop() which now only does some final sanity
checks and sets up the job
This commit is contained in:
Solomon Peachy 2024-01-11 21:15:10 -05:00
parent fe230371db
commit 69344f821a
1 changed files with 88 additions and 93 deletions

View File

@ -1006,6 +1006,31 @@ static int mitsud90_panorama_splitjob(struct mitsud90_printjob *injob, struct mi
return CUPS_BACKEND_OK;
}
static int cpm1_fillmatte(struct mitsud90_printjob *job)
{
int ret;
int rows, cols;
struct mitsud90_plane_hdr *phdr = (struct mitsud90_plane_hdr *) job->databuf;
rows = be16_to_cpu(job->hdr.rows) + 12;
cols = be16_to_cpu(job->hdr.cols);
/* Fill in matte data */
ret = mitsu_readlamdata(CPM1_LAMINATE_FILE, CPM1_LAMINATE_STRIDE,
job->databuf, &job->datalen,
rows, cols, 1);
if (ret)
return ret;
/* Update plane header and overall length */
phdr->lamcols = cpu_to_be16(cols);
phdr->lamrows = cpu_to_be16(rows);
return CUPS_BACKEND_OK;
}
static int mitsud90_read_parse(void *vctx, const void **vjob, int data_fd, int copies) {
struct mitsud90_ctx *ctx = vctx;
int i, remain;
@ -1072,11 +1097,10 @@ static int mitsud90_read_parse(void *vctx, const void **vjob, int data_fd, int c
job->is_pano = 1;
job->hdr.zero_b[3] = 0;
job->hdr.pano.on = 0; /* Will get inserted later */
} else if (be16_to_cpu(job->hdr.rows > 2729)) {
} else if (be16_to_cpu(job->hdr.rows) > 2729) {
job->is_pano = 1;
job->hdr.pano.on = 0;
}
} else if (ctx->conn->type == P_MITSU_W5000) {
struct mitsuw5k_job_hdr *hdr = (struct mitsuw5k_job_hdr*) &job->hdr;
@ -1228,7 +1252,7 @@ read_data:
}
}
/* CP-M1 has... other considerations */
/* Apply 3D Lut if requested and the printer can't handle it */
if (((ctx->conn->type == P_MITSU_M1 ||
ctx->conn->type == P_FUJI_ASK500) && !job->is_raw) ||
(ctx->conn->type == P_MITSU_D90 && job->is_pano)) {
@ -1266,95 +1290,12 @@ read_data:
job->hdr.colorcorr = 1; // XXX not sure if right for ASK500?
}
if (job->is_pano) {
int rval;
// XXX do any print sharpening here! If possible..
rval = mitsud90_panorama_splitjob(job, (struct mitsud90_printjob**)vjob);
/* Clean up original parsed job regardless */
mitsud90_cleanup_job(job);
return rval;
} else {
*vjob = job;
}
/* All further work is in main loop */
if (test_mode >= TEST_MODE_NOPRINT)
mitsud90_main_loop(ctx, job, 1);
return CUPS_BACKEND_OK;
}
static int cpm1_fillmatte(struct mitsud90_printjob *job)
{
int ret;
int rows, cols;
struct mitsud90_plane_hdr *phdr = (struct mitsud90_plane_hdr *) job->databuf;
rows = be16_to_cpu(job->hdr.rows) + 12;
cols = be16_to_cpu(job->hdr.cols);
/* Fill in matte data */
ret = mitsu_readlamdata(CPM1_LAMINATE_FILE, CPM1_LAMINATE_STRIDE,
job->databuf, &job->datalen,
rows, cols, 1);
if (ret)
return ret;
/* Update plane header and overall length */
phdr->lamcols = cpu_to_be16(cols);
phdr->lamrows = cpu_to_be16(rows);
return CUPS_BACKEND_OK;
}
static int mitsud90_main_loop(void *vctx, const void *vjob, int wait_for_return) {
struct mitsud90_ctx *ctx = vctx;
struct mitsud90_status_resp resp;
uint8_t last_status[2] = {0xff, 0xff};
int sent;
int ret;
int copies;
struct mitsud90_printjob *job = (struct mitsud90_printjob *)vjob;
if (!ctx)
return CUPS_BACKEND_FAILED;
if (!job)
return CUPS_BACKEND_FAILED;
copies = job->common.copies;
/* Handle panorama state */
if (ctx->conn->type == P_MITSU_D90) {
if (job->hdr.pano.on) {
ctx->pano_page++;
if (be16_to_cpu(job->hdr.pano.page) != ctx->pano_page) {
ERROR("Invalid panorama state (page %d of %d)\n",
ctx->pano_page, be16_to_cpu(job->hdr.pano.page));
return CUPS_BACKEND_FAILED;
}
if (copies > 1) {
WARNING("Cannot print non-collated copies of a panorama job\n");
copies = 1;
}
} else if (ctx->pano_page) {
/* Clean up panorama state */
WARNING("Dangling panorama state!\n");
ctx->pano_page = 0;
}
} else {
ctx->pano_page = 0;
}
if ((ctx->conn->type == P_MITSU_M1 ||
ctx->conn->type == P_FUJI_ASK500) && !job->is_raw) {
struct BandImage input;
struct BandImage output;
struct M1CPCData *cpc;
int ret;
input.origin_rows = input.origin_cols = 0;
input.rows = be16_to_cpu(job->hdr.rows);
@ -1366,6 +1307,7 @@ static int mitsud90_main_loop(void *vctx, const void *vjob, int wait_for_return)
uint8_t *convbuf = malloc(input.rows * input.cols * sizeof(uint16_t) * 3 + (job->hdr.overcoat? (input.rows + 12) * input.cols + CPM1_LAMINATE_STRIDE / 2 : 0) + sizeof(struct mitsud90_plane_hdr));
if (!convbuf) {
ERROR("Memory allocation Failure!\n");
mitsud90_cleanup_job(job);
return CUPS_BACKEND_RETRY_CURRENT;
}
@ -1418,6 +1360,7 @@ static int mitsud90_main_loop(void *vctx, const void *vjob, int wait_for_return)
if (!cpc) {
ERROR("Cannot read data tables\n");
free(convbuf);
mitsud90_cleanup_job(job);
return CUPS_BACKEND_FAILED;
}
@ -1436,6 +1379,7 @@ static int mitsud90_main_loop(void *vctx, const void *vjob, int wait_for_return)
ERROR("CLocalEnhancer failed (out of memory?)\n");
free(convbuf);
ctx->lib.M1_DestroyCPCData(cpc);
mitsud90_cleanup_job(job);
return CUPS_BACKEND_RETRY_CURRENT;
}
}
@ -1473,9 +1417,60 @@ static int mitsud90_main_loop(void *vctx, const void *vjob, int wait_for_return)
}
}
/* Bypass */
if (test_mode >= TEST_MODE_NOPRINT)
return CUPS_BACKEND_OK;
if (job->is_pano) {
int rval;
// XXX do any print sharpening here! If possible..
rval = mitsud90_panorama_splitjob(job, (struct mitsud90_printjob**)vjob);
/* Clean up original parsed job regardless */
mitsud90_cleanup_job(job);
return rval;
} else {
*vjob = job;
}
return CUPS_BACKEND_OK;
}
static int mitsud90_main_loop(void *vctx, const void *vjob, int wait_for_return) {
struct mitsud90_ctx *ctx = vctx;
struct mitsud90_status_resp resp;
uint8_t last_status[2] = {0xff, 0xff};
int sent;
int ret;
int copies;
struct mitsud90_printjob *job = (struct mitsud90_printjob *)vjob;
if (!ctx)
return CUPS_BACKEND_FAILED;
if (!job)
return CUPS_BACKEND_FAILED;
copies = job->common.copies;
/* Handle panorama state */
if (ctx->conn->type == P_MITSU_D90) {
if (job->hdr.pano.on) {
ctx->pano_page++;
if (be16_to_cpu(job->hdr.pano.page) != ctx->pano_page) {
ERROR("Invalid panorama state (page %d of %d)\n",
ctx->pano_page, be16_to_cpu(job->hdr.pano.page));
return CUPS_BACKEND_FAILED;
}
if (copies > 1) {
WARNING("Cannot print non-collated copies of a panorama job\n");
copies = 1;
}
} else if (ctx->pano_page) {
/* Clean up panorama state */
WARNING("Dangling panorama state!\n");
ctx->pano_page = 0;
}
} else {
ctx->pano_page = 0;
}
INFO("Waiting for printer idle...\n");
@ -2485,10 +2480,10 @@ const struct dyesub_backend mitsud90_backend = {
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 MM == 0 for no margin cut, 1 for margin cut
QQ RR SS HH VV 00 00 00 00 00 ZZ 00 JJ II 09 7c QQ == 02 matte (D90) or 03 (M1), 00 glossy,
09 4c 00 00 02 58 00 0c 00 06 00 00 00 00 00 00 RR == 00 auto, (D90: 03 == fine, 02 == superfine), (M1: 05 == Fast)
Z0 Z1 Z2 00 00 00 00 00 00 00 00 00 00 00 00 00 SS == 00 colorcorr, 01 == none (always 01 on M1)
Z0 Z1 Z2 00 00 00 00 00 00 00 00 00 00 00 00 00 SS == 00 colorcorr, 01 == none (always 01 on M1 or D90 if LUT done in driver)
HH/VV sharpening for Horiz/Vert, 0-8, 0 is off, 4 is normal (always 00 on M1)
TT is waittime (100 max, always 100 on D90)
ZZ is 0x02 on M1, D90 see below
ZZ is 0x02 on M1, D90 see PANORAMA below
Z0 is 0x01 (M1 windows) (00 Linux and d90 UNK!)
Z1 is RGB Rate (M1)
Z2 is OP Rate (M1)
@ -2504,7 +2499,7 @@ const struct dyesub_backend mitsud90_backend = {
9x6div3 == 2724 02 03 90 01 00 07 14 00 00 00 00 00 00
9x6div4 == 2628 03 02 97 01 00 05 22 00 00 07 ad 00 00
from [ZZ 00 03 03] onwards, only shows in 8x20" PANORAMA prints. Assume 2" overlap.
PANORAMA: from [ZZ 00 03 03] onwards, only shows in PANORAMA prints. Assume 2" overlap.
ZZ == 00 (normal) or 01 (panorama)
JJ == 02 03 (num of panorama panels)
II == 01 02 03 (which panel # in panorama!)