diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2020-08-24 18:45:55 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2020-08-24 18:45:55 +0200 |
commit | a77bc1fcbdf83cfdac9570c0a0ac886b5534c90f (patch) | |
tree | d839746371ecb8ed64ac81d2e37c11fcd25a00ac /backend/pixma/pixma_mp150.c | |
parent | 787fb1d54ec9ee5fb941ae897fb201feb9cb2fd1 (diff) | |
parent | 2b3e02411ecc09e7d41741b5587655c9b2f955b7 (diff) |
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'backend/pixma/pixma_mp150.c')
-rw-r--r-- | backend/pixma/pixma_mp150.c | 192 |
1 files changed, 131 insertions, 61 deletions
diff --git a/backend/pixma/pixma_mp150.c b/backend/pixma/pixma_mp150.c index 3973702..b438c1b 100644 --- a/backend/pixma/pixma_mp150.c +++ b/backend/pixma/pixma_mp150.c @@ -1,6 +1,6 @@ /* SANE - Scanner Access Now Easy. - Copyright (C) 2011-2019 Rolf Bensch <rolf at bensch hyphen online dot de> + Copyright (C) 2011-2020 Rolf Bensch <rolf at bensch hyphen online dot de> Copyright (C) 2007-2009 Nicolas Martin, <nicols-guest at alioth dot debian dot org> Copyright (C) 2006-2007 Wittawat Yamwong <wittawat@web.de> @@ -85,7 +85,6 @@ 4096 = size of gamma table. 24 = header + checksum */ #define IMAGE_BLOCK_SIZE (512*1024) #define CMDBUF_SIZE (4096 + 24) -#define DEFAULT_GAMMA 2.0 /***** Gamma different from 1.0 is potentially impacting color profile generation *****/ #define UNKNOWN_PID 0xffff @@ -282,8 +281,10 @@ #define TS8230_PID 0x185b #define TS9580_PID 0x185d #define TR9530_PID 0x185e +#define G7000_PID 0x1863 #define G6000_PID 0x1865 #define G6080_PID 0x1866 +#define GM4000_PID 0x1869 #define XK80_PID 0x1873 #define TS5300_PID 0x188b #define TS5380_PID 0x188c @@ -321,8 +322,6 @@ <ivec:param_set servicetype=\"scan\"><ivec:jobID>00000001</ivec:jobID>\ </ivec:param_set></ivec:contents></cmd>" -#define XML_OK "<ivec:response>OK</ivec:response>" - enum mp150_state_t { state_idle, @@ -460,7 +459,7 @@ send_xml_dialog (pixma_t * s, const char * xml_message) PDBG (pixma_dbg (10, "XML message sent to scanner:\n%s\n", xml_message)); PDBG (pixma_dbg (10, "XML response back from scanner:\n%s\n", mp->cb.buf)); - return (strcasestr ((const char *) mp->cb.buf, XML_OK) != NULL); + return pixma_parse_xml_response((const char*)mp->cb.buf) == PIXMA_STATUS_OK; } static int @@ -567,42 +566,45 @@ send_gamma_table (pixma_t * s) const uint8_t *lut = s->param->gamma_table; uint8_t *data; - if (mp->generation == 1) + if (s->cfg->cap & PIXMA_CAP_GT_4096) { data = pixma_newcmd (&mp->cb, cmd_gamma, 4096 + 8, 0); data[0] = (s->param->channels == 3) ? 0x10 : 0x01; pixma_set_be16 (0x1004, data + 2); if (lut) - memcpy (data + 4, lut, 4096); + { + /* PDBG (pixma_dbg (4, "*send_gamma_table***** Use 4096 bytes from LUT ***** \n")); */ + /* PDBG (pixma_hexdump (4, lut, 4096)); */ + memcpy (data + 4, lut, 4096); + } else - pixma_fill_gamma_table (DEFAULT_GAMMA, data + 4, 4096); + { + /* fallback: we should never see this */ + PDBG (pixma_dbg (4, "*send_gamma_table***** Generate 4096 bytes Table with %f ***** \n", + s->param->gamma)); + pixma_fill_gamma_table (s->param->gamma, data + 4, 4096); + /* PDBG (pixma_hexdump (4, data + 4, 4096)); */ + } } else { - /* FIXME: Gamma table for 2nd generation: 1024 * uint16_le */ - data = pixma_newcmd (&mp->cb, cmd_gamma, 2048 + 8, 0); + /* Gamma table for 2nd+ generation: 1024 * uint16_le */ + data = pixma_newcmd (&mp->cb, cmd_gamma, 1024 * 2 + 8, 0); data[0] = 0x10; pixma_set_be16 (0x0804, data + 2); if (lut) { - int i; - for (i = 0; i < 1024; i++) - { - int j = (i << 2) + (i >> 8); - data[4 + 2 * i + 0] = lut[j]; - data[4 + 2 * i + 1] = lut[j]; - } + /* PDBG (pixma_dbg (4, "*send_gamma_table***** Use 1024 * 2 bytes from LUT ***** \n")); */ + /* PDBG (pixma_hexdump (4, lut, 1024 * 2)); */ + memcpy (data + 4, lut, 1024 * 2); } else { - int i; - pixma_fill_gamma_table (DEFAULT_GAMMA, data + 4, 2048); - for (i = 0; i < 1024; i++) - { - int j = (i << 1) + (i >> 9); - data[4 + 2 * i + 0] = data[4 + j]; - data[4 + 2 * i + 1] = data[4 + j]; - } + /* fallback: we should never see this */ + PDBG (pixma_dbg (4, "*send_gamma_table***** Generate 1024 * 2 Table with %f ***** \n", + s->param->gamma)); + pixma_fill_gamma_table (s->param->gamma, data + 4, 1024); + /* PDBG (pixma_hexdump (4, data + 4, 1024 * 2)); */ } } return pixma_exec (s, &mp->cb); @@ -631,6 +633,12 @@ calc_raw_width (const mp150_t * mp, const pixma_scan_param_t * param) return raw_width; } +static int +is_gray_16 (pixma_t * s) +{ + return (s->param->mode == PIXMA_SCAN_MODE_GRAY_16); +} + static unsigned get_cis_line_size (pixma_t * s) { @@ -640,7 +648,9 @@ get_cis_line_size (pixma_t * s) __func__, s->param->line_size, s->param->w, s->param->wx, mp->scale));*/ return (s->param->wx ? s->param->line_size / s->param->w * s->param->wx - : s->param->line_size) * mp->scale; + : s->param->line_size) + * mp->scale + * (is_gray_16(s) ? 3 : 1); } static int @@ -705,10 +715,12 @@ send_scan_param (pixma_t * s) pixma_set_be32 (y, data + 0x10); pixma_set_be32 (wx, data + 0x14); pixma_set_be32 (h, data + 0x18); - data[0x1c] = (s->param->channels != 1) ? 0x08 : 0x04; + /*PDBG (pixma_dbg (4, "*send_scan_param gen. 3+ ***** Setting: channels=%hi depth=%hi ***** \n", + s->param->channels, s->param->depth));*/ + data[0x1c] = ((s->param->channels != 1) || (is_gray_16(s)) ? 0x08 : 0x04); data[0x1d] = ((s->param->software_lineart) ? 8 : s->param->depth) - * s->param->channels; /* bits per pixel */ + * (is_gray_16(s) ? 3 : s->param->channels); /* bits per pixel */ data[0x1f] = 0x01; /* This one also seen at 0. Don't know yet what's used for */ data[0x20] = 0xff; @@ -902,7 +914,8 @@ handle_interrupt (pixma_t * s, int timeout) || s->cfg->pid == MX920_PID || s->cfg->pid == MB2300_PID || s->cfg->pid == MB5000_PID - || s->cfg->pid == MB5400_PID) + || s->cfg->pid == MB5400_PID + || s->cfg->pid == TR4500_PID) /* button no. in buf[7] * size in buf[10] 01=A4; 02=Letter; 08=10x15; 09=13x18; 0b=auto * format in buf[11] 01=JPEG; 02=TIFF; 03=PDF; 04=Kompakt-PDF @@ -910,18 +923,45 @@ handle_interrupt (pixma_t * s, int timeout) * target = format; original = size; scan-resolution = dpi */ { if (buf[7] & 1) - s->events = PIXMA_EV_BUTTON1 | buf[11] | buf[10]<<8 | buf[12]<<16; /* color scan */ + { + /* color scan */ + s->events = PIXMA_EV_BUTTON1 | (buf[11] & 0x0f) | (buf[10] & 0x0f) << 8 + | (buf[12] & 0x0f) << 16; + } if (buf[7] & 2) - s->events = PIXMA_EV_BUTTON2 | buf[11] | buf[10]<<8 | buf[12]<<16; /* b/w scan */ + { + /* b/w scan */ + s->events = PIXMA_EV_BUTTON2 | (buf[11] & 0x0f) | (buf[10] & 0x0f) << 8 + | (buf[12] & 0x0f) << 16; + } + + /* some scanners provide additional information: + * document type in buf[6] 01=Document; 02=Photo; 03=Auto Scan + * ADF status in buf[8] 01 = ADF empty; 02 = ADF filled + * ADF orientation in buf[16] 01=Portrait; 02=Landscape */ + if (s->cfg->pid == TR4500_PID) + { + s->events |= (buf[6] & 0x0f) << 12; + s->events |= (buf[8] & 0x0f) << 20; + s->events |= (buf[16] & 0x0f) << 4; + } } else if (s->cfg->pid == LIDE300_PID || s->cfg->pid == LIDE400_PID) /* unknown value in buf[4] - * target in buf[0x13] - * always set button-1 */ + * target in buf[0x13] 01=copy; 02=auto; 03=send; 05=start PDF; 06=finish PDF + * "Finish PDF" is Button-2, all others are Button-1 */ { - if (buf[0x13]) - s->events = PIXMA_EV_BUTTON1 | buf[0x13]; + if (buf[0x13] == 0x06) + { + /* button 2 = cancel / end scan */ + s->events = PIXMA_EV_BUTTON2 | (buf[0x13] & 0x0f); + } + else if (buf[0x13]) + { + /* button 1 = start scan */ + s->events = PIXMA_EV_BUTTON1 | (buf[0x13] & 0x0f); + } } else /* button no. in buf[0] @@ -937,9 +977,15 @@ handle_interrupt (pixma_t * s, int timeout) if (buf[9] & 2) query_status (s); if (buf[0] & 2) - s->events = PIXMA_EV_BUTTON2 | buf[1] | ((buf[0] & 0xf0) << 4); /* b/w scan */ + { + /* b/w scan */ + s->events = PIXMA_EV_BUTTON2 | (buf[1] & 0x0f) | (buf[0] & 0xf0) << 4; + } if (buf[0] & 1) - s->events = PIXMA_EV_BUTTON1 | buf[1] | ((buf[0] & 0xf0) << 4); /* color scan */ + { + /* color scan */ + s->events = PIXMA_EV_BUTTON1 | (buf[1] & 0x0f) | ((buf[0] & 0xf0) << 4); + } } return 1; } @@ -1062,7 +1108,7 @@ post_process_image_data (pixma_t * s, pixma_imagebuf_t * ib) } /* process image sizes */ - c = s->param->channels + c = (is_gray_16(s) ? 3 : s->param->channels) * ((s->param->software_lineart) ? 8 : s->param->depth) / 8; /* color channels count */ cw = c * s->param->w; /* image width */ cx = c * s->param->xs; /* x-offset */ @@ -1104,7 +1150,6 @@ post_process_image_data (pixma_t * s, pixma_imagebuf_t * ib) * MP220, MX360 and generation 5 scanners are exceptions */ if (n > 1 && s->cfg->pid != MP220_PID - && s->cfg->pid != MP490_PID && s->cfg->pid != MX360_PID && (mp->generation < 5 /* generation 5 scanners *with* special image format */ @@ -1136,6 +1181,9 @@ post_process_image_data (pixma_t * s, pixma_imagebuf_t * ib) /* Color / Gray to Lineart convert */ if (s->param->software_lineart) cptr = gptr = pixma_binarize_line (s->param, gptr, cptr, s->param->w, c); + /* Color to Grayscale convert for 16bit gray */ + else if (is_gray_16(s)) + cptr = gptr = pixma_rgb_to_gray (gptr, cptr, s->param->w, c); else cptr += cw; } @@ -1218,22 +1266,41 @@ mp150_check_param (pixma_t * s, pixma_scan_param_t * sp) { mp150_t *mp = (mp150_t *) s->subdriver; - /* PDBG (pixma_dbg (4, "*mp150_check_param***** Initially: channels=%u, depth=%u, x=%u, y=%u, w=%u, h=%u, xs=%u, wx=%u *****\n", - sp->channels, sp->depth, sp->x, sp->y, sp->w, sp->h, sp->xs, sp->wx)); */ + /* PDBG (pixma_dbg (4, "*mp150_check_param***** Initially: channels=%u, depth=%u, x=%u, y=%u, w=%u, h=%u, xs=%u, wx=%u, gamma=%f *****\n", + sp->channels, sp->depth, sp->x, sp->y, sp->w, sp->h, sp->xs, sp->wx, sp->gamma)); */ - /* MP150 only supports 8 bit per channel in color and grayscale mode */ - if (sp->depth != 1) - { - sp->software_lineart = 0; + sp->channels = 3; + sp->software_lineart = 0; + switch (sp->mode) + { + /* standard scan modes + * 8 bit per channel in color and grayscale mode */ + case PIXMA_SCAN_MODE_GRAY: + sp->channels = 1; + /* fall through */ + case PIXMA_SCAN_MODE_COLOR: sp->depth = 8; - } - else - { - /* software lineart */ + break; + /* extended scan modes for 48 bit flatbed scanners + * 16 bit per channel in color and grayscale mode */ + case PIXMA_SCAN_MODE_GRAY_16: + sp->channels = 1; + sp->depth = 16; + break; + case PIXMA_SCAN_MODE_COLOR_48: + sp->channels = 3; + sp->depth = 16; + break; + /* software lineart + * 1 bit per channel */ + case PIXMA_SCAN_MODE_LINEART: sp->software_lineart = 1; - sp->depth = 1; sp->channels = 1; - } + sp->depth = 1; + break; + default: + break; + } /* for software lineart w must be a multiple of 8 */ if (sp->software_lineart == 1 && sp->w % 8) @@ -1596,6 +1663,7 @@ static const pixma_scan_ops_t pixma_mp150_ops = { 0, /* iface */ \ &pixma_mp150_ops, /* ops */ \ min_dpi, /* min_xdpi */ \ + 0, /* min_xdpi_16 not used in this subdriver */ \ dpi, 2*(dpi), /* xdpi, ydpi */ \ adftpu_min_dpi, adftpu_max_dpi, /* adftpu_min_dpi, adftpu_max_dpi */ \ 0, 0, /* tpuir_min_dpi & tpuir_max_dpi not used in this subdriver */ \ @@ -1610,11 +1678,11 @@ static const pixma_scan_ops_t pixma_mp150_ops = { const pixma_config_t pixma_mp150_devices[] = { /* Generation 1: CIS */ - DEVICE ("Canon PIXMA MP150", "MP150", MP150_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), - DEVICE ("Canon PIXMA MP170", "MP170", MP170_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), - DEVICE ("Canon PIXMA MP450", "MP450", MP450_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), - DEVICE ("Canon PIXMA MP500", "MP500", MP500_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), - DEVICE ("Canon PIXMA MP530", "MP530", MP530_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA MP150", "MP150", MP150_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_GT_4096), + DEVICE ("Canon PIXMA MP170", "MP170", MP170_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_GT_4096), + DEVICE ("Canon PIXMA MP450", "MP450", MP450_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_GT_4096), + DEVICE ("Canon PIXMA MP500", "MP500", MP500_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_GT_4096), + DEVICE ("Canon PIXMA MP530", "MP530", MP530_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_GT_4096 | PIXMA_CAP_ADF), /* Generation 2: CIS */ DEVICE ("Canon PIXMA MP140", "MP140", MP140_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), @@ -1675,7 +1743,7 @@ const pixma_config_t pixma_mp150_devices[] = { /* Latest devices (2010) Generation 4 CIS */ DEVICE ("Canon PIXMA MP280", "MP280", MP280_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), /* TODO: 1200dpi doesn't work yet */ - DEVICE ("Canon PIXMA MP495", "MP495", MP495_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA MP495", "MP495", MP495_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), /* ToDo: max. scan resolution = 1200x600dpi */ DEVICE ("Canon PIXMA MG5100", "MG5100", MG5100_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA MG5200", "MG5200", MG5200_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA MG6100", "MG6100", MG6100_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS), @@ -1765,12 +1833,12 @@ const pixma_config_t pixma_mp150_devices[] = { /* Latest devices (2018) Generation 5 CIS */ DEVICE ("Canon MAXIFY MB5400 Series", "MB5400", MB5400_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP | PIXMA_CAP_ADF_JPEG), - DEVICE ("Canon MAXIFY MB5100 Series", "MB5100", MB5100_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP), + DEVICE ("Canon MAXIFY MB5100 Series", "MB5100", MB5100_PID, 0, 1200, 0, 0, 638, 1050, PIXMA_CAP_CIS | PIXMA_CAP_ADFDUP | PIXMA_CAP_ADF_JPEG), DEVICE ("Canon PIXMA TS9100 Series", "TS9100", TS9100_PID, 0, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS), - DEVICE ("Canon PIXMA TR8500 Series", "TR8500", TR8500_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA TR8500 Series", "TR8500", TR8500_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF | PIXMA_CAP_ADF_JPEG), DEVICE ("Canon PIXMA TR7500 Series", "TR7500", TR7500_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), DEVICE ("Canon PIXMA TS9500 Series", "TS9500", TS9500_PID, 0, 1200, 0, 600, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), - DEVICE ("CanoScan LiDE 400", "LIDE400", LIDE400_PID, 300, 4800, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("CanoScan LiDE 400", "LIDE400", LIDE400_PID, 300, 4800, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_48BIT), DEVICE ("CanoScan LiDE 300", "LIDE300", LIDE300_PID, 300, 2400, 0, 0, 638, 877, PIXMA_CAP_CIS), /* Latest devices (2019) Generation 5 CIS */ @@ -1788,7 +1856,7 @@ const pixma_config_t pixma_mp150_devices[] = { DEVICE ("Canon PIXMA TR7530 Series", "TR7530", TR7530_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), DEVICE ("Canon PIXUS XK50 Series", "XK50", XK50_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXUS XK70 Series", "XK70", XK70_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), - DEVICE ("Canon PIXMA TR4500 Series", "TR4500", TR4500_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA TR4500 Series", "TR4500", TR4500_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF | PIXMA_CAP_ADF_JPEG), /* ToDo: max. scan resolution = 600x1200dpi */ DEVICE ("Canon PIXMA E4200 Series", "E4200", E4200_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), DEVICE ("Canon PIXMA TS6200 Series", "TS6200", TS6200_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA TS6280 Series", "TS6280", TS6280_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), @@ -1798,8 +1866,10 @@ const pixma_config_t pixma_mp150_devices[] = { DEVICE ("Canon PIXMA TS8230 Series", "TS8230", TS8230_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA TS9580 Series", "TS9580", TS9580_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), DEVICE ("Canon PIXMA TR9530 Series", "TR9530", TR9530_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), + DEVICE ("Canon PIXMA G7000 Series", "G7000", G7000_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), /* ToDo: ADF has legal paper length */ DEVICE ("Canon PIXMA G6000 Series", "G6000", G6000_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA G6080 Series", "G6080", G6080_PID, 0, 600, 0, 0, 638, 877, PIXMA_CAP_CIS), + DEVICE ("Canon PIXMA GM4000 Series", "GM4000", GM4000_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS | PIXMA_CAP_ADF), /* ToDo: ADF has legal paper length */ DEVICE ("Canon PIXUS XK80 Series", "XK80", XK80_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA TS5300 Series", "TS5300", TS5300_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), DEVICE ("Canon PIXMA TS5380 Series", "TS5380", TS5380_PID, 0, 1200, 0, 0, 638, 877, PIXMA_CAP_CIS), |