summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2020-02-05 13:22:26 -0500
committerSolomon Peachy <pizza@shaftnet.org>2020-02-05 18:50:58 -0500
commit8c576b13b2c1d511a5bb046e0e20837601ec90ba (patch)
tree08467f1d4e5aac25671ef2e788b3a6078d499e6d
parent9d8ad9b05cdb78a5bff974ff4e9d1fcce03ec454 (diff)
downloadselphy_print-8c576b13b2c1d511a5bb046e0e20837601ec90ba.tar.gz
selphy_print-8c576b13b2c1d511a5bb046e0e20837601ec90ba.tar.bz2
selphy_print-8c576b13b2c1d511a5bb046e0e20837601ec90ba.zip
Mitsubishi: Start pulling common code into a separate code module.
-rw-r--r--Makefile10
-rw-r--r--backend_mitsu.c192
-rw-r--r--backend_mitsu.h88
-rw-r--r--backend_mitsu70x.c242
-rw-r--r--backend_mitsu9550.c190
-rw-r--r--backend_mitsud90.c43
6 files changed, 362 insertions, 403 deletions
diff --git a/Makefile b/Makefile
index 645eaf6..20bd988 100644
--- a/Makefile
+++ b/Makefile
@@ -98,11 +98,13 @@ LDFLAGS += $(CFLAGS) $(CPPFLAGS)
# Build stuff
DEPS += backend_common.h
-SOURCES = backend_common.c backend_sinfonia.c $(addsuffix .c,$(addprefix backend_,$(BACKENDS)))
+SOURCES = backend_common.c backend_sinfonia.c backend_mitsu.c $(addsuffix .c,$(addprefix backend_,$(BACKENDS)))
# Dependencies for sinfonia backends..
SINFONIA_BACKENDS = sinfonia kodak605 kodak6800 shinkos1245 shinkos2145 shinkos6145 shinkos6245
SINFONIA_BACKENDS_O = $(addsuffix .o,$(addprefix backend_,$(SINFONIA_BACKENDS)))
+MITSU_BACKENDS = mitsu mitsu70x mitsu9550
+MITSU_BACKENDS_O = $(addsuffix .o,$(addprefix backend_,$(MITSU_BACKENDS)))
# And now the rules!
.PHONY: clean all install cppcheck
@@ -175,8 +177,10 @@ endif
# Backend-specific joy:
$(SINFONIA_BACKENDS_O): backend_sinfonia.h
-backend_mitsu70x.o: CPPFLAGS += -DCORRTABLE_PATH=\"$(BACKEND_DATA_DIR)\" -include lib70x/libMitsuD70ImageReProcess.h
-backend_mitsu9550.o: CPPFLAGS += -DCORRTABLE_PATH=\"$(BACKEND_DATA_DIR)\" -include lib70x/libMitsuD70ImageReProcess.h
+$(MITSU_BACKENDS_O): backend_mitsu.h
+backend_mitsu.o: CPPFLAGS += -DCORRTABLE_PATH=\"$(BACKEND_DATA_DIR)\"
+backend_mitsu70x.o: CPPFLAGS += -DCORRTABLE_PATH=\"$(BACKEND_DATA_DIR)\"
+backend_mitsu9550.o: CPPFLAGS += -DCORRTABLE_PATH=\"$(BACKEND_DATA_DIR)\"
backend_hiti.o: CPPFLAGS += -DCORRTABLE_PATH=\"$(BACKEND_DATA_DIR)\"
backend_mitsud90.o: CPPFLAGS += -DCORRTABLE_PATH=\"$(BACKEND_DATA_DIR)\"
diff --git a/backend_mitsu.c b/backend_mitsu.c
new file mode 100644
index 0000000..bcc8cfa
--- /dev/null
+++ b/backend_mitsu.c
@@ -0,0 +1,192 @@
+/*
+ * Mitsubishi Photo Printer Comon Code
+ *
+ * (c) 2013-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+
+ *
+ */
+
+#include "backend_common.h"
+#include "backend_mitsu.h"
+
+int mitsu_loadlib(struct mitsu_lib *lib, int type)
+{
+ DL_INIT();
+
+#if defined(WITH_DYNAMIC)
+ DEBUG("Attempting to load image processing library\n");
+ lib->dl_handle = DL_OPEN(LIB_NAME_RE);
+ if (!lib->dl_handle)
+ WARNING("Image processing library not found, using internal fallback code\n");
+ if (lib->dl_handle) {
+ lib->GetAPIVersion = DL_SYM(lib->dl_handle, "lib70x_getapiversion");
+ if (!lib->GetAPIVersion) {
+ ERROR("Problem resolving API Version symbol in imaging processing library, too old or not installed?\n");
+ DL_CLOSE(lib->dl_handle);
+ lib->dl_handle = NULL;
+ return CUPS_BACKEND_FAILED;
+ }
+ if (lib->GetAPIVersion() != REQUIRED_LIB_APIVERSION) {
+ ERROR("Image processing library API version mismatch!\n");
+ DL_CLOSE(lib->dl_handle);
+ lib->dl_handle = NULL;
+ return CUPS_BACKEND_FAILED;
+ }
+
+ lib->Get3DColorTable = DL_SYM(lib->dl_handle, "CColorConv3D_Get3DColorTable");
+ lib->Load3DColorTable = DL_SYM(lib->dl_handle, "CColorConv3D_Load3DColorTable");
+ lib->Destroy3DColorTable = DL_SYM(lib->dl_handle, "CColorConv3D_Destroy3DColorTable");
+ lib->DoColorConv = DL_SYM(lib->dl_handle, "CColorConv3D_DoColorConv");
+ lib->GetCPCData = DL_SYM(lib->dl_handle, "get_CPCData");
+ lib->DestroyCPCData = DL_SYM(lib->dl_handle, "destroy_CPCData");
+ lib->DoImageEffect60 = DL_SYM(lib->dl_handle, "do_image_effect60");
+ lib->DoImageEffect70 = DL_SYM(lib->dl_handle, "do_image_effect70");
+ lib->DoImageEffect80 = DL_SYM(lib->dl_handle, "do_image_effect80");
+ lib->SendImageData = DL_SYM(lib->dl_handle, "send_image_data");
+ if (!lib->Get3DColorTable || !lib->Load3DColorTable ||
+ !lib->Destroy3DColorTable || !lib->DoColorConv ||
+ !lib->GetCPCData || !lib->DestroyCPCData ||
+ !lib->DoImageEffect60 || !lib->DoImageEffect70 ||
+ !lib->DoImageEffect80 || !lib->SendImageData) {
+ ERROR("Problem resolving symbols in imaging processing library\n");
+ DL_CLOSE(lib->dl_handle);
+ lib->dl_handle = NULL;
+ return CUPS_BACKEND_FAILED;
+ } else {
+ DEBUG("Image processing library successfully loaded\n");
+ }
+ }
+
+ switch (type) {
+ case P_MITSU_D80:
+ lib->DoImageEffect = lib->DoImageEffect80;
+ break;
+ case P_MITSU_K60:
+ case P_KODAK_305:
+ lib->DoImageEffect = lib->DoImageEffect60;
+ break;
+ case P_MITSU_D70X:
+ case P_FUJI_ASK300:
+ lib->DoImageEffect = lib->DoImageEffect70;
+ break;
+ default:
+ lib->DoImageEffect = NULL;
+ }
+
+ return CUPS_BACKEND_OK;
+#else
+ return CUPS_BACKEND_FAILED;
+#endif
+}
+
+int mitsu_destroylib(struct mitsu_lib *lib)
+{
+#if defined(WITH_DYNAMIC)
+ if (lib->dl_handle) {
+ if (lib->cpcdata)
+ lib->DestroyCPCData(lib->cpcdata);
+ if (lib->ecpcdata)
+ lib->DestroyCPCData(lib->ecpcdata);
+ if (lib->lut)
+ lib->Destroy3DColorTable(lib->lut);
+ DL_CLOSE(lib->dl_handle);
+ }
+
+ memset(lib, 0, sizeof(*lib));
+ DL_EXIT();
+
+#endif
+ return CUPS_BACKEND_OK;
+}
+
+int mitsu_apply3dlut(struct mitsu_lib *lib, char *lutfname, uint8_t *databuf,
+ uint16_t cols, uint16_t rows, uint16_t stride,
+ int rgb_bgr)
+{
+#if defined(WITH_DYNAMIC)
+ int i;
+
+ if (!lutfname)
+ return CUPS_BACKEND_OK;
+
+ if (!lib->lut) {
+ uint8_t *buf = malloc(LUT_LEN);
+ if (!buf) {
+ ERROR("Memory allocation failure!\n");
+ return CUPS_BACKEND_RETRY_CURRENT;
+ }
+ if ((i = lib->Get3DColorTable(buf, lutfname))) {
+ ERROR("Unable to open LUT file '%s' (%d)\n", lutfname, i);
+ return CUPS_BACKEND_CANCEL;
+ }
+ lib->lut = lib->Load3DColorTable(buf);
+ free(buf);
+ if (!lib->lut) {
+ ERROR("Unable to parse LUT file '%s'!\n", lutfname);
+ return CUPS_BACKEND_CANCEL;
+ }
+ }
+
+ if (lib->lut) {
+ DEBUG("Running print data through 3D LUT\n");
+ lib->DoColorConv(lib->lut, databuf, cols, rows, stride, rgb_bgr);
+ }
+#endif
+ return CUPS_BACKEND_OK;
+}
+
+int mitsu_readlamdata(const char *fname, uint16_t lamstride,
+ uint8_t *databuf, uint32_t *datalen,
+ uint16_t rows, uint16_t cols, uint8_t bpp)
+{
+ int i, j, fd;
+ int remain = cols * rows * bpp;
+
+ DEBUG("Reading %d bytes of matte data from disk (%d/%d)\n", cols * rows * bpp, cols, lamstride);
+ fd = open(fname, O_RDONLY);
+ if (fd < 0) {
+ ERROR("Unable to open matte lamination data file '%s'\n", fname);
+ return CUPS_BACKEND_CANCEL;
+ }
+
+ /* Read in the matte data plane */
+ for (j = 0 ; j < rows ; j++) {
+ remain = lamstride * bpp;
+
+ /* Read one row of lamination data at a time */
+ while (remain) {
+ i = read(fd, databuf + *datalen, remain);
+ if (i < 0)
+ return CUPS_BACKEND_CANCEL;
+ if (i == 0) {
+ /* We hit EOF, restart from beginning */
+ lseek(fd, 0, SEEK_SET);
+ continue;
+ }
+ *datalen += i;
+ remain -= i;
+ }
+ /* Back off the buffer so we "wrap" on the print row. */
+ *datalen -= ((lamstride - cols) * 2);
+ }
+
+ return CUPS_BACKEND_OK;
+}
diff --git a/backend_mitsu.h b/backend_mitsu.h
new file mode 100644
index 0000000..95e401e
--- /dev/null
+++ b/backend_mitsu.h
@@ -0,0 +1,88 @@
+/*
+ * Mitsubishi Photo Printer Comon Code
+ *
+ * (c) 2013-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+
+ *
+ */
+
+#include "backend_common.h"
+
+#include "lib70x/libMitsuD70ImageReProcess.h"
+
+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);
+typedef struct CPCData *(*get_CPCDataFN)(const char *filename);
+typedef void (*destroy_CPCDataFN)(struct CPCData *data);
+typedef int (*do_image_effectFN)(struct CPCData *cpc, struct CPCData *ecpc, struct BandImage *input, struct BandImage *output, int sharpen, int reverse, uint8_t rew[2]);
+typedef int (*send_image_dataFN)(struct BandImage *out, void *context,
+ int (*callback_fn)(void *context, void *buffer, uint32_t len));
+
+#ifndef WITH_DYNAMIC
+#warning "No dynamic loading support!"
+#endif
+
+#define REQUIRED_LIB_APIVERSION 4
+
+#define LIBMITSU_VER "0.01"
+
+/* Image processing library function prototypes */
+#define LIB_NAME_RE "libMitsuD70ImageReProcess" DLL_SUFFIX
+
+#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
+
+struct mitsu_lib {
+ void *dl_handle;
+ lib70x_getapiversionFN GetAPIVersion;
+ Get3DColorTableFN Get3DColorTable;
+ Load3DColorTableFN Load3DColorTable;
+ Destroy3DColorTableFN Destroy3DColorTable;
+ DoColorConvFN DoColorConv;
+ get_CPCDataFN GetCPCData;
+ destroy_CPCDataFN DestroyCPCData;
+ do_image_effectFN DoImageEffect60;
+ do_image_effectFN DoImageEffect70;
+ do_image_effectFN DoImageEffect80;
+ do_image_effectFN DoImageEffect;
+ send_image_dataFN SendImageData;
+
+ struct CColorConv3D *lut;
+ struct CPCData *cpcdata;
+ struct CPCData *ecpcdata;
+};
+
+int mitsu_loadlib(struct mitsu_lib *lib, int type);
+int mitsu_destroylib(struct mitsu_lib *lib);
+int mitsu_apply3dlut(struct mitsu_lib *lib, char *lutfname, uint8_t *databuf,
+ uint16_t cols, uint16_t rows, uint16_t stride,
+ int rgb_bgr);
+int mitsu_readlamdata(const char *fname, uint16_t lamstride,
+ uint8_t *databuf, uint32_t *datalen,
+ uint16_t rows, uint16_t cols, uint8_t bpp);
diff --git a/backend_mitsu70x.c b/backend_mitsu70x.c
index 714e877..a0450fe 100644
--- a/backend_mitsu70x.c
+++ b/backend_mitsu70x.c
@@ -27,57 +27,13 @@
#define BACKEND mitsu70x_backend
#include "backend_common.h"
+#include "backend_mitsu.h"
/* 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);
-typedef struct CPCData *(*get_CPCDataFN)(const char *filename);
-typedef void (*destroy_CPCDataFN)(struct CPCData *data);
-typedef int (*do_image_effectFN)(struct CPCData *cpc, struct CPCData *ecpc, struct BandImage *input, struct BandImage *output, int sharpen, int reverse, uint8_t rew[2]);
-typedef int (*send_image_dataFN)(struct BandImage *out, void *context,
- int (*callback_fn)(void *context, void *buffer, uint32_t len));
-
-#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 USB_VID_MITSU 0x06D3
#define USB_PID_MITSU_D70X 0x3B30
#define USB_PID_MITSU_K60 0x3B31
@@ -100,7 +56,7 @@ struct mitsu70x_printjob {
int can_combine;
uint8_t *databuf;
- int datalen;
+ uint32_t datalen;
uint8_t *spoolbuf;
int spoolbuflen;
@@ -142,23 +98,7 @@ struct mitsu70x_ctx {
char serno[7]; /* 6+null */
char fwver[7]; /* 6+null */
- void *dl_handle;
- lib70x_getapiversionFN GetAPIVersion;
- Get3DColorTableFN Get3DColorTable;
- Load3DColorTableFN Load3DColorTable;
- Destroy3DColorTableFN Destroy3DColorTable;
- DoColorConvFN DoColorConv;
- get_CPCDataFN GetCPCData;
- destroy_CPCDataFN DestroyCPCData;
- do_image_effectFN DoImageEffect60;
- do_image_effectFN DoImageEffect70;
- do_image_effectFN DoImageEffect80;
- do_image_effectFN DoImageEffect;
- send_image_dataFN SendImageData;
-
- struct CColorConv3D *lut;
- struct CPCData *cpcdata;
- struct CPCData *ecpcdata;
+ struct mitsu_lib lib;
char *last_cpcfname;
char *last_ecpcfname;
@@ -689,8 +629,6 @@ static void *mitsu70x_init(void)
}
memset(ctx, 0, sizeof(struct mitsu70x_ctx));
- DL_INIT();
-
return ctx;
}
@@ -712,63 +650,10 @@ static int mitsu70x_attach(void *vctx, struct libusb_device_handle *dev, int typ
ctx->last_l = ctx->last_u = 65535;
- /* Attempt to open the library */
#if defined(WITH_DYNAMIC)
- 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");
- ctx->GetCPCData = DL_SYM(ctx->dl_handle, "get_CPCData");
- ctx->DestroyCPCData = DL_SYM(ctx->dl_handle, "destroy_CPCData");
- ctx->DoImageEffect60 = DL_SYM(ctx->dl_handle, "do_image_effect60");
- ctx->DoImageEffect70 = DL_SYM(ctx->dl_handle, "do_image_effect70");
- ctx->DoImageEffect80 = DL_SYM(ctx->dl_handle, "do_image_effect80");
- ctx->SendImageData = DL_SYM(ctx->dl_handle, "send_image_data");
- if (!ctx->Get3DColorTable || !ctx->Load3DColorTable ||
- !ctx->Destroy3DColorTable || !ctx->DoColorConv ||
- !ctx->GetCPCData || !ctx->DestroyCPCData ||
- !ctx->DoImageEffect60 || !ctx->DoImageEffect70 ||
- !ctx->DoImageEffect80 || !ctx->SendImageData) {
- 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");
- }
- }
-
- switch (ctx->type) {
- case P_MITSU_D80:
- ctx->DoImageEffect = ctx->DoImageEffect80;
- break;
- case P_MITSU_K60:
- case P_KODAK_305:
- ctx->DoImageEffect = ctx->DoImageEffect60;
- break;
- default:
- ctx->DoImageEffect = ctx->DoImageEffect70;
- break;
- }
+ /* Attempt to open the library */
+ if (mitsu_loadlib(&ctx->lib, ctx->type))
+ return CUPS_BACKEND_FAILED;
#else
WARNING("Dynamic library support not enabled, using internal fallback code\n");
#endif
@@ -887,17 +772,7 @@ static void mitsu70x_teardown(void *vctx) {
if (!ctx)
return;
- if (ctx->dl_handle) {
- if (ctx->cpcdata)
- ctx->DestroyCPCData(ctx->cpcdata);
- if (ctx->ecpcdata)
- ctx->DestroyCPCData(ctx->ecpcdata);
- if (ctx->lut)
- ctx->Destroy3DColorTable(ctx->lut);
- DL_CLOSE(ctx->dl_handle);
- }
-
- DL_EXIT();
+ mitsu_destroylib(&ctx->lib);
free(ctx);
}
@@ -1242,11 +1117,10 @@ repeat:
job->datalen += i;
remain -= i;
}
- goto done;
+ goto bypass_raw;
}
/* Non-RAW mode! */
-
remain = job->rows * job->cols * 3;
DEBUG("Reading in %d bytes of 8bpp BGR data\n", remain);
@@ -1273,7 +1147,7 @@ repeat:
remain -= i;
}
- if (!ctx->dl_handle) {
+ if (!ctx->lib.dl_handle) {
// XXXFALLBACK write fallback code?
ERROR("!!! Image Processing Library not found, aborting!\n");
mitsu70x_cleanup_job(job);
@@ -1281,33 +1155,18 @@ repeat:
}
/* Run through basic LUT, if present and enabled */
- if (job->lutfname && !ctx->lut) { /* printer-specific, it is fixed per-job */
- uint8_t *buf = malloc(LUT_LEN);
- if (!buf) {
- ERROR("Memory allocation failure!\n");
- mitsu70x_cleanup_job(job);
- return CUPS_BACKEND_RETRY_CURRENT;
- }
- if ((i = ctx->Get3DColorTable(buf, job->lutfname))) {
- ERROR("Unable to open LUT file '%s' (%d)\n", job->lutfname, i);
+ if (job->lutfname) {
+ int ret = mitsu_apply3dlut(&ctx->lib, job->lutfname,
+ job->databuf, job->cols,
+ job->rows, job->cols * 3,
+ COLORCONV_BGR);
+ if (ret) {
mitsu70x_cleanup_job(job);
- return CUPS_BACKEND_CANCEL;
+ return ret;
}
- ctx->lut = ctx->Load3DColorTable(buf);
- free(buf);
- if (!ctx->lut) {
- ERROR("Unable to parse LUT file '%s'!\n", job->lutfname);
- mitsu70x_cleanup_job(job);
- return CUPS_BACKEND_CANCEL;
- }
- }
-
- if (job->lutfname && ctx->lut) {
- DEBUG("Running print data through 3D LUT\n");
- ctx->DoColorConv(ctx->lut, job->spoolbuf, job->cols, job->rows, job->cols * 3, COLORCONV_BGR);
}
-done:
+bypass_raw:
for (i = 0 ; i < ctx->num_decks ; i++) {
switch (ctx->medias[i]) {
case 0x1: // 5x3.5
@@ -1729,10 +1588,10 @@ static int mitsu70x_main_loop(void *vctx, const void *vjob)
/* Load in the CPC file, if needed */
if (job->cpcfname && job->cpcfname != ctx->last_cpcfname) {
ctx->last_cpcfname = job->cpcfname;
- if (ctx->cpcdata)
- ctx->DestroyCPCData(ctx->cpcdata);
- ctx->cpcdata = ctx->GetCPCData(job->cpcfname);
- if (!ctx->cpcdata) {
+ if (ctx->lib.cpcdata)
+ ctx->lib.DestroyCPCData(ctx->lib.cpcdata);
+ ctx->lib.cpcdata = ctx->lib.GetCPCData(job->cpcfname);
+ if (!ctx->lib.cpcdata) {
ERROR("Unable to load CPC file '%s'\n", job->cpcfname);
return CUPS_BACKEND_CANCEL;
}
@@ -1741,16 +1600,16 @@ static int mitsu70x_main_loop(void *vctx, const void *vjob)
/* Load in the secondary CPC, if needed */
if (job->ecpcfname != ctx->last_ecpcfname) {
ctx->last_ecpcfname = job->ecpcfname;
- if (ctx->ecpcdata)
- ctx->DestroyCPCData(ctx->ecpcdata);
+ if (ctx->lib.ecpcdata)
+ ctx->lib.DestroyCPCData(ctx->lib.ecpcdata);
if (job->ecpcfname) {
- ctx->ecpcdata = ctx->GetCPCData(job->ecpcfname);
- if (!ctx->ecpcdata) {
+ ctx->lib.ecpcdata = ctx->lib.GetCPCData(job->ecpcfname);
+ if (!ctx->lib.ecpcdata) {
ERROR("Unable to load CPC file '%s'\n", job->cpcfname);
return CUPS_BACKEND_CANCEL;
}
} else {
- ctx->ecpcdata = NULL;
+ ctx->lib.ecpcdata = NULL;
}
}
@@ -1768,8 +1627,8 @@ static int mitsu70x_main_loop(void *vctx, const void *vjob)
ctx->output.bytes_per_row = job->cols * 3 * 2;
DEBUG("Running print data through processing library\n");
- if (ctx->DoImageEffect(ctx->cpcdata, ctx->ecpcdata,
- &input, &ctx->output, job->sharpen, job->reverse, rew)) {
+ 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;
}
@@ -1792,40 +1651,17 @@ static int mitsu70x_main_loop(void *vctx, const void *vjob)
/* Now that we've filled everything in, read matte from file */
if (job->matte) {
- int fd;
- uint32_t j;
- DEBUG("Reading %u bytes of matte data from disk (%d/%d)\n", job->matte, job->cols, LAMINATE_STRIDE);
- fd = open(job->laminatefname, O_RDONLY);
- if (fd < 0) {
- ERROR("Unable to open matte lamination data file '%s'\n", job->laminatefname);
- return CUPS_BACKEND_CANCEL;
- }
+ int ret;
- for (j = 0 ; j < be16_to_cpu(hdr->lamrows) ; j++) {
- int remain = LAMINATE_STRIDE * 2;
-
- /* Read one row of lamination data at a time */
- while (remain) {
- int 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);
+ 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. */
- j = be16_to_cpu(hdr->lamcols) * be16_to_cpu(hdr->lamrows) * 2;
- memset(job->databuf + job->datalen, 0, job->matte - j);
+ ret = be16_to_cpu(hdr->lamcols) * be16_to_cpu(hdr->lamrows) * 2;
+ memset(job->databuf + job->datalen, 0, job->matte - ret);
}
bypass:
@@ -2032,8 +1868,8 @@ top:
sizeof(struct mitsu70x_hdr))))
return CUPS_BACKEND_FAILED;
- if (ctx->dl_handle && !job->raw_format) {
- if (ctx->SendImageData(&ctx->output, ctx, d70_library_callback))
+ if (ctx->lib.dl_handle && !job->raw_format) {
+ if (ctx->lib.SendImageData(&ctx->output, ctx, d70_library_callback))
return CUPS_BACKEND_FAILED;
if (job->matte)
@@ -2554,7 +2390,7 @@ static const char *mitsu70x_prefixes[] = {
/* Exported */
struct dyesub_backend mitsu70x_backend = {
.name = "Mitsubishi CP-D70 family",
- .version = "0.97",
+ .version = "0.98" " (lib " LIBMITSU_VER ")",
.flags = BACKEND_FLAG_DUMMYPRINT,
.uri_prefixes = mitsu70x_prefixes,
.cmdline_usage = mitsu70x_cmdline,
diff --git a/backend_mitsu9550.c b/backend_mitsu9550.c
index da18f71..5431c52 100644
--- a/backend_mitsu9550.c
+++ b/backend_mitsu9550.c
@@ -27,52 +27,13 @@
#define BACKEND mitsu9550_backend
#include "backend_common.h"
+#include "backend_mitsu.h"
/* 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"
@@ -212,14 +173,7 @@ struct mitsu9550_ctx {
struct marker marker;
/* CP98xx stuff */
- void *dl_handle;
- lib70x_getapiversionFN GetAPIVersion;
- Get3DColorTableFN Get3DColorTable;
- Load3DColorTableFN Load3DColorTable;
- Destroy3DColorTableFN Destroy3DColorTable;
- DoColorConvFN DoColorConv;
-
- struct CColorConv3D *lut;
+ struct mitsu_lib lib;
struct mitsu98xx_tables *m98xxdata;
};
@@ -322,16 +276,7 @@ static void mitsu98xx_dogamma(uint8_t *src, uint16_t *dest, uint8_t plane,
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;
- }
+ int ret;
/* Fill in the lamination plane header */
struct mitsu9550_plane *matte = (struct mitsu9550_plane *)(job->databuf + job->datalen);
@@ -345,28 +290,11 @@ static int mitsu98xx_fillmatte(struct mitsu9550_printjob *job)
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);
+ ret = mitsu_readlamdata(MITSU_M98xx_LAMINATE_FILE, LAMINATE_STRIDE,
+ job->databuf, &job->datalen,
+ job->rows, job->cols, 2);
+ if (ret)
+ return ret;
/* Fill in the lamination plane footer */
job->databuf[job->datalen++] = 0x1b;
@@ -374,16 +302,9 @@ static int mitsu98xx_fillmatte(struct mitsu9550_printjob *job)
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);
@@ -396,8 +317,6 @@ static void *mitsu9550_init(void)
}
memset(ctx, 0, sizeof(struct mitsu9550_ctx));
- DL_INIT();
-
return ctx;
}
@@ -424,46 +343,15 @@ static int mitsu9550_attach(void *vctx, struct libusb_device_handle *dev, int ty
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:
+#if defined(WITH_DYNAMIC)
+ /* Attempt to open the library */
+ if (mitsu_loadlib(&ctx->lib, ctx->type))
+ return CUPS_BACKEND_FAILED;
+#else
+ WARNING("Dynamic library support not enabled, using internal fallback code\n");
#endif
-
+skip:
if (test_mode < TEST_MODE_NOATTACH) {
if (mitsu9550_get_status(ctx, (uint8_t*) &media, 0, 0, 1))
return CUPS_BACKEND_FAILED;
@@ -502,13 +390,10 @@ static void mitsu9550_teardown(void *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);
- }
+ if (ctx->m98xxdata)
+ free(ctx->m98xxdata);
+
+ mitsu_destroylib(&ctx->lib);
free(ctx);
}
@@ -796,38 +681,15 @@ hdr_done:
/* Apply LUT, if job calls for it.. */
if (ctx->is_98xx && !job->is_raw && job->hdr2.unkc[9]) {
-
- if (!ctx->dl_handle) {
- // XXXFALLBACK write fallback code?
- ERROR("!!! Image Processing Library not found, aborting!\n");
+ int ret = mitsu_apply3dlut(&ctx->lib, MITSU_M98xx_LUT_FILE,
+ job->databuf + sizeof(struct mitsu9550_plane),
+ job->cols, job->rows,
+ job->cols * 3, COLORCONV_BGR);
+ if (ret) {
mitsu9550_cleanup_job(job);
- return CUPS_BACKEND_CANCEL;
- }
-
- if (!ctx->lut) {
- uint8_t *lbuf = malloc(LUT_LEN);
- if (!lbuf) {
- ERROR("Memory allocation failure!\n");
- mitsu9550_cleanup_job(job);
- return CUPS_BACKEND_RETRY_CURRENT;
- }
- if (ctx->Get3DColorTable(lbuf, MITSU_M98xx_LUT_FILE)) {
- ERROR("Unable to open LUT file '%s'\n", MITSU_M98xx_LUT_FILE);
- mitsu9550_cleanup_job(job);
- return CUPS_BACKEND_CANCEL;
- }
- ctx->lut = ctx->Load3DColorTable(lbuf);
- free(lbuf);
- if (!ctx->lut) {
- ERROR("Unable to parse LUT\n");
- mitsu9550_cleanup_job(job);
- return CUPS_BACKEND_CANCEL;
- }
+ return ret;
}
- DEBUG("Running print data through 3D LUT\n");
- ctx->DoColorConv(ctx->lut, job->databuf + sizeof(struct mitsu9550_plane),
- job->cols, job->rows, job->cols * 3, COLORCONV_BGR);
job->hdr2.unkc[9] = 0;
}
@@ -1675,7 +1537,7 @@ static const char *mitsu9550_prefixes[] = {
/* Exported */
struct dyesub_backend mitsu9550_backend = {
.name = "Mitsubishi CP9xxx family",
- .version = "0.49",
+ .version = "0.50" " (lib " LIBMITSU_VER ")",
.uri_prefixes = mitsu9550_prefixes,
.cmdline_usage = mitsu9550_cmdline,
.cmdline_arg = mitsu9550_cmdline_arg,
diff --git a/backend_mitsud90.c b/backend_mitsud90.c
index fb0aa89..ce8f00e 100644
--- a/backend_mitsud90.c
+++ b/backend_mitsud90.c
@@ -27,6 +27,7 @@
#define BACKEND mitsud90_backend
#include "backend_common.h"
+#include "backend_mitsu.h"
#define USB_VID_MITSU 0x06D3
#define USB_PID_MITSU_D90 0x3B60
@@ -411,7 +412,7 @@ static void mitsud90_dump_status(struct mitsud90_status_resp *resp)
/* Private data structure */
struct mitsud90_printjob {
uint8_t *databuf;
- int datalen;
+ uint32_t datalen;
int copies;
};
@@ -1311,7 +1312,7 @@ static const char *mitsud90_prefixes[] = {
/* Exported */
struct dyesub_backend mitsud90_backend = {
.name = "Mitsubishi CP-D90DW",
- .version = "0.17",
+ .version = "0.17" " (lib " LIBMITSU_VER ")",
.uri_prefixes = mitsud90_prefixes,
.cmdline_arg = mitsud90_cmdline_arg,
.cmdline_usage = mitsud90_cmdline,
@@ -1742,43 +1743,19 @@ done_free:
static int cpm1_fillmatte(struct mitsud90_printjob *job)
{
- int fd, i, j;
- struct mitsud90_job_hdr *hdr = (struct mitsud90_job_hdr *) job->databuf;
+ int ret;
- DEBUG("Reading %d bytes of matte data from disk (%d/%d)\n", be16_to_cpu(hdr->cols) * be16_to_cpu(hdr->rows), be16_to_cpu(hdr->cols), LAMINATE_STRIDE);
- fd = open(MITSU_CPM1_LAMINATE_FILE, O_RDONLY);
- if (fd < 0) {
- WARNING("Unable to open matte lamination data file '%s'\n", MITSU_CPM1_LAMINATE_FILE);
- hdr->overcoat = 0;
- goto done;
- }
+ struct mitsud90_job_hdr *hdr = (struct mitsud90_job_hdr *) job->databuf;
// XXX fill out lamination header?
+ ret = mitsu_readlamdata(MITSU_CPM1_LAMINATE_FILE, LAMINATE_STRIDE,
+ job->databuf, &job->datalen,
+ be16_to_cpu(hdr->rows), be16_to_cpu(hdr->cols), 1);
- /* Read in the matte data */
- for (j = 0; j < be16_to_cpu(hdr->rows) ; j++) {
- int remain = LAMINATE_STRIDE;
-
- /* Read in one row at a time */
- while(remain) {
- i = read(fd, job->databuf + job->datalen, remain);
- if (i < 0)
- return CUPS_BACKEND_CANCEL;
- if (i == 0) {
- lseek(fd, 0, SEEK_SET);
- continue;
- }
- job->datalen += i;
- remain -= i;
- }
- /* Back off the buffer so we "wrap" on the row. */
- job->datalen -= (LAMINATE_STRIDE - be16_to_cpu(hdr->cols));
- }
- /* All done */
- close(fd);
+ if (ret)
+ return ret;
// XXX fill out footer?
-done:
return CUPS_BACKEND_OK;
}