selphy_print/backend_mitsu9550.c

1998 lines
52 KiB
C
Raw Normal View History

/*
* Mitsubishi CP-9xxx Photo Printer Family CUPS backend
*
* (c) 2014-2020 Solomon Peachy <pizza@shaftnet.org>
*
* The latest version of this program can be found at:
*
* http://git.shaftnet.org/cgit/selphy_print.git
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0+
*
*/
2019-09-28 11:05:42 -04:00
#define BACKEND mitsu9550_backend
2019-09-28 11:05:42 -04:00
#include "backend_common.h"
2018-04-23 21:58:45 -04:00
/* For Integration into gutenprint */
#if defined(HAVE_CONFIG_H)
#include <config.h>
#endif
#ifndef WITH_DYNAMIC
#warning "No dynamic loading support!"
#endif
// #include "lib70x/libMitsuD70ImageReProcess.h"
#ifndef LUT_LEN
#define COLORCONV_RGB 0
#define COLORCONV_BGR 1
#define LUT_LEN 14739
struct BandImage {
void *imgbuf;
int32_t bytes_per_row;
uint16_t origin_cols;
uint16_t origin_rows;
uint16_t cols;
uint16_t rows;
};
#endif
#define REQUIRED_LIB_APIVERSION 4
/* Image processing library function prototypes */
#define LIB_NAME_RE "libMitsuD70ImageReProcess" DLL_SUFFIX
typedef int (*lib70x_getapiversionFN)(void);
typedef int (*Get3DColorTableFN)(uint8_t *buf, const char *filename);
typedef struct CColorConv3D *(*Load3DColorTableFN)(const uint8_t *ptr);
typedef void (*Destroy3DColorTableFN)(struct CColorConv3D *this);
typedef void (*DoColorConvFN)(struct CColorConv3D *this, uint8_t *data, uint16_t cols, uint16_t rows, uint32_t bytes_per_row, int rgb_bgr);
#ifndef CORRTABLE_PATH
#ifdef PACKAGE_DATA_DIR
#define CORRTABLE_PATH PACKAGE_DATA_DIR "/backend_data"
#else
#error "Must define CORRTABLE_PATH or PACKAGE_DATA_DIR!"
#endif
#endif
#define MITSU_M98xx_LAMINATE_FILE CORRTABLE_PATH "/M98MATTE.raw"
#define MITSU_M98xx_DATATABLE_FILE CORRTABLE_PATH "/M98TABLE.dat"
#define MITSU_M98xx_LUT_FILE CORRTABLE_PATH "/M98XXL01.lut"
#define LAMINATE_STRIDE 1868
#define DATATABLE_SIZE 42204
/* USB VIDs and PIDs */
#define USB_VID_MITSU 0x06D3
#define USB_PID_MITSU_9500D 0x0393
#define USB_PID_MITSU_9000D 0x0394
#define USB_PID_MITSU_9000AM 0x0395
#define USB_PID_MITSU_9550D 0x03A1
#define USB_PID_MITSU_9550DS 0x03A5 // or DZ/DZS/DZU
#define USB_PID_MITSU_9600D 0x03A9
//#define USB_PID_MITSU_9600DS XXXXXX
#define USB_PID_MITSU_9800D 0x03AD
#define USB_PID_MITSU_9800DS 0x03AE
#define USB_PID_MITSU_98__D 0x3B21
//#define USB_PID_MITSU_9810D XXXXXX
//#define USB_PID_MITSU_9820DS XXXXXX
/* Spool file structures */
/* Print parameters1 */
struct mitsu9550_hdr1 {
uint8_t cmd[4]; /* 1b 57 20 2e */
uint8_t unk[10]; /* 00 0a 10 00 [...] */
uint16_t cols; /* BE */
uint16_t rows; /* BE */
uint8_t matte; /* CP9810/9820 only. 01 for matte, 00 glossy */
2016-10-12 20:29:02 -04:00
uint8_t null[31];
} __attribute__((packed));
/* Print parameters2 */
struct mitsu9550_hdr2 {
uint8_t cmd[4]; /* 1b 57 21 2e */
uint8_t unk[24]; /* 00 80 00 22 08 03 [...] */
uint16_t copies; /* BE, 1-680 */
uint8_t null[2];
uint8_t cut; /* 00 == normal, 83 == 2x6*2 */
uint8_t unkb[5];
uint8_t mode; /* 00 == fine, 80 == superfine */
2016-09-28 14:15:04 -04:00
uint8_t unkc[11]; /* 00 [...] 00 01 */
} __attribute__((packed));
/* Fine Deep selection (9550 only) */
struct mitsu9550_hdr3 {
uint8_t cmd[4]; /* 1b 57 22 2e */
uint8_t unk[7]; /* 00 40 00 [...] */
uint8_t mode2; /* 00 == normal, 01 == finedeep */
2016-09-28 14:15:04 -04:00
uint8_t null[38];
} __attribute__((packed));
/* Error policy? */
struct mitsu9550_hdr4 {
uint8_t cmd[4]; /* 1b 57 26 2e */
uint8_t unk[46]; /* 00 70 00 00 00 00 00 00 01 01 00 [...] */
} __attribute__((packed));
/* Data plane header */
struct mitsu9550_plane {
uint8_t cmd[4]; /* 1b 5a 54 XX */ /* XX == 0x10 if 16bpp, 0x00 for 8bpp */
uint16_t col_offset; /* BE, normally 0, where we start dumping data */
uint16_t row_offset; /* BE, normally 0, where we start dumping data */
uint16_t cols; /* BE */
uint16_t rows; /* BE */
} __attribute__((packed));
/* CP98xx Tabular Data, as stored in data file! */
struct mitsu98xx_data {
/* @ 0 */ uint16_t GNMby[256]; /* BGR Order uncertain */
/* @ 512 */ uint16_t GNMgm[256];
/* @ 1024 */ uint16_t GNMrc[256];
/* @ 1536 */ uint16_t unk_sharp[20]; /* Actual format is: u16, u16[9], u16, u16[9] */
/* @ 1576 */ double GammaAdj[3]; /* Assumed to be same order as tables (BGR?) */
/* @ 1600 */ struct {
/* @ 0 */ double unka[256];
/* @ 2048 */ double unkb[256];
/* @ 4096 */ double unkc[5]; /* Weight factors */
/* @ 4136 */ double unkd[256];
/* @ 6184 */ double unke[256]; // *= sharp->coef[X]
/* @ 8232 */ double unkf[5]; /* Weight factors */
/* @ 8272 */ double unkg[256];
/* @10320 */
} WMAM;
/* @11920 */ double sharp_coef[11]; /* 0 is off, 1-10 are the levels. Default is 5. [4 in settings] */
/* @12008 */ uint32_t KHStart;
/* @12012 */ uint32_t KHEnd;
/* @12016 */ uint32_t KHStep;
/* @12020 */ double KH[256];
/* @14068 */
} __attribute__((packed));
struct mitsu98xx_tables {
struct mitsu98xx_data superfine;
struct mitsu98xx_data fine_std;
struct mitsu98xx_data fine_hg;
} __attribute__((packed));
/* Command header */
2014-12-14 19:09:32 -05:00
struct mitsu9550_cmd {
uint8_t cmd[4];
} __attribute__((packed));
/* Private data structure */
struct mitsu9550_printjob {
uint8_t *databuf;
uint32_t datalen;
uint16_t rows;
uint16_t cols;
uint32_t plane_len;
int is_raw;
int copies;
/* Parse headers separately */
struct mitsu9550_hdr1 hdr1;
int hdr1_present;
struct mitsu9550_hdr2 hdr2;
int hdr2_present;
struct mitsu9550_hdr3 hdr3;
int hdr3_present;
struct mitsu9550_hdr4 hdr4;
int hdr4_present;
};
struct mitsu9550_ctx {
struct libusb_device_handle *dev;
uint8_t endp_up;
uint8_t endp_down;
int type;
int is_s;
int is_98xx;
struct marker marker;
/* CP98xx stuff */
void *dl_handle;
lib70x_getapiversionFN GetAPIVersion;
Get3DColorTableFN Get3DColorTable;
Load3DColorTableFN Load3DColorTable;
Destroy3DColorTableFN Destroy3DColorTable;
DoColorConvFN DoColorConv;
struct CColorConv3D *lut;
struct mitsu98xx_tables *m98xxdata;
};
/* Printer data structures */
struct mitsu9550_media {
uint8_t hdr[2]; /* 24 2e */
uint8_t unk[12];
uint8_t type;
uint8_t unka[13];
uint16_t max; /* BE, prints per media */
uint8_t unkb[2];
uint16_t remain; /* BE, prints remaining */
uint8_t unkc[14];
} __attribute__((packed));
struct mitsu9550_status {
uint8_t hdr[2]; /* 30 2e */
uint8_t null[4];
uint8_t sts1; // MM
2014-12-20 12:43:22 -05:00
uint8_t nullb[1];
2016-09-28 14:15:04 -04:00
uint16_t copies; // BE, NN
uint8_t sts2; // ZZ (9600 only?)
uint8_t nullc[5];
uint8_t sts3; // QQ
uint8_t sts4; // RR
uint8_t sts5; // SS
uint8_t nulld[25];
uint8_t sts6; // TT
uint8_t sts7; // UU
uint8_t nulle[2];
} __attribute__((packed));
struct mitsu9550_status2 {
uint8_t hdr[2]; /* 21 2e / 24 2e on 9550/9800 */
uint8_t unk[40];
uint16_t remain; /* BE, media remaining */
uint8_t unkb[4]; /* 0a 00 00 01 */
} __attribute__((packed));
static int mitsu9550_main_loop(void *vctx, const void *vjob);
#define CMDBUF_LEN 64
#define READBACK_LEN 128
#define QUERY_STATUS() \
do {\
struct mitsu9550_status *sts = (struct mitsu9550_status*) rdbuf;\
/* struct mitsu9550_status2 *sts2 = (struct mitsu9550_status2*) rdbuf; */ \
struct mitsu9550_media *media = (struct mitsu9550_media *) rdbuf; \
uint16_t donor; \
/* media */ \
ret = mitsu9550_get_status(ctx, rdbuf, 0, 0, 1); \
if (ret < 0) \
return CUPS_BACKEND_FAILED; \
\
donor = be16_to_cpu(media->remain); \
if (donor != ctx->marker.levelnow) { \
ctx->marker.levelnow = donor; \
dump_markers(&ctx->marker, 1, 0); \
} \
/* Sanity-check media response */ \
if (media->remain == 0 || media->max == 0) { \
ERROR("Printer out of media!\n"); \
return CUPS_BACKEND_HOLD; \
} \
if (validate_media(ctx->type, media->type, job->cols, job->rows)) { \
ERROR("Incorrect media (%u) type for printjob (%ux%u)!\n", media->type, job->cols, job->rows); \
return CUPS_BACKEND_HOLD; \
} \
/* status2 */ \
ret = mitsu9550_get_status(ctx, rdbuf, 0, 1, 0); \
if (ret < 0) \
return CUPS_BACKEND_FAILED; \
/* status */ \
ret = mitsu9550_get_status(ctx, rdbuf, 1, 0, 0); \
if (ret < 0) \
return CUPS_BACKEND_FAILED; \
\
/* Make sure we're idle */ \
if (sts->sts5 != 0) { /* Printer ready for another job */ \
sleep(1); \
goto top; \
} \
/* Check for known errors */ \
if (sts->sts2 != 0) { \
ERROR("Printer cover open!\n"); \
return CUPS_BACKEND_STOP; \
} \
} while (0);
static void mitsu98xx_dogamma(uint8_t *src, uint16_t *dest, uint8_t plane,
uint16_t *table, uint32_t len)
{
src += plane;
while(len--) {
*dest++ = cpu_to_be16(table[*src]);
src += 3;
}
}
static int mitsu98xx_fillmatte(struct mitsu9550_printjob *job)
{
int fd, i;
uint32_t j, remain;
DEBUG("Reading %d bytes of matte data from disk (%d/%d)\n", job->cols * job->rows * 2, job->cols, LAMINATE_STRIDE);
fd = open(MITSU_M98xx_LAMINATE_FILE, O_RDONLY);
if (fd < 0) {
WARNING("Unable to open matte lamination data file '%s'\n", MITSU_M98xx_LAMINATE_FILE);
job->hdr1.matte = 0;
goto done;
}
/* Fill in the lamination plane header */
struct mitsu9550_plane *matte = (struct mitsu9550_plane *)(job->databuf + job->datalen);
matte->cmd[0] = 0x1b;
matte->cmd[1] = 0x5a;
matte->cmd[2] = 0x54;
matte->cmd[3] = 0x10;
matte->row_offset = 0;
matte->col_offset = 0;
matte->cols = cpu_to_be16(job->hdr1.cols);
matte->rows = cpu_to_be16(job->hdr1.rows);
job->datalen += sizeof(struct mitsu9550_plane);
/* Read in the matte data plane */
for (j = 0 ; j < job->rows ; j++) {
remain = LAMINATE_STRIDE * 2;
/* Read one row of lamination data at a time */
while (remain) {
i = read(fd, job->databuf + job->datalen, remain);
if (i < 0)
return CUPS_BACKEND_CANCEL;
if (i == 0) {
/* We hit EOF, restart from beginning */
lseek(fd, 0, SEEK_SET);
continue;
}
job->datalen += i;
remain -= i;
}
/* Back off the buffer so we "wrap" on the print row. */
job->datalen -= ((LAMINATE_STRIDE - job->cols) * 2);
}
/* We're done! */
close(fd);
/* Fill in the lamination plane footer */
job->databuf[job->datalen++] = 0x1b;
job->databuf[job->datalen++] = 0x50;
job->databuf[job->datalen++] = 0x56;
job->databuf[job->datalen++] = 0x00;
done:
return CUPS_BACKEND_OK;
}
#ifndef LUT_LEN
#define LUT_LEN 14739
#define COLORCONV_RGB 0
#define COLORCONV_BGR 1
#endif
static int mitsu9550_get_status(struct mitsu9550_ctx *ctx, uint8_t *resp, int status, int status2, int media);
static char *mitsu9550_media_types(uint8_t type, uint8_t is_s);
static void *mitsu9550_init(void)
{
struct mitsu9550_ctx *ctx = malloc(sizeof(struct mitsu9550_ctx));
if (!ctx) {
ERROR("Memory Allocation Failure!\n");
return NULL;
}
memset(ctx, 0, sizeof(struct mitsu9550_ctx));
DL_INIT();
return ctx;
}
static int mitsu9550_attach(void *vctx, struct libusb_device_handle *dev, int type,
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
{
struct mitsu9550_ctx *ctx = vctx;
struct mitsu9550_media media;
UNUSED(jobid);
UNUSED(iface);
ctx->dev = dev;
ctx->endp_up = endp_up;
ctx->endp_down = endp_down;
ctx->type = type;
if (ctx->type == P_MITSU_9550S ||
ctx->type == P_MITSU_9800S)
ctx->is_s = 1;
if (ctx->type == P_MITSU_9800 ||
ctx->type == P_MITSU_9800S ||
ctx->type == P_MITSU_9810)
ctx->is_98xx = 1;
/* Attempt to open the library */
#if defined(WITH_DYNAMIC)
if (!ctx->is_98xx) goto skip;
DEBUG("Attempting to load image processing library\n");
ctx->dl_handle = DL_OPEN(LIB_NAME_RE);
if (!ctx->dl_handle)
WARNING("Image processing library not found, using internal fallback code\n");
if (ctx->dl_handle) {
ctx->GetAPIVersion = DL_SYM(ctx->dl_handle, "lib70x_getapiversion");
if (!ctx->GetAPIVersion) {
ERROR("Problem resolving API Version symbol in imaging processing library, too old or not installed?\n");
DL_CLOSE(ctx->dl_handle);
ctx->dl_handle = NULL;
return CUPS_BACKEND_FAILED;
}
if (ctx->GetAPIVersion() != REQUIRED_LIB_APIVERSION) {
ERROR("Image processing library API version mismatch!\n");
DL_CLOSE(ctx->dl_handle);
ctx->dl_handle = NULL;
return CUPS_BACKEND_FAILED;
}
ctx->Get3DColorTable = DL_SYM(ctx->dl_handle, "CColorConv3D_Get3DColorTable");
ctx->Load3DColorTable = DL_SYM(ctx->dl_handle, "CColorConv3D_Load3DColorTable");
ctx->Destroy3DColorTable = DL_SYM(ctx->dl_handle, "CColorConv3D_Destroy3DColorTable");
ctx->DoColorConv = DL_SYM(ctx->dl_handle, "CColorConv3D_DoColorConv");
if (!ctx->Get3DColorTable || !ctx->Load3DColorTable ||
!ctx->Destroy3DColorTable || !ctx->DoColorConv ) {
ERROR("Problem resolving symbols in imaging processing library\n");
DL_CLOSE(ctx->dl_handle);
ctx->dl_handle = NULL;
return CUPS_BACKEND_FAILED;
} else {
DEBUG("Image processing library successfully loaded\n");
}
}
skip:
#endif
if (test_mode < TEST_MODE_NOATTACH) {
if (mitsu9550_get_status(ctx, (uint8_t*) &media, 0, 0, 1))
return CUPS_BACKEND_FAILED;
} else {
int media_code = 0x2;
if (getenv("MEDIA_CODE"))
media_code = atoi(getenv("MEDIA_CODE")) & 0xf;
media.max = cpu_to_be16(400);
2018-05-12 18:33:39 -04:00
media.remain = cpu_to_be16(330);
media.type = media_code;
}
ctx->marker.color = "#00FFFF#FF00FF#FFFF00";
ctx->marker.name = mitsu9550_media_types(media.type, ctx->is_s);
ctx->marker.numtype = media.type;
ctx->marker.levelmax = be16_to_cpu(media.max);
ctx->marker.levelnow = be16_to_cpu(media.remain);
return CUPS_BACKEND_OK;
}
static void mitsu9550_cleanup_job(const void *vjob)
{
const struct mitsu9550_printjob *job = vjob;
if (job->databuf)
free(job->databuf);
free((void*)job);
}
static void mitsu9550_teardown(void *vctx) {
struct mitsu9550_ctx *ctx = vctx;
if (!ctx)
return;
if (ctx->dl_handle) {
if (ctx->lut)
ctx->Destroy3DColorTable(ctx->lut);
if (ctx->m98xxdata)
free(ctx->m98xxdata);
DL_CLOSE(ctx->dl_handle);
}
free(ctx);
}
static int mitsu9550_read_parse(void *vctx, const void **vjob, int data_fd, int copies) {
struct mitsu9550_ctx *ctx = vctx;
uint8_t buf[sizeof(struct mitsu9550_hdr1)];
int remain, i;
uint32_t planelen = 0;
struct mitsu9550_printjob *job = NULL;
if (!ctx)
return CUPS_BACKEND_FAILED;
job = malloc(sizeof(*job));
if (!job) {
ERROR("Memory allocation failure!\n");
return CUPS_BACKEND_RETRY_CURRENT;
}
memset(job, 0, sizeof(*job));
job->is_raw = 1;
top:
/* Read in initial header */
remain = sizeof(buf);
while (remain > 0) {
i = read(data_fd, buf + sizeof(buf) - remain, remain);
if (i == 0) {
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
if (i < 0) {
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
remain -= i;
}
/* Sanity check */
if (buf[0] != 0x1b || buf[1] != 0x57 || buf[3] != 0x2e) {
if (!job->hdr1_present || !job->hdr2_present) {
ERROR("Unrecognized data format (%02x%02x%02x%02x)!\n",
buf[0], buf[1], buf[2], buf[3]);
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
} else if (buf[0] == 0x1b &&
buf[1] == 0x5a &&
buf[2] == 0x54) {
/* We're in the data portion now */
if (buf[3] == 0x10)
planelen *= 2;
else if (ctx->is_98xx && buf[3] == 0x80)
job->is_raw = 0;
goto hdr_done;
} else {
ERROR("Unrecognized data block (%02x%02x%02x%02x)!\n",
buf[0], buf[1], buf[2], buf[3]);
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
}
switch(buf[2]) {
case 0x20: /* header 1 */
memcpy(&job->hdr1, buf, sizeof(job->hdr1));
job->hdr1_present = 1;
/* Work out printjob size */
job->rows = be16_to_cpu(job->hdr1.rows);
job->cols = be16_to_cpu(job->hdr1.cols);
planelen = job->rows * job->cols;
break;
case 0x21: /* header 2 */
memcpy(&job->hdr2, buf, sizeof(job->hdr2));
job->hdr2_present = 1;
break;
case 0x22: /* header 3 */
memcpy(&job->hdr3, buf, sizeof(job->hdr3));
job->hdr3_present = 1;
break;
case 0x26: /* header 4 */
memcpy(&job->hdr4, buf, sizeof(job->hdr4));
job->hdr4_present = 1;
break;
default:
ERROR("Unrecognized header format (%02x)!\n", buf[2]);
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_CANCEL;
}
/* Read in the next chunk */
goto top;
hdr_done:
/* Read in CP98xx data tables if necessary */
if (ctx->is_98xx && !job->is_raw && !ctx->m98xxdata) {
int ret;
ctx->m98xxdata = malloc(DATATABLE_SIZE);
if (!ctx->m98xxdata) {
ERROR("Memory allocation Failure!\n");
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_RETRY_CURRENT;
}
DEBUG("Reading in 98xx data from disk\n");
if ((ret = dyesub_read_file(MITSU_M98xx_DATATABLE_FILE, ctx->m98xxdata, DATATABLE_SIZE, NULL))) {
ERROR("Unable to read 98xx data table file '%s'\n", MITSU_M98xx_DATATABLE_FILE);
free(ctx->m98xxdata);
return ret;
}
/* Byteswap data table to native endianness, if necessary */
#if (__BYTE_ORDER == __LITTLE_ENDIAN)
int j;
struct mitsu98xx_data *ptr = &ctx->m98xxdata->superfine;
for (j = 0 ; j < 3 ; j++) {
ptr->KHStart = be32_to_cpu(ptr->KHStart);
ptr->KHEnd = be32_to_cpu(ptr->KHEnd);
ptr->KHStep = be32_to_cpu(ptr->KHStep);
for (i = 3 ; i < 3 ; i++) {
ptr->GammaAdj[i] = be64_to_cpu(ptr->GammaAdj[i]);
}
for (i = 0 ; i < 5 ; i++) {
ptr->WMAM.unkc[i] = be64_to_cpu(ptr->WMAM.unkc[i]);
ptr->WMAM.unkf[i] = be64_to_cpu(ptr->WMAM.unkf[i]);
}
for (i = 0 ; i < 11 ; i++) {
ptr->sharp_coef[i] = be64_to_cpu(ptr->sharp_coef[i]);
}
for (i = 0 ; i < 20 ; i++) {
ptr->unk_sharp[i] = be16_to_cpu(ptr->unk_sharp[i]);
}
for (i = 0 ; i < 256 ; i++) {
ptr->WMAM.unka[i] = be64_to_cpu(ptr->WMAM.unka[i]);
ptr->WMAM.unkb[i] = be64_to_cpu(ptr->WMAM.unkb[i]);
ptr->WMAM.unkd[i] = be64_to_cpu(ptr->WMAM.unkd[i]);
ptr->WMAM.unke[i] = be64_to_cpu(ptr->WMAM.unke[i]);
ptr->WMAM.unkg[i] = be64_to_cpu(ptr->WMAM.unkg[i]);
ptr->GNMby[i] = be16_to_cpu(ptr->GNMby[i]);
ptr->GNMgm[i] = be16_to_cpu(ptr->GNMgm[i]);
ptr->GNMrc[i] = be16_to_cpu(ptr->GNMrc[i]);
ptr->KH[i] = be64_to_cpu(ptr->KH[i]);
}
ptr++;
}
#endif
}
if (job->is_raw) {
/* We have three planes + headers and the final terminator to read */
remain = 3 * (planelen + sizeof(struct mitsu9550_plane)) + sizeof(struct mitsu9550_cmd);
} else {
/* We have one plane + header and the final terminator to read */
remain = planelen * 3 + sizeof(struct mitsu9550_plane) + sizeof(struct mitsu9550_cmd);
}
/* Mitsu9600 windows spool uses more, smaller blocks, but plane data is the same */
if (ctx->type == P_MITSU_9600) {
remain += 128 * sizeof(struct mitsu9550_plane); /* 39 extra seen on 4x6" */
}
/* 9550S/9800S doesn't typically sent over hdr4! */
if (ctx->type == P_MITSU_9550S ||
ctx->type == P_MITSU_9800S) {
/* XXX Has to do with error policy, but not sure what.
Mitsu9550-S/9800-S will set this based on a command,
but it's not part of the standard job spool */
job->hdr4_present = 0;
}
/* Disable matte if the printer doesn't support it */
if (job->hdr1.matte) {
if (ctx->type != P_MITSU_9810) {
WARNING("Matte not supported on this printer, disabling\n");
job->hdr1.matte = 0;
} else if (job->is_raw) {
remain += planelen + sizeof(struct mitsu9550_plane) + sizeof(struct mitsu9550_cmd);
}
}
/* Allocate buffer for the payload */
job->datalen = 0;
job->databuf = malloc(remain);
if (!job->databuf) {
ERROR("Memory allocation failure!\n");
mitsu9550_cleanup_job(job);
return CUPS_BACKEND_RETRY_CURRENT;
}
/* Load up the data blocks.*/
while(1) {
2016-10-23 11:59:29 -04:00
/* Note that 'buf' needs to be already filled here! */
struct mitsu9550_plane *plane = (struct mitsu9550_plane *)buf;
/* Sanity check header... */
if (plane->cmd[0] != 0x1b ||
plane->cmd[1] != 0x5a ||
plane->cmd[2] != 0x54) {
2018-05-09 10:47:19 -04:00
ERROR("Unrecognized data read (%02x%02x%02x%02x)!\n",
plane->cmd[0], plane->cmd[1], plane->cmd[2], plane->cmd[3]);
mitsu9550_cleanup_job(job);