| 1 |
/* |
| 2 |
* HiTi Photo Printer CUPS backend |
| 3 |
* |
| 4 |
* (c) 2019-2026 Solomon Peachy <[email protected]> |
| 5 |
* |
| 6 |
* The latest version of this program can be found at: |
| 7 |
* |
| 8 |
* https://git.shaftnet.org/gitea/slp/selphy_print.git |
| 9 |
* |
| 10 |
* This program is free software; you can redistribute it and/or modify it |
| 11 |
* under the terms of the GNU General Public License as published by the Free |
| 12 |
* Software Foundation; either version 2 of the License, or (at your option) |
| 13 |
* any later version. |
| 14 |
* |
| 15 |
* This program is distributed in the hope that it will be useful, but |
| 16 |
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 17 |
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 18 |
* for more details. |
| 19 |
* |
| 20 |
* You should have received a copy of the GNU General Public License |
| 21 |
* along with this program; if not, see <https://www.gnu.org/licenses/>. |
| 22 |
* |
| 23 |
* SPDX-License-Identifier: GPL-2.0+ |
| 24 |
* |
| 25 |
*/ |
| 26 |
|
| 27 |
#define BACKEND hiti_backend |
| 28 |
|
| 29 |
#include "backend_common.h" |
| 30 |
|
| 31 |
/* For Integration into gutenprint */ |
| 32 |
#if defined(HAVE_CONFIG_H) |
| 33 |
#include <config.h> |
| 34 |
#endif |
| 35 |
|
| 36 |
// We should use nanosleep everywhere properly. |
| 37 |
#define __usleep(__x) { struct timespec t = { 0, (__x) * 1000 } ; nanosleep (&t, NULL); } |
| 38 |
|
| 39 |
/* Private structures */ |
| 40 |
struct hiti_cmd { |
| 41 |
uint8_t hdr; /* 0xa5 */ |
| 42 |
uint16_t len; /* (BE) everything after this field, minimum 3, max 64 */ |
| 43 |
uint8_t flag; /* see CMD_FLAG_* -- MUST include CMD_FLAG_DEST */ |
| 44 |
uint16_t cmd; /* CMD_* (BE) */ |
| 45 |
uint8_t payload[]; /* 0-61 items */ |
| 46 |
} __attribute__((packed)); |
| 47 |
|
| 48 |
struct hiti_cmd_lun { |
| 49 |
uint8_t hdr; /* 0xa5 */ |
| 50 |
uint16_t len; /* (BE) everything after this field, minimum 4, max 64 */ |
| 51 |
uint8_t flag; /* see CMD_FLAG_* -- MUST NOT include CMD_FLAG_DEST */ |
| 52 |
uint8_t lun; |
| 53 |
uint16_t cmd; /* CMD_* (BE) */ |
| 54 |
uint8_t payload[]; /* 0-60 items */ |
| 55 |
} __attribute__((packed)); |
| 56 |
|
| 57 |
#define CMD_FLAG_NOP_ERR 0x80 |
| 58 |
#define CMD_FLAG_DEST 0x40 |
| 59 |
#define CMD_FLAG_CONTINUE 0x20 |
| 60 |
#define CMD_FLAG_REPLY 0x10 |
| 61 |
|
| 62 |
#define CMD_FLAG_CHK_MASK 0x8c |
| 63 |
#define CMD_FLAG_CHK_OK 0x00 |
| 64 |
#define CMD_FLAG_CHK_REJECTED 0x80 // no errors, but rejected |
| 65 |
#define CMD_FLAG_CHK_DATAERR 0x84 // error in data stream |
| 66 |
#define CMD_FLAG_CHK_CMDERR 0x88 // error in command itself |
| 67 |
|
| 68 |
#define CMD_FLAG_STS_MASK 0x03 |
| 69 |
#define CMD_FLAG_STS_OK 0x00 // OK |
| 70 |
#define CMD_FLAG_STS_COND 0x01 // OK, but alert to a condition |
| 71 |
#define CMD_FLAG_STS_OPER 0x02 // operator intervention required (eg media) |
| 72 |
#define CMD_FLAG_STS_ERR 0x03 // fatal, eg memory error |
| 73 |
|
| 74 |
/* Request Device Characteristics */ |
| 75 |
#define CMD_RDC_RS 0x0100 /* Request Summary */ |
| 76 |
#define CMD_RDC_ROC 0x0104 /* Request Option Characteristics (1 resp on p52x, not on p51x, 16 on p461 */ |
| 77 |
|
| 78 |
/* Printer Configuratio Control */ |
| 79 |
#define CMD_PCC_RP 0x0301 /* Reset Printer (1 arg) */ |
| 80 |
#define CMD_RCC_UNK 0x0310 /* XX Unknown */ |
| 81 |
#define CMD_PCC_STP 0x030F /* Set Target Printer (1 arg) XXX -- 00 == master or 01 == slave ? Or maybe it's a bank select for CMD_EFM_RNV? */ |
| 82 |
|
| 83 |
/* Request Device Status */ |
| 84 |
#define CMD_RDS_RSS 0x0400 /* Request Status Summary */ |
| 85 |
#define CMD_RDS_RIS 0x0401 /* Request Input Status */ |
| 86 |
#define CMD_RDS_RIA 0x0403 /* Request Input Alert */ |
| 87 |
#define CMD_RDS_RJA 0x0405 /* Request Jam Alert */ |
| 88 |
#define CMD_RDS_ROIRA 0x0406 /* Request Operator Intervention Alert */ |
| 89 |
#define CMD_RDS_RW 0x0407 /* Request Warnings */ |
| 90 |
#define CMD_RDS_DSRA 0x0408 /* Request Device Serviced Alerts */ |
| 91 |
#define CMD_RDS_SA 0x040A /* Request Service Alerts */ |
| 92 |
#define CMD_RDS_RPS 0x040B /* Request Printer Statistics */ |
| 93 |
#define CMD_RDS_RSUS 0x040C /* Request Supplies Status */ |
| 94 |
|
| 95 |
/* Job Control */ |
| 96 |
#define CMD_JC_SJ 0x0500 /* Start Job (3 arg) */ |
| 97 |
#define CMD_JC_EJ 0x0501 /* End Job (3 arg) */ |
| 98 |
#define CMD_JC_QJC 0x0502 /* Query Job Completed (5 arg) XX 6 byte resp (most), 2 (p461) */ |
| 99 |
#define CMD_JC_QQA 0x0503 /* Query Jobs Queued or Active (3 arg), 1 rsp */ |
| 100 |
#define CMD_JC_RSJ 0x0510 /* Resume Suspended Job (3 arg) XX */ |
| 101 |
|
| 102 |
/* Extended Read Device Characteristics */ |
| 103 |
#define CMD_ERDC_RS 0x8000 /* Request Summary */ |
| 104 |
#define CMD_ERDC_RCC 0x8001 /* Read Calibration Charcteristics */ |
| 105 |
#define CMD_ERDC_RPC 0x8005 /* Request Print Count (1 arg, 8 (51x) or 4 (52x,7xx) resp) */ |
| 106 |
#define CMD_ERDC_RLC 0x8006 /* Request LED calibration (10 on 52x, 6 on 461 */ |
| 107 |
#define CMD_ERDC_RSN 0x8007 /* Read Serial Number (1 arg) */ |
| 108 |
#define CMD_ERDC_C_RPCS 0x8008 /* CS Request Printer Correction Status */ |
| 109 |
#define CMD_ERDC_CTV 0x8008 /* Color Table Version XXX p51x, string (14 byte reply?), error on p461 */ |
| 110 |
#define CMD_ERDC_RPIDM 0x8009 /* Request PID and Model Code */ |
| 111 |
#define CMD_ERDC_UNKA 0x800A /* XX Unknown */ |
| 112 |
#define CMD_ERDC_UNKC 0x800C /* XX p51x Unknown, 4 byte resp (00 87 00 02) */ |
| 113 |
#define CMD_ERDC_UNKD 0x800D /* XX Unknown (1 arg) */ |
| 114 |
#define CMD_ERDC_RTLV 0x800E /* Request T/L Voltage */ |
| 115 |
#define CMD_ERDC_RRVC 0x800F /* Read Ribbon Vendor Code */ |
| 116 |
#define CMD_ERDC_UNK0 0x8010 /* Used when printer doesn't support RRVC? NOT p525/u826 */ |
| 117 |
#define CMD_ERDC_RHTV 0x8011 /* Request Heating Paramaters Table VersionXX p52x Unknown Query */ |
| 118 |
#define CMD_ERDC_RHA 0x801C /* Read Highlight Adjustment (6 resp) RE */ |
| 119 |
|
| 120 |
/* Extended Format Data */ |
| 121 |
#define CMD_EFD_SF 0x8100 /* Sublimation Format */ |
| 122 |
#define CMD_EFD_CHS 0x8101 /* Color & Heating Setting (2 arg) -- Not P525/U826/P630 */ |
| 123 |
#define CMD_EFD_C_CHS 0x8102 /* CS Color Heating Setting (3 arg) */ |
| 124 |
#define CMD_EFD_C_SIID 0x8103 /* CS Set Input ID (1 arg) */ |
| 125 |
|
| 126 |
/* Extended Page Control */ |
| 127 |
#define CMD_EPC_SP 0x8200 /* Start Page */ |
| 128 |
#define CMD_EPC_EP 0x8201 /* End Page */ |
| 129 |
#define CMD_EPC_SYP 0x8202 /* Start Yellow Plane */ |
| 130 |
#define CMD_EPC_SMP 0x8204 /* Start Magenta Plane */ |
| 131 |
#define CMD_EPC_SCP 0x8206 /* Start Cyan Plane */ |
| 132 |
|
| 133 |
#define CMD_EPC_C_SYP 0x8202 /* CS Start Yellow Page */ |
| 134 |
#define CMD_EPC_C_SMP 0x8203 /* CS Start Magenta Page */ |
| 135 |
#define CMD_EPC_C_SCP 0x8204 /* CS Start Cyan Page */ |
| 136 |
#define CMD_EPC_C_SBP 0x8205 /* CS Start Black Page */ |
| 137 |
#define CMD_EPC_C_SKP 0x8206 /* CS Start K Resin Page */ |
| 138 |
#define CMD_EPC_C_SLP 0x8207 /* CS Start Lamination Page */ |
| 139 |
#define CMD_EPC_C_SOP 0x8208 /* CS Start Overcoat Page */ |
| 140 |
#define CMD_EPC_C_SY2P 0x8209 /* CS Start Yellow2 Page */ |
| 141 |
#define CMD_EPC_C_SM2P 0x820A /* CS Start Magenta2 Page */ |
| 142 |
#define CMD_EPC_C_SC2P 0x820B /* CS Start Cyan2 Page */ |
| 143 |
#define CMD_EPC_C_SB2P 0x820C /* CS Start Black2 Page */ |
| 144 |
#define CMD_EPC_C_SK2P 0x820D /* CS Start K Resin2 Page */ |
| 145 |
#define CMD_EPC_C_SL2P 0x820E /* CS Start Lamination2 Page */ |
| 146 |
#define CMD_EPC_C_SO2P 0x820F /* CS Start Overcoat2 Page */ |
| 147 |
|
| 148 |
/* Extended Send Data */ |
| 149 |
#define CMD_ESD_SEHT2 0x8303 /* Send Ext Heating Table (2 arg) */ |
| 150 |
#define CMD_ESD_SEHT 0x8304 /* Send Ext Heating Table XX */ |
| 151 |
#define CMD_ESD_UNK6 0x8306 /* Unknown, seen in FW update (1 byte payload) */ |
| 152 |
#define CMD_ESD_UNK7 0x8307 /* Unknown, seen in FW update (no payload) */ |
| 153 |
#define CMD_ESD_SD 0x8308 /* Send data (256 or 0xfc00 byte payload) */ |
| 154 |
#define CMD_ESD_SEPD 0x8309 /* Send Ext Print Data (2 arg) + struct */ |
| 155 |
#define CMD_ESD_SHCI 0x830A /* Unknown, seen on P51x (4 byte payload) */ |
| 156 |
#define CMD_ESD_SHPTC 0x830B /* Send Heating Parameters & Tone Curve (varying payload) */ |
| 157 |
#define CMD_ESD_SHPTC2 0x830C /* Send Heating Parameters & Tone Curve Extended (when SHPTC is > 64K) */ |
| 158 |
|
| 159 |
/* Extended Flash/NVram */ |
| 160 |
#define CMD_EFM_WCV 0x8403 /* Write Calibration Value (n arg) */ |
| 161 |
#define CMD_EFM_RNV 0x8405 /* Read NVRam (1 arg) -- arg is offset, 1 byte resp of data @ that offset. -- P51x */ |
| 162 |
#define CMD_EFM_UNK6 0x8406 /* Write NVRAM, maybe? */ |
| 163 |
#define CMD_EFM_RD 0x8408 /* Read single location (2 byte offset arg, 1 byte of data @ that offset -- not P51x */ |
| 164 |
#define CMD_EFM_UNKC 0x840C /* Write NVRAM, maybe? */ |
| 165 |
#define CMD_EFM_SHA 0x840E /* Set Highlight Adjustment (5 arg) -- XXX RE */ |
| 166 |
|
| 167 |
#define CMD_ERD_RTCV 0x8702 /* XX No idea what this does */ |
| 168 |
|
| 169 |
/* Extended Security Control */ |
| 170 |
#define CMD_ESC_SP 0x8900 /* Set Password */ |
| 171 |
#define CMD_ESC_SSM 0x8901 /* Set Security Mode */ |
| 172 |
|
| 173 |
/* Extended Debug Mode */ |
| 174 |
#define CMD_EDM_CVD 0xE002 /* Common Voltage Drop Values (n arg) */ |
| 175 |
#define CMD_EDM_CPP 0xE023 /* Clean Paper Path (1 arg) XX */ |
| 176 |
#define CMD_EDM_UNK 0xE028 /* XX Called if ERC_RTCV is supported. */ |
| 177 |
#define CMD_EDM_C_MC2CES 0xE02E /* CS Move card to Contact Encoder Station */ |
| 178 |
#define CMD_EDM_C_MC2MES 0xE02F /* CS Move card to Mag Encoder Station */ |
| 179 |
#define CMD_EDM_C_MC2CLES 0xE030 /* CS Move card to ContactLess Encoder Station */ |
| 180 |
#define CMD_EDM_C_MC2EB 0xE031 /* CS Move card to Eject Box */ |
| 181 |
#define CMD_EDM_C_MC2H 0xE037 /* CS Move card to Hopper */ |
| 182 |
|
| 183 |
#define CMD_UNK_UNK 0xE200 |
| 184 |
|
| 185 |
/* CMD_PCC_RP */ |
| 186 |
#define RESET_PRINTER 0x01 |
| 187 |
#define RESET_SOFT 0x02 |
| 188 |
|
| 189 |
/* 801C --> 0 args |
| 190 |
<-- 6 bytes: 00 YY MM CC 00 00 (YMC is +- 31 decimal) |
| 191 |
|
| 192 |
840E --> 5 args: YY MM CC 00 00 (YMC is +- 31 decimal) |
| 193 |
<-- 1 arg: 00 (success, presumably) |
| 194 |
|
| 195 |
Highlight Correction. Unclear if it's used by printer or by "driver" |
| 196 |
|
| 197 |
*/ |
| 198 |
|
| 199 |
/* CMD_ERDC_RCC */ |
| 200 |
struct hiti_calibration { |
| 201 |
uint8_t cols; |
| 202 |
uint8_t rows; |
| 203 |
} __attribute__((packed)); |
| 204 |
|
| 205 |
/* CMD_EDRC_RHTV */ |
| 206 |
struct hiti_rhtv { |
| 207 |
uint16_t major; |
| 208 |
uint16_t minor; |
| 209 |
} __attribute__((packed)); |
| 210 |
|
| 211 |
/* CMD_ERDC_RPIDM */ |
| 212 |
struct hiti_rpidm { |
| 213 |
uint16_t usb_pid; /* BE */ |
| 214 |
uint8_t region; /* See hiti_regions, fixed at 01 on P52x and P630 */ |
| 215 |
} __attribute__((packed)); |
| 216 |
|
| 217 |
/* CMD_EDRC_RS */ |
| 218 |
struct hiti_erdc_rs { /* All are BIG endian */ |
| 219 |
uint8_t tph_seg; // Always 0x1e? |
| 220 |
uint16_t stride; /* Head width: 1920 (6" models) 1280 (4" models) */ |
| 221 |
uint16_t dpi_cols; /* fixed at 300 */ |
| 222 |
uint16_t dpi_rows; /* fixed at 300 */ |
| 223 |
uint16_t cols; /* fixed at the printer's max print size width (eg 1844 for all 6" models) */ |
| 224 |
uint16_t rows; /* 1240 for 6x4" media */ |
| 225 |
uint16_t vertUnitInstalled; // 0xa055 for P510S, 0xffff for rest |
| 226 |
uint8_t y_speed; /* Varies based on model, units unknown */ |
| 227 |
uint8_t m_speed; |
| 228 |
uint8_t c_speed; |
| 229 |
uint8_t o_speed; |
| 230 |
uint8_t overheatTemp; |
| 231 |
uint8_t heaterOffTemp; |
| 232 |
uint8_t hwFeature1; // P52x bit 7 means Toshiba ("RI1") printhead |
| 233 |
uint8_t fwFeature1; // bit 7 means KO function |
| 234 |
uint8_t preheatTemp; |
| 235 |
|
| 236 |
// These might not be present */ |
| 237 |
|
| 238 |
uint16_t dpi_rows2; /* 0x5c08 p520l/p510s */ |
| 239 |
uint16_t dpi_rows3; /* 0x0020 p461 */ |
| 240 |
uint8_t hwFeature2; // 64/64/40/20 p630/520l/510s/p461 |
| 241 |
uint8_t overheatTempS; |
| 242 |
uint8_t overheatTempOT; |
| 243 |
} __attribute__((packed)); |
| 244 |
|
| 245 |
/* CMD_JC_* */ |
| 246 |
struct hiti_job { |
| 247 |
uint8_t lun; /* Logical Unit Number. Leave at 0 */ |
| 248 |
uint16_t jobid; /* BE */ |
| 249 |
} __attribute__((packed)); |
| 250 |
|
| 251 |
/* CMD_JC_QQA */ |
| 252 |
#define MAX_JOBS 4 |
| 253 |
struct hiti_job_qqa { |
| 254 |
uint8_t count; /* 0-MAX_JOBS */ |
| 255 |
struct { |
| 256 |
struct hiti_job job; |
| 257 |
uint8_t status; |
| 258 |
} row[MAX_JOBS]; /* Four jobs max outstanding */ |
| 259 |
} __attribute__((packed)); |
| 260 |
|
| 261 |
#define QQA_STATUS_PRINTING 0x00 |
| 262 |
#define QQA_STATUS_WAITING 0x01 |
| 263 |
#define QQA_STATUS_SUSPENDED 0x03 |
| 264 |
#define QQA_STATUS_ERROR 0x80 // ??? |
| 265 |
|
| 266 |
/* CMD_JC_QJC */ |
| 267 |
struct hiti_jc_qjc { |
| 268 |
uint8_t lun; /* Logical Unit Number. Leave at 0 */ |
| 269 |
uint16_t jobid; /* BE */ |
| 270 |
uint16_t jobid2; /* BE, set to 1? */ |
| 271 |
} __attribute__((packed)); |
| 272 |
// repsonse is 6 bytes. |
| 273 |
|
| 274 |
// Roll Type: |
| 275 |
// 5x3.5 1547 1072 |
| 276 |
// 6x4 1844 1240 |
| 277 |
// 6x4b 1844 1216 /" 6x3.94" |
| 278 |
// 6x9 1844 2740 |
| 279 |
// 6x8/2 1844 2492 |
| 280 |
// 6x8 1844 2434 |
| 281 |
// 5x7 1548 2140 |
| 282 |
// 5x7/2 1548 2152 |
| 283 |
// 6x4/2 1844 1248 |
| 284 |
// 6x6 1844 1844 |
| 285 |
// 5x5 1540 1540 ? (1548?) |
| 286 |
// 6x5 1844 1544 |
| 287 |
// 6x2 1844 ???? |
| 288 |
|
| 289 |
// Sheet type: |
| 290 |
// 6x4 1818 1280 |
| 291 |
|
| 292 |
#define PRINT_TYPE_6x4 0 |
| 293 |
#define PRINT_TYPE_5x7 2 |
| 294 |
#define PRINT_TYPE_6x8 3 |
| 295 |
#define PRINT_TYPE_6x9 6 |
| 296 |
#define PRINT_TYPE_6x9_2UP 7 |
| •297 |
#define PRINT_TYPE_5x3_5 8 // "5x3.74" ?? |
| 298 |
#define PRINT_TYPE_6x4_2UP 9 |
| 299 |
#define PRINT_TYPE_6x2 10 |
| 300 |
#define PRINT_TYPE_5x7_2UP 11 |
| 301 |
#define PRINT_TYPE_6x4_3UP 16 // ("4x6-split_3up") |
| 302 |
#define PRINT_TYPE_6x9_4UP 17 // ("6x9-2up2split") |
| 303 |
#define PRINT_TYPE_6x9_6UP 24 // ("6x9-2up3split") |
| 304 |
#define PRINT_TYPE_6x5 20 |
| 305 |
#define PRINT_TYPE_6x6 21 |
| •306 |
#define PRINT_TYPE_5x5 23 |
| 307 |
|
| 308 |
struct hiti_heattable_hdr_v1 { /* P51x */ |
| 309 |
uint8_t type; |
| 310 |
uint32_t len; /* Length in 16-bit words, LE */ |
| 311 |
} __attribute((packed)); |
| 312 |
|
| 313 |
#define HITI_HEATTABLE_V1_Y 0x01 |
| 314 |
#define HITI_HEATTABLE_V1_M 0x02 |
| 315 |
#define HITI_HEATTABLE_V1_C 0x03 |
| 316 |
#define HITI_HEATTABLE_V1_U 0x04 // XXX unknown, maybe K? |
| 317 |
#define HITI_HEATTABLE_V1_O 0x05 |
| 318 |
#define HITI_HEATTABLE_V1_OM 0x07 |
| 319 |
#define HITI_HEATTABLE_V1_CVD 0x08 |
| 320 |
|
| 321 |
#define HITI_HEATTABLE_V1_PLANESIZE 2050 |
| 322 |
#define HITI_HEATTABLE_V1_CVDSIZE 582 |
| 323 |
|
| 324 |
/* All fields are little endian */ |
| 325 |
struct hiti_heattable_entry_v2 { |
| 326 |
uint8_t type; |
| 327 |
uint32_t len; /* in 16-bit words */ |
| 328 |
uint32_t offset; |
| 329 |
} __attribute((packed)); |
| 330 |
|
| 331 |
struct hiti_heattable_hdr_v2 { |
| 332 |
uint8_t num_headers; |
| 333 |
struct hiti_heattable_entry_v2 entries[]; |
| 334 |
} __attribute((packed)); |
| 335 |
|
| 336 |
#define HEATTABLE_V2_MAX_SIZE (1024*4096) /* P630 has 3.6MB tables! */ |
| 337 |
|
| 338 |
#define HEATTABLE_S_SIZE 4167 /* P461, P310, and some P32x */ |
| 339 |
#define HEATTABLE_S2_SIZE 4232 /* Some P32x */ |
| 340 |
// size |
| 341 |
#define HEATTABLE_V2_ID_HT_D_Y 0x01 // 522 |
| 342 |
#define HEATTABLE_V2_ID_HT_D_M 0x02 // |
| 343 |
#define HEATTABLE_V2_ID_HT_D_C 0x03 // |
| 344 |
#define HEATTABLE_V2_ID_HT_D_K 0x04 // |
| 345 |
#define HEATTABLE_V2_ID_HT_R_RK 0x10 // |
| 346 |
#define HEATTABLE_V2_ID_HT_R_R 0x11 // |
| 347 |
#define HEATTABLE_V2_ID_HT_R_L 0x12 // |
| 348 |
#define HEATTABLE_V2_ID_HT_R_FO 0x13 // |
| 349 |
#define HEATTABLE_V2_ID_HT_D_O 0x20 // |
| 350 |
#define HEATTABLE_V2_ID_HT_D_KO 0x21 // |
| 351 |
#define HEATTABLE_V2_ID_HT_D_MO 0x22 // |
| 352 |
#define HEATTABLE_V2_ID_CVD 0x40 // 582 |
| 353 |
#define HEATTABLE_V2_ID_VER_MAJOR 0x50 // 4 |
| 354 |
#define HEATTABLE_V2_ID_VER_MINOR 0x51 // |
| 355 |
#define HEATTABLE_V2_ID_CT_INVERT 0x80 // 2562 |
| 356 |
#define HEATTABLE_V2_ID_CT_CLASSIC 0x81 // |
| 357 |
#define HEATTABLE_V2_ID_CT_IDPASS 0x82 // |
| 358 |
#define HEATTABLE_V2_ID_TC_COMPENSATE 0x90 // 26 |
| 359 |
#define HEATTABLE_V2_ID_HAC_Y 0xa1 // 1540 |
| 360 |
#define HEATTABLE_V2_ID_HAC_M 0xa2 // |
| 361 |
#define HEATTABLE_V2_ID_HAC_C 0xa3 // |
| 362 |
#define HEATTABLE_V2_ID_HAC_DK 0xa4 // |
| 363 |
#define HEATTABLE_V2_ID_HAC_RK 0xa5 // |
| 364 |
#define HEATTABLE_V2_ID_HAC_R 0xa6 // |
| 365 |
#define HEATTABLE_V2_ID_HAC_O 0xa7 // |
| 366 |
#define HEATTABLE_V2_ID_HAC_MO 0xa8 // |
| 367 |
#define HEATTABLE_V2_ID_HAC_FO 0xa9 // |
| 368 |
#define HEATTABLE_V2_ID_HAC_YMC 0xae // |
| 369 |
#define HEATTABLE_V2_ID_HAC_ALL 0xaf // |
| 370 |
#define HEATTABLE_V2_ID_LS_Y 0xb1 // 24 (Long Smear) |
| 371 |
#define HEATTABLE_V2_ID_LS_M 0xb2 // |
| 372 |
#define HEATTABLE_V2_ID_LS_C 0xb3 // |
| 373 |
#define HEATTABLE_V2_ID_LS_DK 0xb4 // |
| 374 |
#define HEATTABLE_V2_ID_LS_RK 0xb5 // |
| 375 |
#define HEATTABLE_V2_ID_LS_R 0xb6 // |
| 376 |
#define HEATTABLE_V2_ID_LS_O 0xb7 // |
| 377 |
#define HEATTABLE_V2_ID_LS_MO 0xb8 // |
| 378 |
#define HEATTABLE_V2_ID_LS_FO 0xb9 // |
| 379 |
#define HEATTABLE_V2_ID_LS_YMC 0xbe // |
| 380 |
#define HEATTABLE_V2_ID_LS_ALL 0xbf // |
| 381 |
#define HEATTABLE_V2_ID_GL_Y 0xc1 // ?? (Ghost Line) |
| 382 |
#define HEATTABLE_V2_ID_GL_M 0xc2 // |
| 383 |
#define HEATTABLE_V2_ID_GL_C 0xc3 // |
| 384 |
#define HEATTABLE_V2_ID_GL_DK 0xc4 // |
| 385 |
#define HEATTABLE_V2_ID_GL_RK 0xc5 // |
| 386 |
#define HEATTABLE_V2_ID_GL_R 0xc6 // |
| 387 |
#define HEATTABLE_V2_ID_GL_O 0xc7 // |
| 388 |
#define HEATTABLE_V2_ID_GL_MO 0xc8 // |
| 389 |
#define HEATTABLE_V2_ID_GL_FO 0xc9 // |
| 390 |
#define HEATTABLE_V2_ID_GL_YMC 0xce // |
| 391 |
#define HEATTABLE_V2_ID_GL_ALL 0xcf // |
| 392 |
#define HEATTABLE_V2_ID_EN_Y 0xd1 // 18 (Energy) |
| 393 |
#define HEATTABLE_V2_ID_EN_M 0xd2 // |
| 394 |
#define HEATTABLE_V2_ID_EN_C 0xd3 // |
| 395 |
#define HEATTABLE_V2_ID_EN_DK 0xd4 // |
| 396 |
#define HEATTABLE_V2_ID_EN_RK 0xd5 // |
| 397 |
#define HEATTABLE_V2_ID_EN_R 0xd6 // |
| 398 |
#define HEATTABLE_V2_ID_EN_O 0xd7 // |
| 399 |
#define HEATTABLE_V2_ID_EN_MO 0xd8 // |
| 400 |
#define HEATTABLE_V2_ID_EN_FO 0xd9 // |
| 401 |
#define HEATTABLE_V2_ID_EN_YMC 0xde // |
| 402 |
#define HEATTABLE_V2_ID_EN_ALL 0xdf // |
| 403 |
#define HEATTABLE_V2_ID_OP1 0xf1 // rp only so far |
| 404 |
#define HEATTABLE_V2_ID_OP2 0xf2 // rp only so far |
| 405 |
#define HEATTABLE_V2_ID_SMEAR 0xf3 // rp only so far |
| 406 |
#define HEATTABLE_V2_ID_MSKL_RATE 0xf4 // rp only so far |
| 407 |
|
| 408 |
#define HEATTABLE_V2_ID_EMBEDDED 0xf0 // 2 |
| 409 |
#define HEATTABLE_V2_ID_EMBEDDED_1 0x00 // varies |
| 410 |
#define HEATTABLE_V2_ID_EMBEDDED_2 0x20 // varies |
| 411 |
|
| 412 |
/* All fields are LE */ |
| 413 |
struct hiti_gpjobhdr { |
| 414 |
uint32_t cookie; /* "GPHT" */ |
| 415 |
uint32_t hdr_len; /* Including the whole thing */ |
| 416 |
uint32_t model; /* Model family, in decimal */ |
| 417 |
uint32_t cols; |
| 418 |
uint32_t rows; |
| 419 |
uint32_t col_dpi; |
| 420 |
uint32_t row_dpi; |
| 421 |
uint32_t copies; |
| 422 |
uint32_t quality; /* 0 for std, 1 for fine */ |
| 423 |
uint32_t code; /* PRINT_TYPE_* */ |
| 424 |
uint32_t overcoat; /* 1 for matte, 0 for glossy */ |
| 425 |
uint32_t payload_flag; /* See PAYLOAD_FLAG_* */ |
| 426 |
uint32_t payload_len; |
| 427 |
} __attribute__((packed)); |
| 428 |
|
| 429 |
#define PAYLOAD_FLAG_YMCPLANAR 0x01 |
| 430 |
#define PAYLOAD_FLAG_NOCORRECT 0x02 |
| 431 |
#define PAYLOAD_FLAG_MEDIAVER 0x04 |
| 432 |
#define PAYLOAD_FLAG_MEDIATYPE 0x08 |
| 433 |
|
| 434 |
#define PAYLOAD_FLAG_DATA_SHIFT 24 |
| 435 |
|
| 436 |
#define HDR_COOKIE 0x54485047 |
| 437 |
|
| 438 |
/* CMD_EFD_SF for non-CS systems */ |
| 439 |
struct hiti_efd_sf { |
| 440 |
/*@0 */ uint8_t mediaType; /* PRINT_TYPE_?? */ |
| 441 |
/*@1 */ uint16_t cols_res; /* BE, always 300dpi */ |
| 442 |
/*@3 */ uint16_t rows_res; /* BE, always 300dpi */ |
| 443 |
/*@5 */ uint16_t cols; /* BE */ |
| 444 |
/*@7 */ uint16_t rows; /* BE */ |
| 445 |
/*@9 */ int8_t cols_offset; /* Has to do with H_Offset calibration */ |
| 446 |
/*@10*/ int8_t rows_offset; /* Has to do wiwth V_Offset calibration */ |
| 447 |
/*@11*/ uint8_t colorSeq; /* See SF_COLORSEQ_* */ |
| 448 |
/*@12*/ uint8_t copies; |
| 449 |
/*@13*/ uint8_t printMode; /* See SF_PRINTMODE_* */ |
| 450 |
/*@14*/ uint8_t zero[4]; /* P461, U826, P630 only? */ |
| 451 |
} __attribute__((packed)); |
| 452 |
|
| 453 |
/* SF_COLORSEQ is actually: |
| 454 |
|
| 455 |
Y 0x01 |
| 456 |
M 0x02 |
| 457 |
C 0x04 |
| 458 |
DK 0x08 (Dye Black) |
| 459 |
RK 0x10 (Resin Black) |
| 460 |
OM 0x20 (NOT CSxxx models) |
| 461 |
O 0x80 (On CSxx, means there is an explicit O plane) |
| 462 |
*/ |
| 463 |
#define SF_COLORSEQ_YMCO 0x87 |
| 464 |
#define SF_COLORSEQ_MATTE 0xC0 |
| 465 |
|
| 466 |
#define SF_PRINTMODE_NORMAL 0x00 |
| 467 |
#define SF_PRINTMODE_SPLITK 0x01 /* CSxxx only */ |
| 468 |
#define SF_PRINTMODE_FINE 0x02 /* For P5xx/P7xx only */ |
| 469 |
#define SF_PRINTMODE_BASE 0x08 /* For P5xx/P7xx only */ |
| 470 |
#define SF_PRINTMODE_OBHEAT 0x10 /* Onboard Heat Comp, CSxxx only */ |
| 471 |
|
| 472 |
/* CMD_ESD_SEPD -- Note it's different from the usual command flow */ |
| 473 |
struct hiti_extprintdata { |
| 474 |
uint8_t hdr; /* 0xa5 */ |
| 475 |
uint16_t len; /* 24bit data length (+8) in BE format, first two bytes */ |
| 476 |
uint8_t flag; /* 0x50 */ |
| 477 |
uint16_t cmd; /* 0x8309, BE */ |
| 478 |
uint8_t lenb; /* LSB of length */ |
| 479 |
uint16_t startLine; /* Starting line number, BE */ |
| 480 |
uint16_t numLines; /* Number of lines in block, BE, 3000 max. */ |
| 481 |
uint8_t payload[]; /* ie data length bytes */ |
| 482 |
} __attribute__((packed)); |
| 483 |
|
| 484 |
/* CMD_ESD_SEHT2 -- Note it's different from the usual command flow */ |
| 485 |
struct hiti_seht2 { |
| 486 |
uint8_t hdr; /* 0xa5 */ |
| 487 |
uint16_t len; /* 24-bit data length (+5) in BE format, first two bytes */ |
| 488 |
uint8_t flag; /* 0x50 */ |
| 489 |
uint16_t cmd; /* 0x8303, BE */ |
| 490 |
uint8_t lenb; /* LSB of length */ |
| 491 |
uint8_t plane; |
| 492 |
} __attribute__((packed)); |
| 493 |
|
| 494 |
/* All multi-byte fields here are LE */ |
| 495 |
struct hiti_matrix { |
| 496 |
/*@00*/ uint8_t row0[16]; // all 00 |
| 497 |
|
| 498 |
/*@10*/ uint8_t row1[6]; // 01 00 00 00 00 00 |
| 499 |
uint16_t cuttercount; |
| 500 |
uint8_t align_v; |
| 501 |
uint8_t aligh_h; |
| 502 |
uint8_t row1_2[6]; // all 00 |
| 503 |
|
| 504 |
/*@20*/ uint8_t row2[16]; // no idea |
| 505 |
|
| 506 |
/*@30*/ uint8_t error_index0; /* Value % 31 == NEWEST. Count back */ |
| 507 |
uint8_t errorcode[31]; |
| 508 |
|
| 509 |
/*@50*/ uint8_t row5[16]; // all 00, except [8] which is a5. |
| 510 |
/*@60*/ char serno[16]; /* device serial number */ |
| 511 |
|
| 512 |
/*@70*/ uint16_t unclean_prints; |
| 513 |
uint16_t cleanat[15]; // XX Guess? |
| 514 |
|
| 515 |
/*@90*/ uint16_t supply_motor; |
| 516 |
uint16_t take_motor; |
| 517 |
uint8_t row9[12]; // all 00 except last, which is 0xa5 |
| 518 |
|
| 519 |
/*@a0*/ uint16_t errorcount[31]; |
| 520 |
uint8_t rowd[2]; // seems to be 00 cc ? |
| 521 |
|
| 522 |
/*@e0*/ uint16_t tpc_4x6; |
| 523 |
uint16_t tpc_5x7; |
| 524 |
uint16_t tpc_6x8; |
| 525 |
uint16_t tpc_6x9; |
| 526 |
uint8_t unk_rowe[8]; // all 00 |
| 527 |
|
| 528 |
/*@f0*/ uint16_t apc_4x6; |
| 529 |
uint16_t apc_5x7; |
| 530 |
uint16_t apc_6x8; |
| 531 |
uint16_t apc_6x9; |
| 532 |
uint8_t unk_rowf[4]; // all 00 |
| 533 |
uint8_t tphv_a; |
| 534 |
uint8_t tphv_d; |
| 535 |
uint8_t unk_rowf2[2]; // all 00 |
| 536 |
|
| 537 |
/*@100*/uint8_t unk_row10[16]; |
| 538 |
/*@110*/uint8_t unk_row11[16]; |
| 539 |
/*@120*/uint8_t unk_row12[16]; |
| 540 |
/*@130*/uint8_t unk_row13[16]; |
| 541 |
/*@140*/uint8_t unk_row14[16]; |
| 542 |
/*@150*/uint8_t unk_row15[16]; |
| 543 |
/*@160*/uint8_t unk_row16[16]; |
| 544 |
/*@170*/uint8_t unk_row17[16]; |
| 545 |
/*@180*/uint8_t unk_row18[16]; |
| 546 |
/*@190*/uint8_t unk_row19[16]; |
| 547 |
/*@1a0*/uint8_t unk_row1a[16]; |
| 548 |
/*@1b0*/uint8_t unk_row1b[16]; |
| 549 |
/*@1c0*/uint8_t unk_row1c[16]; |
| 550 |
/*@1d0*/uint8_t unk_row1d[16]; |
| 551 |
/*@1e0*/uint8_t unk_row1e[16]; |
| 552 |
/*@1f0*/uint8_t unk_row1f[16]; |
| 553 |
/*@200*/ |
| 554 |
} __attribute__((packed)); |
| 555 |
|
| 556 |
STATIC_ASSERT(sizeof(struct hiti_matrix) == 512); |
| 557 |
|
| 558 |
struct hiti_ribbon { |
| 559 |
uint16_t unk; // 01 08 (p461, u826, p630) |
| 560 |
uint8_t type; /* RIBBON_TYPE_XXX */ |
| 561 |
uint16_t unk2; // 00 07 (p461, u826, p630) |
| 562 |
} __attribute__((packed)); |
| 563 |
|
| 564 |
#define RIBBON_TYPE_4x6 0x01 |
| 565 |
#define RIBBON_TYPE_5x7 0x02 |
| 566 |
#define RIBBON_TYPE_6x9 0x03 |
| 567 |
#define RIBBON_TYPE_6x8 0x04 |
| 568 |
|
| 569 |
struct hiti_paper { |
| 570 |
uint8_t unk; // 01 on U286 w/6x8 |
| 571 |
uint8_t type; /* PAPER_TYPE_XXX */ |
| 572 |
uint16_t unk2; // 00 07 on U826 w/6x8) |
| 573 |
} __attribute__((packed)); |
| 574 |
|
| 575 |
#define PAPER_TYPE_X4INCH 0xf0 // XXX hack |
| 576 |
#define PAPER_TYPE_5INCH 0x02 |
| 577 |
#define PAPER_TYPE_6INCH 0x01 |
| 578 |
#define PAPER_TYPE_NONE 0x00 |
| 579 |
|
| 580 |
/* Private data structure */ |
| 581 |
enum { |
| 582 |
HT_COLORMODE_NULL = 0, |
| 583 |
HT_COLORMODE_INVERT = 1, |
| 584 |
HT_COLORMODE_CLASSIC = 2, |
| 585 |
HT_COLORMODE_IDPASS_VIVID = 3, |
| 586 |
|
| 587 |
HT_COLORMODE_METALLIC = 5, |
| 588 |
HT_COLORMODE_HIGHDENSITY = 6, |
| 589 |
HT_COLORMODE_TRANSPARENT = 7, |
| 590 |
}; |
| 591 |
|
| 592 |
enum { |
| 593 |
HT_PLANE_Y = 0x01, |
| 594 |
HT_PLANE_M = 0x02, |
| 595 |
HT_PLANE_C = 0x04, |
| 596 |
HT_PLANE_K = 0x08, // Dye K, eg on YMCKO ribbons? |
| 597 |
HT_PLANE_OG = 0x10, |
| 598 |
HT_PLANE_OK = 0x20, // Glossy on YMCKO ribbons |
| 599 |
HT_PLANE_OM = 0x40, |
| 600 |
HT_PLANE_RK = 0x100, // Resin K on YMCKO |
| 601 |
HT_PLANE_R = 0x200, // Resin K only |
| 602 |
HT_PLANE_FO = 0x400, // Flourescent |
| 603 |
HT_PLANE_L = 0x800, // Lamination on RESIN K |
| 604 |
HT_CVD = 0x1000, |
| 605 |
HT_PLANE_630X = 0x2000, // P630 has several unknown fields |
| 606 |
}; |
| 607 |
|
| 608 |
struct hiti_printjob { |
| 609 |
struct dyesub_job_common common; |
| 610 |
|
| 611 |
uint8_t *databuf; |
| 612 |
uint32_t datalen; |
| 613 |
|
| 614 |
struct hiti_gpjobhdr hdr; |
| 615 |
|
| 616 |
int colormode; |
| 617 |
|
| 618 |
uint8_t *heattable_buf; |
| 619 |
int heattable_len; |
| 620 |
|
| 621 |
struct hiti_heattable_v2 { |
| 622 |
uint8_t type; |
| 623 |
uint8_t *data; |
| 624 |
uint32_t len; |
| 625 |
} *heattable_v2; |
| 626 |
uint8_t num_heattable_entries; |
| 627 |
}; |
| 628 |
|
| 629 |
enum { |
| 630 |
HEATTABLE_TYPE_V0, // P461, P320, P310, passed as-is |
| 631 |
HEATTABLE_TYPE_V1, // P51x |
| 632 |
HEATTABLE_TYPE_V2, // All others |
| 633 |
}; |
| 634 |
|
| 635 |
struct hiti_ctx { |
| 636 |
struct dyesub_connection *conn; |
| 637 |
|
| 638 |
int jobid; |
| 639 |
int nodata; |
| 640 |
|
| 641 |
int sheet; |
| 642 |
int heattable_type; |
| 643 |
|
| 644 |
char serno[32]; |
| 645 |
|
| 646 |
int erdc_rpc_len; |
| 647 |
|
| 648 |
struct marker marker; |
| 649 |
char version[256]; |
| 650 |
char id[256]; |
| 651 |
uint8_t matrix[512]; // XXX convert to struct matrix */ |
| 652 |
struct hiti_ribbon ribbon; |
| 653 |
struct hiti_paper paper; |
| 654 |
struct hiti_calibration calibration; |
| 655 |
struct hiti_rhtv rhtv; |
| 656 |
uint8_t led_calibration[10]; // XXX convert to struct |
| 657 |
uint8_t unk_8010[17]; // XXX !sheet. 17 on U826+P630, 15 on rest |
| 658 |
uint8_t unk_800c[4]; // XXX |
| 659 |
struct hiti_erdc_rs erdc_rs; |
| 660 |
uint8_t hilight_adj[6]; // XXX convert to struct, not P51x! |
| 661 |
uint8_t rtlv[2]; /* XXX figure out conversion/math? */ |
| 662 |
struct hiti_rpidm rpidm; |
| 663 |
uint16_t ribbonvendor; // see below. |
| 664 |
uint32_t media_remain; // XXX could be array? |
| 665 |
}; |
| 666 |
|
| 667 |
#define RRVC_VENDOR_MASK 0xf000 |
| 668 |
#define RRVC_VERSION_MASK 0x003f |
| 669 |
|
| 670 |
/* Prototypes */ |
| 671 |
static int hiti_doreset(struct hiti_ctx *ctx, uint8_t type); |
| 672 |
static int hiti_query_job_qa(struct hiti_ctx *ctx, struct hiti_job *jobid, struct hiti_job_qqa *resp); |
| 673 |
static int hiti_query_status(struct hiti_ctx *ctx, uint8_t *sts, uint32_t *err); |
| 674 |
static int hiti_query_version(struct hiti_ctx *ctx); |
| 675 |
static int hiti_query_matrix(struct hiti_ctx *ctx); |
| 676 |
static int hiti_query_matrix_51x(struct hiti_ctx *ctx); |
| 677 |
static int hiti_query_supplies(struct hiti_ctx *ctx); |
| 678 |
static int hiti_query_tphv(struct hiti_ctx *ctx); |
| 679 |
static int hiti_query_statistics(struct hiti_ctx *ctx); |
| 680 |
static int hiti_query_calibration(struct hiti_ctx *ctx); |
| 681 |
static int hiti_query_led_calibration(struct hiti_ctx *ctx); |
| 682 |
static int hiti_query_ribbonvendor(struct hiti_ctx *ctx); |
| 683 |
static int hiti_query_summary(struct hiti_ctx *ctx, struct hiti_erdc_rs *rds); |
| 684 |
static int hiti_query_rpidm(struct hiti_ctx *ctx); |
| 685 |
static int hiti_query_hilightadj(struct hiti_ctx *ctx); |
| 686 |
static int hiti_query_unk8010(struct hiti_ctx *ctx); |
| 687 |
static int hiti_query_unk800c(struct hiti_ctx *ctx); |
| 688 |
static int hiti_query_counter(struct hiti_ctx *ctx, uint8_t arg, uint32_t *resp, int num); |
| 689 |
static int hiti_query_markers(void *vctx, struct marker **markers, int *count); |
| 690 |
|
| 691 |
static int hiti_query_serno(struct dyesub_connection *conn, char *buf, int buf_len); |
| 692 |
static int hiti_parse_heattable_v2(struct hiti_printjob *job); |
| 693 |
static int hiti_construct_heattable_v2(const struct hiti_printjob *job, int planes, int colormode, struct hiti_heattable_hdr_v2 *table); |
| 694 |
static void *hiti_find_heattable_v2_entry(const struct hiti_printjob *job, int id, size_t *len); |
| 695 |
|
| 696 |
static const char* hiti_modelcode(int type, int subtype) { |
| 697 |
switch (type) { |
| 698 |
case P_HITI_CS2XX: |
| 699 |
return "cd"; |
| 700 |
case P_HITI_310: |
| 701 |
return "sl"; |
| 702 |
case P_HITI_320: |
| 703 |
return "sp"; |
| 704 |
case P_HITI_461: |
| 705 |
return "sn"; |
| 706 |
case P_HITI_51X: |
| 707 |
return "ra"; |
| 708 |
case P_HITI_520: |
| 709 |
case P_HITI_525: |
| 710 |
if (subtype) |
| 711 |
return "ri1"; |
| 712 |
else |
| 713 |
return "ri"; |
| 714 |
case P_HITI_530: |
| 715 |
return "rk"; |
| 716 |
case P_HITI_630: |
| 717 |
return "rp"; |
| 718 |
case P_HITI_720: |
| 719 |
return "rd"; |
| 720 |
case P_HITI_750: |
| 721 |
return "rh"; |
| 722 |
case P_HITI_826: |
| 723 |
if (subtype) |
| 724 |
return "ro1"; |
| 725 |
else |
| 726 |
return "ro"; |
| 727 |
case P_SWIFTFOTO_KSF10: |
| 728 |
if (subtype) |
| 729 |
return "rq1"; |
| 730 |
else |
| 731 |
return "rq"; |
| 732 |
default: |
| 733 |
ERROR("Unknown HiTi type %d\n", type); |
| 734 |
return "XX"; |
| 735 |
} |
| 736 |
} |
| 737 |
|
| 738 |
static int hiti_docmd(struct hiti_ctx *ctx, uint16_t cmdid, const uint8_t *buf, uint16_t buf_len, uint16_t *rsplen) |
| 739 |
{ |
| 740 |
uint8_t cmdbuf[2048]; |
| 741 |
struct hiti_cmd *cmd = (struct hiti_cmd *)cmdbuf; |
| 742 |
int ret, num = 0; |
| 743 |
|
| 744 |
cmd->hdr = 0xa5; |
| 745 |
cmd->len = cpu_to_be16(buf_len + 3); |
| 746 |
cmd->flag = (CMD_FLAG_DEST | CMD_FLAG_REPLY); |
| 747 |
cmd->cmd = cpu_to_be16(cmdid); |
| 748 |
if (buf && buf_len) |
| 749 |
memcpy(cmd->payload, buf, buf_len); |
| 750 |
|
| 751 |
/* Send over command */ |
| 752 |
if ((ret = send_data(ctx->conn, (uint8_t*) cmd, buf_len + 3 + 3))) { |
| 753 |
return ret; |
| 754 |
} |
| 755 |
|
| 756 |
__usleep(10*1000); |
| 757 |
|
| 758 |
/* Read back command */ |
| 759 |
ret = read_data(ctx->conn, cmdbuf, 6, &num); |
| 760 |
if (ret) |
| 761 |
return ret; |
| 762 |
|
| 763 |
if (num != 6) { |
| 764 |
ERROR("CMD Readback length mismatch (%d vs %d)!\n", num, 6); |
| 765 |
return CUPS_BACKEND_FAILED; |
| 766 |
} |
| 767 |
|
| 768 |
/* Compensate for hdr len */ |
| 769 |
num = be16_to_cpu(cmd->len) - 3; |
| 770 |
|
| 771 |
if (num > *rsplen) { |
| 772 |
ERROR("Response too long for buffer (%d vs %d)!\n", num, *rsplen); |
| 773 |
*rsplen = 0; |
| 774 |
return CUPS_BACKEND_FAILED; |
| 775 |
} |
| 776 |
|
| 777 |
/* Check response */ |
| 778 |
switch (cmd->flag & CMD_FLAG_CHK_MASK) { |
| 779 |
case CMD_FLAG_CHK_OK: |
| 780 |
break; |
| 781 |
case CMD_FLAG_CHK_REJECTED: |
| 782 |
ERROR("Command %04x rejected, code %02x\n", cmdid, cmd->flag); |
| 783 |
return CUPS_BACKEND_FAILED; |
| 784 |
case CMD_FLAG_CHK_DATAERR: |
| 785 |
ERROR("Command %04x Data Error, code %02x\n", cmdid, cmd->flag); |
| 786 |
return CUPS_BACKEND_FAILED; |
| 787 |
case CMD_FLAG_CHK_CMDERR: |
| 788 |
ERROR("Command %04x Data Error, code %02x\n", cmdid, cmd->flag); |
| 789 |
return CUPS_BACKEND_FAILED; |
| 790 |
default: |
| 791 |
ERROR("Command %04x failed, code %02x\n", cmdid, cmd->flag); |
| 792 |
return CUPS_BACKEND_FAILED; |
| 793 |
} |
| 794 |
|
| 795 |
*rsplen = num; |
| 796 |
|
| 797 |
return CUPS_BACKEND_OK; |
| 798 |
} |
| 799 |
|
| 800 |
static int hiti_docmd_resp(struct hiti_ctx *ctx, uint16_t cmdid, |
| 801 |
const uint8_t *buf, uint8_t buf_len, |
| 802 |
uint8_t *respbuf, uint16_t *resplen) |
| 803 |
{ |
| 804 |
int ret, num = 0; |
| 805 |
uint16_t cmd_resp_len = *resplen; |
| 806 |
|
| 807 |
ret = hiti_docmd(ctx, cmdid, buf, buf_len, &cmd_resp_len); |
| 808 |
if (ret) |
| 809 |
return ret; |
| 810 |
|
| 811 |
if (cmd_resp_len > *resplen) { |
| 812 |
ERROR("Response too long! (%d vs %d)\n", cmd_resp_len, *resplen); |
| 813 |
*resplen = 0; |
| 814 |
return CUPS_BACKEND_FAILED; |
| 815 |
} |
| 816 |
|
| 817 |
__usleep(10*1000); |
| 818 |
|
| 819 |
/* Read back the data*/ |
| 820 |
int remain = *resplen; |
| 821 |
int total = 0; |
| 822 |
do { |
| 823 |
ret = read_data(ctx->conn, respbuf + total, remain, &num); |
| 824 |
if (ret) |
| 825 |
return ret; |
| 826 |
total += num; |
| 827 |
remain -= num; |
| 828 |
} while (remain > 0 && num == 64); |
| 829 |
|
| 830 |
/* Sanity check */ |
| 831 |
if (total > *resplen) { |
| 832 |
ERROR("Response too long for buffer (%d vs %d)!\n", total, *resplen); |
| 833 |
*resplen = 0; |
| 834 |
return CUPS_BACKEND_FAILED; |
| 835 |
} |
| 836 |
|
| 837 |
*resplen = total; |
| 838 |
|
| 839 |
return CUPS_BACKEND_OK; |
| 840 |
} |
| 841 |
|
| 842 |
static int hiti_shptc(struct hiti_ctx *ctx, const uint8_t *buf, uint32_t buf_len) |
| 843 |
{ |
| 844 |
uint8_t cmdbuf[sizeof(struct hiti_cmd) + 1]; |
| 845 |
struct hiti_cmd *cmd = (struct hiti_cmd *)cmdbuf; |
| 846 |
int cmdsize = 0; |
| 847 |
int ret, num = 0; |
| 848 |
|
| 849 |
cmd->hdr = 0xa5; |
| 850 |
if (buf_len > 0xffff-3) { |
| 851 |
cmd->cmd = cpu_to_be16(CMD_ESD_SHPTC2); |
| 852 |
cmd->len = cpu_to_be16((buf_len + 4) >> 8); |
| 853 |
cmdbuf[sizeof(struct hiti_cmd)] = (buf_len + 4) & 0xff; |
| 854 |
cmdsize = sizeof(struct hiti_cmd) + 1; |
| 855 |
} else { |
| 856 |
cmd->cmd = cpu_to_be16(CMD_ESD_SHPTC); |
| 857 |
cmd->len = cpu_to_be16(buf_len + 3); |
| 858 |
cmdsize = sizeof(struct hiti_cmd); |
| 859 |
} |
| 860 |
cmd->flag = (CMD_FLAG_DEST | CMD_FLAG_REPLY); |
| 861 |
|
| 862 |
/* Send over command */ |
| 863 |
if ((ret = send_data(ctx->conn, (uint8_t*) cmd, cmdsize))) { |
| 864 |
return ret; |
| 865 |
} |
| 866 |
|
| 867 |
__usleep(10*1000); |
| 868 |
|
| 869 |
/* Read back command */ |
| 870 |
ret = read_data(ctx->conn, cmdbuf, 6, &num); |
| 871 |
if (ret) |
| 872 |
return ret; |
| 873 |
|
| 874 |
if (num != 6) { |
| 875 |
ERROR("CMD Readback length mismatch (%d vs %d)!\n", num, 6); |
| 876 |
return CUPS_BACKEND_FAILED; |
| 877 |
} |
| 878 |
|
| 879 |
ret = send_data(ctx->conn, buf, buf_len); |
| 880 |
if (ret) |
| 881 |
return CUPS_BACKEND_FAILED; |
| 882 |
|
| 883 |
return CUPS_BACKEND_OK; |
| 884 |
} |
| 885 |
|
| 886 |
static int hiti_sepd(struct hiti_ctx *ctx, uint32_t buf_len, |
| 887 |
uint16_t startLine, uint16_t numLines) |
| 888 |
{ |
| 889 |
uint8_t cmdbuf[sizeof(struct hiti_extprintdata)]; |
| 890 |
struct hiti_extprintdata *cmd = (struct hiti_extprintdata *)cmdbuf; |
| 891 |
int ret, num = 0; |
| 892 |
|
| 893 |
buf_len += 8; |
| 894 |
|
| 895 |
cmd->hdr = 0xa5; |
| 896 |
cmd->len = cpu_to_be16(buf_len >> 8); |
| 897 |
cmd->flag = (CMD_FLAG_DEST | CMD_FLAG_REPLY); |
| 898 |
cmd->cmd = cpu_to_be16(CMD_ESD_SEPD); |
| 899 |
cmd->lenb = buf_len & 0xff; |
| 900 |
cmd->startLine = cpu_to_be16(startLine); |
| 901 |
cmd->numLines = cpu_to_be16(numLines); |
| 902 |
|
| 903 |
/* Send over command */ |
| 904 |
if ((ret = send_data(ctx->conn, (uint8_t*) cmd, sizeof(*cmd)))) { |
| 905 |
return ret; |
| 906 |
} |
| 907 |
|
| 908 |
__usleep(10*1000); |
| 909 |
|
| 910 |
/* Read back command */ |
| 911 |
ret = read_data(ctx->conn, cmdbuf, 6, &num); |
| 912 |
if (ret) |
| 913 |
return ret; |
| 914 |
|
| 915 |
if (num != 6) { |
| 916 |
ERROR("CMD Readback length mismatch (%d vs %d)!\n", num, 6); |
| 917 |
return CUPS_BACKEND_FAILED; |
| 918 |
} |
| 919 |
return CUPS_BACKEND_OK; |
| 920 |
} |
| 921 |
|
| 922 |
#define STATUS_IDLE 0x00 |
| 923 |
#define STATUS0_POWERON 0x01 |
| 924 |
#define STATUS0_RESEND_DATA 0x04 |
| 925 |
#define STATUS0_BUSY 0x80 |
| 926 |
#define STATUS1_SUPPLIES 0x01 |
| 927 |
#define STATUS1_PAPERJAM 0x02 |
| 928 |
#define STATUS1_INPUT 0x08 |
| 929 |
#define STATUS2_WARNING 0x02 |
| 930 |
#define STATUS2_DEVSERVICE 0x04 |
| 931 |
#define STATUS2_OPERATOR 0x08 |
| 932 |
|
| 933 |
static const char *hiti_status(const uint8_t *sts) |
| 934 |
{ |
| 935 |
if (sts[2] & STATUS2_WARNING) |
| 936 |
return "Warning"; |
| 937 |
else if (sts[2] & STATUS2_DEVSERVICE) |
| 938 |
return "Service Required"; |
| 939 |
else if (sts[2] & STATUS2_OPERATOR) |
| 940 |
return "Operator Intervention Required"; |
| 941 |
else if (sts[1] & STATUS1_PAPERJAM) |
| 942 |
return "Paper Jam"; |
| 943 |
else if (sts[1] & STATUS1_INPUT) |
| 944 |
return "Input Alert"; |
| 945 |
else if (sts[1] & STATUS1_SUPPLIES) |
| 946 |
return "Supply Alert"; |
| 947 |
else if (sts[0] & STATUS0_RESEND_DATA) |
| 948 |
return "Resend Data"; |
| 949 |
else if (sts[0] & STATUS0_BUSY) |
| 950 |
return "Busy"; |
| 951 |
else if (sts[0] & STATUS0_POWERON) |
| 952 |
return "Powering On"; |
| 953 |
else if (sts[0] == STATUS_IDLE) |
| 954 |
return "Accepting Jobs"; |
| 955 |
else |
| 956 |
return "Unknown"; |
| 957 |
} |
| 958 |
|
| 959 |
static const char *hiti_jobstatuses(uint8_t code) |
| 960 |
{ |
| 961 |
switch (code) { |
| 962 |
case QQA_STATUS_PRINTING: return "Printing"; |
| 963 |
case QQA_STATUS_WAITING: return "Waiting"; |
| 964 |
case QQA_STATUS_SUSPENDED: return "Suspended"; |
| 965 |
case QQA_STATUS_ERROR: return "Unknown Error"; |
| 966 |
default: return "Unknown"; |
| 967 |
} |
| 968 |
} |
| 969 |
|
| 970 |
static const char* hiti_ribbontypes(uint8_t code) |
| 971 |
{ |
| 972 |
switch (code) { |
| 973 |
case RIBBON_TYPE_4x6: return "4x6"; |
| 974 |
case RIBBON_TYPE_5x7: return "5x7"; |
| 975 |
case RIBBON_TYPE_6x9: return "6x9"; |
| 976 |
case RIBBON_TYPE_6x8: return "6x8"; |
| 977 |
default: return "Unknown"; |
| 978 |
} |
| 979 |
} |
| 980 |
|
| 981 |
static unsigned int hiti_ribboncounts(uint8_t code, uint8_t type) |
| 982 |
{ |
| 983 |
if (type == P_HITI_461 || |
| 984 |
type == P_HITI_320 || |
| 985 |
type == P_HITI_310) { |
| 986 |
switch(code) { |
| 987 |
case RIBBON_TYPE_4x6: return 60; |
| 988 |
default: return 999; |
| 989 |
} |
| 990 |
} else if (type == P_HITI_51X) { |
| 991 |
switch(code) { |
| 992 |
case RIBBON_TYPE_4x6: return 330; |
| 993 |
case RIBBON_TYPE_5x7: return 190; |
| 994 |
case RIBBON_TYPE_6x8: return 165; |
| 995 |
case RIBBON_TYPE_6x9: return 150; |
| 996 |
default: return 999; |
| 997 |
} |
| 998 |
} else if (type == P_HITI_520 || type == P_HITI_525 || type == P_HITI_530) { |
| 999 |
switch(code) { |
| 1000 |
case RIBBON_TYPE_4x6: return 500; |
| 1001 |
case RIBBON_TYPE_5x7: return 290; |
| 1002 |
case RIBBON_TYPE_6x8: return 250; |
| 1003 |
case RIBBON_TYPE_6x9: return 220; // XXX guess |
| 1004 |
default: return 999; |
| 1005 |
} |
| 1006 |
} else if (type == P_HITI_630) { |
| 1007 |
switch(code) { |
| 1008 |
case RIBBON_TYPE_4x6: return 430; |
| 1009 |
case RIBBON_TYPE_5x7: return 215; |
| 1010 |
case RIBBON_TYPE_6x8: return 215; |
| 1011 |
case RIBBON_TYPE_6x9: return 190; // XXX guess |
| 1012 |
default: return 999; |
| 1013 |
} |
| 1014 |
} else if (type == P_HITI_826) { |
| 1015 |
switch(code) { |
| 1016 |
case RIBBON_TYPE_4x6: return 400; |
| 1017 |
case RIBBON_TYPE_5x7: return 290; |
| 1018 |
case RIBBON_TYPE_6x8: return 200; |
| 1019 |
default: return 999; |
| 1020 |
} |
| 1021 |
} else if (type == P_SWIFTFOTO_KSF10) { |
| 1022 |
switch(code) { |
| 1023 |
case RIBBON_TYPE_4x6: return 500; |
| 1024 |
case RIBBON_TYPE_5x7: return 290; |
| 1025 |
case RIBBON_TYPE_6x8: return 250; // 200 on brochure, 250 in service manual |
| 1026 |
default: return 999; |
| 1027 |
} |
| 1028 |
} else if (type == P_HITI_720) { |
| 1029 |
switch(code) { |
| 1030 |
case RIBBON_TYPE_4x6: return 1000; |
| 1031 |
case RIBBON_TYPE_5x7: return 600; |
| 1032 |
case RIBBON_TYPE_6x8: return 455; |
| 1033 |
case RIBBON_TYPE_6x9: return 455; |
| 1034 |
default: return 999; |
| 1035 |
} |
| 1036 |
} else if (type == P_HITI_750) { |
| 1037 |
switch(code) { |
| 1038 |
case RIBBON_TYPE_4x6: return 1000; |
| 1039 |
case RIBBON_TYPE_5x7: return 600; |
| 1040 |
case RIBBON_TYPE_6x8: return 500; |
| 1041 |
case RIBBON_TYPE_6x9: return 455; |
| 1042 |
default: return 999; |
| 1043 |
} |
| 1044 |
} |
| 1045 |
|
| 1046 |
return 999; |
| 1047 |
} |
| 1048 |
|
| 1049 |
static const char* hiti_papers(uint8_t code) |
| 1050 |
{ |
| 1051 |
switch (code) { |
| 1052 |
case PAPER_TYPE_NONE : return "None"; |
| 1053 |
case PAPER_TYPE_5INCH: return "5 inch"; |
| 1054 |
case PAPER_TYPE_6INCH: return "6 inch"; |
| 1055 |
case PAPER_TYPE_X4INCH: return "4x6 sheet"; |
| 1056 |
default: return "Unknown"; |
| 1057 |
} |
| 1058 |
} |
| 1059 |
|
| 1060 |
static const char* hiti_regions(uint8_t code) |
| 1061 |
{ |
| 1062 |
switch (code) { |
| 1063 |
case 0x11: return "GB"; |
| 1064 |
case 0x12: |
| 1065 |
case 0x22: return "CN"; |
| 1066 |
case 0x13: return "NA"; |
| 1067 |
case 0x14: return "SA"; |
| 1068 |
case 0x15: return "EU"; |
| 1069 |
case 0x16: return "IN"; |
| 1070 |
case 0x17: return "DB"; |
| 1071 |
case 0xf0: // Seen on P510S |
| 1072 |
case 0x01: // Seen on P520L, P525L, U826, KSF-10R, P630 |
| 1073 |
default: |
| 1074 |
return "Unknown"; |
| 1075 |
} |
| 1076 |
} |
| 1077 |
|
| 1078 |
/* Supposedly correct for P720, P728, and P520 */ |
| 1079 |
static const char *hiti_errors(uint32_t code) |
| 1080 |
{ |
| 1081 |
switch(code) { |
| 1082 |
case 0x00000000: return "None"; |
| 1083 |
|
| 1084 |
#if 0 |
| 1085 |
/* Not sure about these, might be driver-generated? */ |
| 1086 |
case 0x00000001: return "Processing data"; |
| 1087 |
case 0x00000002: return "Sending data"; |
| 1088 |
case 0x00000003: return "Printing"; |
| 1089 |
case 0x00000004: return "End page"; |
| 1090 |
case 0x00000005: return "??"; |
| 1091 |
case 0x00000006: return "Starting job"; |
| 1092 |
case 0x00000008: return "Tray missing"; |
| 1093 |
|
| 1094 |
case 0x000000A1: return "Sending Y"; |
| 1095 |
case 0x000000A2: return "Sending M"; |
| 1096 |
case 0x000000A3: return "Sending C"; |
| 1097 |
case 0x000000A4: return "Sending O"; |
| 1098 |
#endif |
| 1099 |
/* Warning Alerts */ |
| 1100 |
case 0x000100FE: return "Paper type mismatch"; |
| 1101 |
case 0x000300FE: return "Buffer underrun when printing"; |
| 1102 |
case 0x000301FE: return "Command sequence error"; |
| 1103 |
case 0x000302FE: return "NAND flash unformatted"; |
| 1104 |
case 0x000303FE: return "NAND flash space insufficient"; |
| 1105 |
case 0x000304FE: return "Heating parameter table incompatible"; |
| 1106 |
/* Device Service Required Alerts */ |
| 1107 |
case 0x00030001: return "SRAM error"; |
| 1108 |
case 0x00030101: return "SDRAM error"; |
| 1109 |
case 0x00030201: return "ADC error"; |
| 1110 |
case 0x00030301: return "NVRAM R/W error"; |
| 1111 |
case 0x00030302: return "SDRAM checksum error"; |
| 1112 |
case 0x00030402: return "DSP code checksum error"; |
| 1113 |
case 0x00030501: return "Cam TPH error"; |
| 1114 |
case 0x00030502: return "NVRAM checksom error"; |
| 1115 |
case 0x00030601: return "Cam pinch error"; |
| 1116 |
case 0x00030602: return "SRAM checksum error"; |
| 1117 |
case 0x00030701: return "Firmware write error"; |
| 1118 |
case 0x00030702: return "Flash checksum error"; |
| 1119 |
case 0x00030802: return "Heating table checksum error"; |
| 1120 |
case 0x00030901: return "ADC error in slave printer"; |
| 1121 |
case 0x00030A01: return "Cam Platen error in slave printer"; |
| 1122 |
case 0x00030B01: return "NVRAM R/W error in slave printer"; |
| 1123 |
case 0x00030C02: return "NVRAM CRC error in slave printer"; |
| 1124 |
case 0x00030D02: return "SDRAM checksum error in slave printer"; |
| 1125 |
case 0x00030E02: return "SRAM checksum error in slave printer"; |
| 1126 |
case 0x00030F02: return "FLASH checksum error in slave printer"; |
| 1127 |
case 0x00031002: return "Wrong firmware checksum error in slave printer"; |
| 1128 |
case 0x00031101: return "Communication error with slave printer"; |
| 1129 |
case 0x00031201: return "NAND flash error"; |
| 1130 |
case 0x00031302: return "Cutter error"; |
| 1131 |
/* Operator Intervention Required Alerts */ |
| 1132 |
case 0x00050001: return "Cover open"; // XXX or no ribbon loaded on P461? |
| 1133 |
case 0x00050101: return "Cover open"; |
| 1134 |
case 0x000502FE: return "Dust box needs cleaning"; |
| 1135 |
/* Supplies Alerts */ |
| 1136 |
case 0x00080004: return "Ribbon missing"; |
| 1137 |
case 0x00080007: return "Ribbon newly inserted"; |
| 1138 |
case 0x00080103: return "Ribbon exhausted"; |
| 1139 |
case 0x00080104: return "Ribbon exhausted"; |
| 1140 |
case 0x00080105: return "Ribbon malfunction"; |
| 1141 |
case 0x00080204: return "Ribbon missing in slave printer"; |
| 1142 |
case 0x00080207: return "Ribbon newly inserted in slave printer"; |
| 1143 |
case 0x000802FE: return "Ribbon IC error"; |
| 1144 |
case 0x00080303: return "Ribbon exhausted in slave printer"; |
| 1145 |
case 0x000803FE: return "Ribbon not authenticated"; |
| 1146 |
case 0x000804FE: return "Ribbon IC read/write error"; |
| 1147 |
case 0x000805FE: return "Ribbon IC read/write error in slave printer"; |
| 1148 |
case 0x000806FE: return "Unsupported ribbon"; |
| 1149 |
case 0x000807FE: return "Unsupported ribbon in slave printer"; |
| 1150 |
case 0x000808FE: return "Unknown ribbon"; |
| 1151 |
case 0x000809FE: return "Unknown ribbon in slave printer"; |
| 1152 |
/* Jam Alerts */ |
| 1153 |
case 0x00030000: return "Paper jam"; |
| 1154 |
case 0x0003000F: return "Paper jam"; |
| 1155 |
case 0x00030200: return "Paper jam in paper path 01"; |
| 1156 |
case 0x00030300: return "Paper jam in paper path 02"; |
| 1157 |
case 0x00030400: return "Paper jam in paper path 03"; |
| 1158 |
case 0x00030500: return "Paper jam in paper path 04"; |
| 1159 |
case 0x00030600: return "Paper jam in paper path 05"; |
| 1160 |
case 0x00030700: return "Paper jam in paper path 06"; |
| 1161 |
case 0x00030800: return "Paper jam in paper path 07"; |
| 1162 |
case 0x00030900: return "Paper jam in paper path 08"; |
| 1163 |
case 0x00030A00: return "Paper jam in paper path 09"; |
| 1164 |
/* Input Alerts */ |
| 1165 |
case 0x00000008: return "Paper box missing"; |
| 1166 |
case 0x00000100: return "Cover open"; |
| 1167 |
case 0x00000101: return "Cover open failure"; |
| 1168 |
case 0x00000200: return "Ribbon IC missing"; |
| 1169 |
case 0x00000201: return "Ribbon missing"; |
| 1170 |
case 0x00000202: return "Ribbon mismatch 01"; |
| 1171 |
case 0x00000203: return "Security check fail"; |
| 1172 |
case 0x00000204: return "Ribbon mismatch 02"; |
| 1173 |
case 0x00000205: return "Ribbon mismatch 03"; |
| 1174 |
case 0x00000300: return "Ribbon exhausted 01"; |
| 1175 |
case 0x00000301: return "Ribbon exhausted 02"; |
| 1176 |
case 0x00000302: return "Printing failure (jam?)"; |
| 1177 |
case 0x00000400: return "Paper exhausted 01"; |
| 1178 |
case 0x00000401: return "Paper exhausted 02"; |
| 1179 |
case 0x00000402: return "Paper not ready"; |
| 1180 |
case 0x00000500: return "Paper jam 01"; |
| 1181 |
case 0x00000501: return "Paper jam 02"; |
| 1182 |
case 0x00000502: return "Paper jam 03"; |
| 1183 |
case 0x00000503: return "Paper jam 04"; |
| 1184 |
case 0x00000504: return "Paper jam 05"; |
| 1185 |
case 0x00000600: return "Paper mismatch"; |
| 1186 |
case 0x00000700: return "Cam error 01"; |
| 1187 |
case 0x00000800: return "Cam error 02"; |
| 1188 |
case 0x00000900: return "NVRAM error"; |
| 1189 |
case 0x00001000: return "IC error"; |
| 1190 |
case 0x00001200: return "ADC error"; |
| 1191 |
case 0x00001300: return "FW Check Error"; |
| 1192 |
case 0x00001500: return "Cutter error"; |
| 1193 |
|
| 1194 |
case 0x00007538: return "Device attached to printer"; |
| 1195 |
case 0x00007539: return "Printer is in mobile mode"; |
| 1196 |
case 0x00007540: return "Printer is in standalone mode"; |
| 1197 |
case 0x00007542: return "Firmware too old for Fine mode"; |
| 1198 |
case 0x00007543: return "Firmware too old for 2x6 mode"; |
| 1199 |
case 0x00007544: return "Firmware too old for Matte mode"; |
| 1200 |
case 0x00007545: return "Firmware too old"; |
| 1201 |
case 0x00007546: return "Firmware too old"; |
| 1202 |
|
| 1203 |
case 0x00008000: return "Paper out or feeding error"; |
| 1204 |
case 0x00008008: return "Paper box missing"; |
| 1205 |
case 0x00008010: return "Paper tray/roll mismatch"; |
| 1206 |
case 0x00008011: return "Paper tray mismatch (need photo tray)"; |
| 1207 |
case 0x00008012: return "Paper tray mismatch (need sticker 4/2/4 tray)"; |
| 1208 |
case 0x00008013: return "Paper tray mismatch (need sticker 4x4 tray)"; |
| 1209 |
case 0x00008014: return "Paper tray mismatch (need sticker 1x1 tray)"; |
| 1210 |
case 0x00008015: return "Paper tray mismatch (need PVC tray)"; |
| 1211 |
case 0x00080200: return "Unsupported ribbon type"; |
| 1212 |
case 0x00080201: return "Ribbon type mismatch (need YMCO)"; |
| 1213 |
case 0x00080203: return "Ribbon type mismatch (need KO)"; |
| 1214 |
case 0x00080230: return "Ribbon type mismatch (need KO)"; |
| 1215 |
case 0x00080240: return "Ribbon type mismatch (need 4x6)"; |
| 1216 |
case 0x00080250: return "Ribbon type mismatch (need 5x7)"; |
| 1217 |
case 0x00080260: return "Ribbon type mismatch (need 6x8)"; |
| 1218 |
// case 0x10008000: return "Paper out or paper low"; /* XXX this won't work, high byte is cleared */ |
| 1219 |
|
| 1220 |
default: return "Unknown"; |
| 1221 |
} |
| 1222 |
} |
| 1223 |
|
| 1224 |
static int hiti_dump_options(struct hiti_ctx *ctx) |
| 1225 |
{ |
| 1226 |
int ret; |
| 1227 |
uint8_t buf[256]; |
| 1228 |
uint16_t len = 256; |
| 1229 |
int i; |
| 1230 |
uint8_t *ptr; |
| 1231 |
|
| 1232 |
ret = hiti_docmd_resp(ctx, CMD_RDC_ROC, NULL, 0, |
| 1233 |
buf, &len); |
| 1234 |
if (ret) |
| 1235 |
return ret; |
| 1236 |
|
| 1237 |
ptr = buf; |
| 1238 |
while (len > 0 && *ptr) { |
| 1239 |
i = ptr[ptr[1]+2]; |
| 1240 |
ptr[ptr[1]+2] = 0; |
| 1241 |
INFO("Option %02x: '%s'\n", *ptr, ptr+2); |
| 1242 |
len -= ptr[1] + 2; |
| 1243 |
ptr += ptr[1] + 2; |
| 1244 |
*ptr = i; |
| 1245 |
} |
| 1246 |
|
| 1247 |
|
| 1248 |
return CUPS_BACKEND_OK; |
| 1249 |
} |
| 1250 |
|
| 1251 |
static int hiti_get_info(struct hiti_ctx *ctx) |
| 1252 |
{ |
| 1253 |
int ret; |
| 1254 |
|
| 1255 |
ret = hiti_query_tphv(ctx); |
| 1256 |
if (ret) |
| 1257 |
return ret; |
| 1258 |
ret = hiti_query_led_calibration(ctx); |
| 1259 |
if (ret) |
| 1260 |
return ret; |
| 1261 |
|
| 1262 |
INFO("Printer ID: %s\n", ctx->id); |
| 1263 |
INFO("Printer Version: %s\n", ctx->version); |
| 1264 |
INFO("Serial Number: %s\n", ctx->serno); |
| 1265 |
|
| 1266 |
if (ctx->conn->type != P_HITI_51X) { |
| 1267 |
ret = hiti_dump_options(ctx); |
| 1268 |
if (ret) |
| 1269 |
return ret; |
| 1270 |
} |
| 1271 |
|
| 1272 |
INFO("Calibration: H: %d V: %d\n", ctx->calibration.rows, ctx->calibration.cols); |
| 1273 |
INFO("LED Calibration: %d %d %d / %d %d %d\n", |
| 1274 |
ctx->led_calibration[4], ctx->led_calibration[5], |
| 1275 |
ctx->led_calibration[6], ctx->led_calibration[7], |
| 1276 |
ctx->led_calibration[8], ctx->led_calibration[9]); |
| 1277 |
INFO("TPH Voltage (T/L): %d %d\n", ctx->rtlv[0], ctx->rtlv[1]); |
| 1278 |
hiti_query_markers(ctx, NULL, NULL); |
| 1279 |
|
| 1280 |
if (!(ctx->conn->type == P_HITI_520 || ctx->conn->type == P_HITI_525 || ctx->conn->type == P_HITI_826 || ctx->conn->type == P_SWIFTFOTO_KSF10 || ctx->conn->type == P_HITI_630)) { |
| 1281 |
INFO("Region: %s (%02x)\n", |
| 1282 |
hiti_regions(ctx->rpidm.region), |
| 1283 |
ctx->rpidm.region); |
| 1284 |
} |
| 1285 |
|
| 1286 |
if (ctx->conn->type != P_HITI_51X) { |
| 1287 |
INFO("Highlight Adjustment (Y M C): %d %d %d\n", |
| 1288 |
ctx->hilight_adj[1], ctx->hilight_adj[2], ctx->hilight_adj[3]); |
| 1289 |
} |
| 1290 |
|
| 1291 |
INFO("Status Summary: %d %dx%d %dx%d\n", |
| 1292 |
ctx->erdc_rs.stride, |
| 1293 |
ctx->erdc_rs.cols, |
| 1294 |
ctx->erdc_rs.rows, |
| 1295 |
ctx->erdc_rs.dpi_cols, |
| 1296 |
ctx->erdc_rs.dpi_rows); |
| 1297 |
|
| 1298 |
uint32_t buf[2] = {0,0}; |
| 1299 |
ret = hiti_query_counter(ctx, 1, buf, ctx->erdc_rpc_len); |
| 1300 |
if (ret) |
| 1301 |
return CUPS_BACKEND_FAILED; |
| 1302 |
INFO("Total prints: %u\n", buf[0]); |
| 1303 |
|
| 1304 |
ret = hiti_query_counter(ctx, 2, buf, ctx->erdc_rpc_len); |
| 1305 |
if (ret) |
| 1306 |
return CUPS_BACKEND_FAILED; |
| 1307 |
INFO("6x4 prints: %u\n", buf[0]); |
| 1308 |
|
| 1309 |
if (!ctx->sheet) { |
| 1310 |
ret = hiti_query_counter(ctx, 3, buf, ctx->erdc_rpc_len); |
| 1311 |
if (ret) |
| 1312 |
return CUPS_BACKEND_FAILED; |
| 1313 |
INFO("5x7 prints: %u\n", buf[0]); |
| 1314 |
|
| 1315 |
ret = hiti_query_counter(ctx, 4, buf, ctx->erdc_rpc_len); |
| 1316 |
if (ret) |
| 1317 |
return CUPS_BACKEND_FAILED; |
| 1318 |
INFO("6x8 prints: %u\n", buf[0]); |
| 1319 |
|
| 1320 |
ret = hiti_query_counter(ctx, 5, buf, ctx->erdc_rpc_len); |
| 1321 |
if (ret) |
| 1322 |
return CUPS_BACKEND_FAILED; |
| 1323 |
INFO("6x9 prints: %u\n", buf[0]); |
| 1324 |
} |
| 1325 |
|
| 1326 |
// XXX other shit.. |
| 1327 |
|
| 1328 |
return CUPS_BACKEND_OK; |
| 1329 |
} |
| 1330 |
|
| 1331 |
/* Use jobid of 0 for "any" */ |
| 1332 |
static int hiti_query_job_qa(struct hiti_ctx *ctx, struct hiti_job *jobid, struct hiti_job_qqa *resp) |
| 1333 |
{ |
| 1334 |
int ret; |
| 1335 |
uint16_t len = sizeof(*resp); |
| 1336 |
|
| 1337 |
resp->count = 0; |
| 1338 |
ret = hiti_docmd_resp(ctx, CMD_JC_QQA, |
| 1339 |
(uint8_t*) jobid, sizeof(*jobid), |
| 1340 |
(uint8_t*) resp, &len); |
| 1341 |
if (ret) |
| 1342 |
return ret; |
| 1343 |
|
| 1344 |
return CUPS_BACKEND_OK; |
| 1345 |
} |
| 1346 |
|
| 1347 |
static int hiti_get_status(struct hiti_ctx *ctx) |
| 1348 |
{ |
| 1349 |
uint8_t sts[3]; |
| 1350 |
uint32_t err = 0; |
| 1351 |
int ret, i; |
| 1352 |
struct hiti_job_qqa qqa; |
| 1353 |
|
| 1354 |
hiti_query_markers(ctx, NULL, NULL); |
| 1355 |
ret = hiti_query_status(ctx, sts, &err); |
| 1356 |
if (ret) |
| 1357 |
return ret; |
| 1358 |
|
| 1359 |
INFO("Printer ID: %s\n", ctx->id); |
| 1360 |
INFO("Printer Version: %s\n", ctx->version); |
| 1361 |
INFO("Serial Number: %s\n", ctx->serno); |
| 1362 |
|
| 1363 |
INFO("Printer Status: %s (%02x %02x %02x)\n", |
| 1364 |
hiti_status(sts), sts[0], sts[1], sts[2]); |
| 1365 |
INFO("Printer Error: %s (%08x)\n", |
| 1366 |
hiti_errors(err), err); |
| 1367 |
|
| 1368 |
INFO("Media: %s (%02x / %04x) : %03u/%03u\n", |
| 1369 |
hiti_ribbontypes(ctx->ribbon.type), |
| 1370 |
ctx->ribbon.type, |
| 1371 |
ctx->ribbonvendor, |
| 1372 |
ctx->media_remain, hiti_ribboncounts(ctx->ribbon.type, ctx->conn->type)); |
| 1373 |
INFO("Paper: %s (%02x)\n", |
| 1374 |
hiti_papers(ctx->paper.type), |
| 1375 |
ctx->paper.type); |
| 1376 |
|
| 1377 |
/* Find out if we have any jobs outstanding */ |
| 1378 |
struct hiti_job job = { 0 }; |
| 1379 |
hiti_query_job_qa(ctx, &job, &qqa); |
| 1380 |
for (i = 0 ; i < qqa.count ; i++) { |
| 1381 |
INFO("JobID %02x %04x (status %s)\n", |
| 1382 |
qqa.row[i].job.lun, |
| 1383 |
be16_to_cpu(qqa.row[i].job.jobid), |
| 1384 |
hiti_jobstatuses(qqa.row[i].status)); |
| 1385 |
} |
| 1386 |
|
| 1387 |
// XXX other shit...? |
| 1388 |
|
| 1389 |
return CUPS_BACKEND_OK; |
| 1390 |
} |
| 1391 |
|
| 1392 |
static void *hiti_init(void) |
| 1393 |
{ |
| 1394 |
struct hiti_ctx *ctx = malloc(sizeof(struct hiti_ctx)); |
| 1395 |
if (!ctx) { |
| 1396 |
ERROR("Memory Allocation Failure!\n"); |
| 1397 |
return NULL; |
| 1398 |
} |
| 1399 |
memset(ctx, 0, sizeof(struct hiti_ctx)); |
| 1400 |
|
| 1401 |
if (getenv("HITI_NODATA")) { |
| 1402 |
ctx->nodata = 1; |
| 1403 |
} |
| 1404 |
return ctx; |
| 1405 |
} |
| 1406 |
|
| 1407 |
static int hiti_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid) |
| 1408 |
{ |
| 1409 |
struct hiti_ctx *ctx = vctx; |
| 1410 |
int ret; |
| 1411 |
|
| 1412 |
ctx->conn = conn; |
| 1413 |
|
| 1414 |
/* Ensure jobid is sane */ |
| 1415 |
ctx->jobid = (jobid & 0x7fff); |
| 1416 |
if (!ctx->jobid) |
| 1417 |
ctx->jobid++; |
| 1418 |
|
| 1419 |
if (ctx->conn->type == P_HITI_51X) { |
| 1420 |
ctx->erdc_rpc_len = 2; |
| 1421 |
} else { |
| 1422 |
ctx->erdc_rpc_len = 1; |
| 1423 |
} |
| 1424 |
|
| 1425 |
/* Sheet type */ |
| 1426 |
if (ctx->conn->type == P_HITI_461 || |
| 1427 |
ctx->conn->type == P_HITI_320 || |
| 1428 |
ctx->conn->type == P_HITI_310) { |
| 1429 |
ctx->sheet = 1; |
| 1430 |
} |
| 1431 |
|
| 1432 |
switch(ctx->conn->type) { |
| 1433 |
case P_HITI_461: |
| 1434 |
case P_HITI_320: |
| 1435 |
case P_HITI_310: |
| 1436 |
ctx->heattable_type = HEATTABLE_TYPE_V0; |
| 1437 |
break; |
| 1438 |
case P_HITI_51X: |
| 1439 |
ctx->heattable_type = HEATTABLE_TYPE_V1; |
| 1440 |
break; |
| 1441 |
default: |
| 1442 |
ctx->heattable_type = HEATTABLE_TYPE_V2; |
| 1443 |
} |
| 1444 |
|
| 1445 |
if (test_mode < TEST_MODE_NOATTACH) { |
| 1446 |
/* P520 firmware v1.19-v1.21 lose their minds when Linux |
| 1447 |
issues a routine CLEAR_ENDPOINT_HALT. Printer can recover |
| 1448 |
if it is reset. Unclear what the side effects are.. */ |
| 1449 |
if (ctx->conn->type == P_HITI_520) |
| 1450 |
libusb_reset_device(ctx->conn->dev); |
| 1451 |
|
| 1452 |
if (!ctx->sheet) { |
| 1453 |
ret = hiti_query_unk8010(ctx); |
| 1454 |
if (ret) |
| 1455 |
return ret; |
| 1456 |
} |
| 1457 |
if (ctx->conn->type == P_HITI_51X) { |
| 1458 |
ret = hiti_query_unk800c(ctx); |
| 1459 |
if (ret) |
| 1460 |
return ret; |
| 1461 |
} |
| 1462 |
ret = hiti_query_version(ctx); |
| 1463 |
if (ret) |
| 1464 |
return ret; |
| 1465 |
ret = hiti_query_supplies(ctx); |
| 1466 |
if (ret) |
| 1467 |
return ret; |
| 1468 |
ret = hiti_query_calibration(ctx); |
| 1469 |
if (ret) |
| 1470 |
return ret; |
| 1471 |
if (ctx->sheet) { |
| 1472 |
ctx->paper.type = PAPER_TYPE_X4INCH; |
| 1473 |
ctx->ribbonvendor = 0x1000; /* Hardcoded */ |
| 1474 |
} else { |
| 1475 |
ret = hiti_query_ribbonvendor(ctx); |
| 1476 |
if (ret) |
| 1477 |
return ret; |
| 1478 |
} |
| 1479 |
ret = hiti_query_rpidm(ctx); |
| 1480 |
if (ret) |
| 1481 |
return ret; |
| 1482 |
|
| 1483 |
if (ctx->conn->type != P_HITI_51X && !ctx->sheet) { |
| 1484 |
ret = hiti_query_hilightadj(ctx); |
| 1485 |
if (ret) |
| 1486 |
return ret; |
| 1487 |
} |
| 1488 |
|
| 1489 |
ret = hiti_query_serno(ctx->conn, ctx->serno, sizeof(ctx->serno)); |
| 1490 |
if (ret) |
| 1491 |
return ret; |
| 1492 |
|
| 1493 |
ret = hiti_query_summary(ctx, &ctx->erdc_rs); |
| 1494 |
if (ret) |
| 1495 |
return CUPS_BACKEND_FAILED; |
| 1496 |
|
| 1497 |
switch (ctx->conn->type) { |
| 1498 |
case P_HITI_310: |
| 1499 |
if (strncmp(ctx->version, "1.17.0", 6) < 0) |
| 1500 |
WARNING("Printer firmware %s out of date (vs %s), please update.\n", ctx->version, "v1.17.0"); |
| 1501 |
break; |
| 1502 |
case P_HITI_320: |
| 1503 |
if (strncmp(ctx->version, "1.04.0", 6) < 0) |
| 1504 |
WARNING("Printer firmware %s out of date (vs %s), please update.\n", ctx->version, "v1.04.0"); |
| 1505 |
break; |
| 1506 |
case P_HITI_461: |
| 1507 |
if (strncmp(ctx->version, "1.12.0", 6) < 0) |
| 1508 |
WARNING("Printer firmware %s out of date (vs %s), please update.\n", ctx->version, "v1.12.0"); |
| 1509 |
break; |
| 1510 |
// XXX P510s: v2.05.0 is latest known so far... |
| 1511 |
case P_HITI_520: |
| 1512 |
if (strncmp(ctx->version, "1.22", 4) < 0 && |
| 1513 |
strncmp(ctx->version, "1.17", 4) > 0) /* V1.18 -> v1.21 have a known USB CLEAR_ENDPOINT_HALT issue */ |
| 1514 |
WARNING("Printer firmware %s has a known USB bug, please update to at least v1.22\n", ctx->version); |
| 1515 |
else if (strncmp(ctx->version, "1.30", 4) < 0) |
| 1516 |
WARNING("Printer firmware %s out of date (vs %s), please update.\n", ctx->version, "v1.30"); |
| 1517 |
break; |
| 1518 |
case P_HITI_525: |
| 1519 |
if (strncmp(ctx->version, "1.05", 4) < 0) |
| 1520 |
WARNING("Printer firmware %s out of date (vs %s), please update.\n", ctx->version, "v1.05"); |
| 1521 |
break; |
| 1522 |
case P_HITI_530: |
| 1523 |
if (strncmp(ctx->version, "1.02.0", 6) < 0) |
| 1524 |
WARNING("Printer firmware %s out of date (vs %s), please update.\n", ctx->version, "v1.02.0"); |
| 1525 |
break; |
| 1526 |
case P_HITI_630: |
| 1527 |
if (strncmp(ctx->version, "9.05.2", 6) < 0) |
| 1528 |
WARNING("Printer firmware %s out of date (vs %s), please update.\n", ctx->version, "v9.05.2.3"); |
| 1529 |
break; |
| 1530 |
case P_HITI_720: |
| 1531 |
if (strncmp(ctx->version, "1.19", 4) < 0) |
| 1532 |
WARNING("Printer firmware %s out of date (vs %s), please update.\n", ctx->version, "v1.19"); |
| 1533 |
break; |
| 1534 |
case P_HITI_750: |
| 1535 |
if (strncmp(ctx->version, "1.22.0", 6) < 0) |
| 1536 |
WARNING("Printer firmware %s out of date (vs %s), please update.\n", ctx->version, "v1.22.0"); |
| 1537 |
break; |
| 1538 |
case P_HITI_826: |
| 1539 |
if (strncmp(ctx->version, "1.07.0", 6) < 0) |
| 1540 |
WARNING("Printer firmware %s out of date (vs %s), please update.\n", ctx->version, "v1.07.0"); |
| 1541 |
break; |
| 1542 |
case P_SWIFTFOTO_KSF10: |
| 1543 |
if (strncmp(ctx->version, "1.00.0", 6) < 0) |
| 1544 |
WARNING("Printer firmware %s out of date (vs %s), please update.\n", ctx->version, "v1.00.0"); |
| 1545 |
break; |
| 1546 |
default: |
| 1547 |
break; |
| 1548 |
} |
| 1549 |
// do real stuff |
| 1550 |
} else { |
| 1551 |
if (ctx->sheet) { |
| 1552 |
ctx->paper.type = PAPER_TYPE_X4INCH; |
| 1553 |
ctx->erdc_rs.cols = 1280; |
| 1554 |
} else { |
| 1555 |
ctx->paper.type = PAPER_TYPE_6INCH; |
| 1556 |
ctx->erdc_rs.cols = 1844; |
| 1557 |
} |
| 1558 |
|
| 1559 |
ctx->ribbon.type = RIBBON_TYPE_4x6; |
| 1560 |
ctx->ribbonvendor = 0x101f; /* CHC, type 0x1f */ |
| 1561 |
if (getenv("MEDIA_CODE") && strlen(getenv("MEDIA_CODE"))) { |
| 1562 |
// set fake fw version? |
| 1563 |
ctx->ribbon.type = strtol(getenv("MEDIA_CODE"), NULL, 16); |
| 1564 |
if (ctx->ribbon.type == RIBBON_TYPE_5x7) |
| 1565 |
ctx->paper.type = PAPER_TYPE_5INCH; |
| 1566 |
} |
| 1567 |
} |
| 1568 |
|
| 1569 |
ctx->marker.color = "#00FFFF#FF00FF#FFFF00"; |
| 1570 |
ctx->marker.name = hiti_ribbontypes(ctx->ribbon.type); |
| 1571 |
ctx->marker.levelmax = hiti_ribboncounts(ctx->ribbon.type, ctx->conn->type); |
| 1572 |
ctx->marker.levelnow = 0; |
| 1573 |
|
| 1574 |
if (ctx->sheet) |
| 1575 |
ctx->marker.numtype = -1; |
| 1576 |
else |
| 1577 |
ctx->marker.numtype = ctx->ribbon.type; |
| 1578 |
|
| 1579 |
return CUPS_BACKEND_OK; |
| 1580 |
} |
| 1581 |
|
| 1582 |
static void hiti_cleanup_job(const void *vjob) { |
| 1583 |
const struct hiti_printjob *job = vjob; |
| 1584 |
|
| 1585 |
if (job->databuf) |
| 1586 |
free(job->databuf); |
| 1587 |
|
| 1588 |
if (job->heattable_v2) |
| 1589 |
free(job->heattable_v2); |
| 1590 |
if (job->heattable_buf) |
| 1591 |
free(job->heattable_buf); |
| 1592 |
// job->num_heattable_entries = 0; |
| 1593 |
|
| 1594 |
free((void*)job); |
| 1595 |
} |
| 1596 |
|
| 1597 |
static void *hiti_get_heat_data(struct hiti_ctx *ctx, uint8_t mode, uint8_t colormode, int ribbonvendor, int *len) |
| 1598 |
{ |
| 1599 |
int ret; |
| 1600 |
void *buf; |
| 1601 |
|
| 1602 |
int mediaver = ribbonvendor & RRVC_VERSION_MASK; |
| 1603 |
int mediatype = ribbonvendor & RRVC_VENDOR_MASK; |
| 1604 |
|
| 1605 |
const char *modelname = hiti_modelcode(ctx->conn->type, ctx->erdc_rs.hwFeature1 & 0x80); // XXX P52x only |
| 1606 |
const char *modename; |
| 1607 |
const char *medianame; |
| 1608 |
char fname_base[24]; |
| 1609 |
|
| 1610 |
buf = malloc(HEATTABLE_V2_MAX_SIZE); |
| 1611 |
if (!buf) { |
| 1612 |
WARNING("Memory allocation failure!\n"); |
| 1613 |
return NULL; |
| 1614 |
} |
| 1615 |
|
| 1616 |
switch (colormode) { |
| 1617 |
case HT_COLORMODE_METALLIC: |
| 1618 |
modename = "m"; |
| 1619 |
mode = 0; |
| 1620 |
break; |
| 1621 |
case HT_COLORMODE_HIGHDENSITY: |
| 1622 |
modename = "h"; |
| 1623 |
mode = 0; |
| 1624 |
break; |
| 1625 |
case HT_COLORMODE_TRANSPARENT: |
| 1626 |
modename = "r"; |
| 1627 |
mode = 0; |
| 1628 |
break; |
| 1629 |
default: |
| 1630 |
if (mode) { |
| 1631 |
modename = "q"; |
| 1632 |
} else { |
| 1633 |
modename = "t"; |
| 1634 |
} // XXX p/o/s ?? |
| 1635 |
break; |
| 1636 |
} |
| 1637 |
|
| 1638 |
if (mediatype == 0x1000) { |
| 1639 |
medianame = "c"; |
| 1640 |
} else { |
| 1641 |
medianame = "h"; |
| 1642 |
} // XXX 'd' ?? |
| 1643 |
|
| 1644 |
// XXX special case! hea0qcra.bin/heatqcra.bin, and hea0tcra.bin/heattcra.bin, and they differ! |
| 1645 |
|
| 1646 |
DEBUG("Locating heat table for model %d, mode %02x/%02x media %02x, ver %02x\n", |
| 1647 |
ctx->conn->type, mode, colormode, mediatype >> 8, mediaver); |
| 1648 |
|
| 1649 |
while (mediaver >= 0) { |
| 1650 |
char full[2048]; |
| 1651 |
|
| 1652 |
char ver; |
| 1653 |
|
| 1654 |
if (mediaver == 0) |
| 1655 |
ver = 't'; |
| 1656 |
else if (mediaver < 10) |
| 1657 |
ver = '0' + mediaver; |
| 1658 |
else |
| 1659 |
ver = 'a' + mediaver - 10; |
| 1660 |
|
| 1661 |
/* Build base name */ |
| 1662 |
snprintf(fname_base, sizeof(fname_base)-1, "hea%c%s%s%s.bin", ver, modename, medianame, modelname); |
| 1663 |
|
| 1664 |
snprintf(full, sizeof(full), "%s/%s", corrtable_path, fname_base); |
| 1665 |
|
| 1666 |
ret = dyesub_read_file2(full, buf, HEATTABLE_V2_MAX_SIZE, len, 1); |
| 1667 |
if (!ret) |
| 1668 |
break; |
| 1669 |
|
| 1670 |
mediaver--; |
| 1671 |
} |
| 1672 |
|
| 1673 |
if (mediaver < 0) { |
| 1674 |
WARNING("Unable to find suitable heat table file (%s) skipping\n", fname_base); |
| 1675 |
free(buf); |
| 1676 |
return NULL; |
| 1677 |
} |
| 1678 |
|
| 1679 |
DEBUG("Using heat table in (%s)\n", fname_base); |
| 1680 |
|
| 1681 |
return buf; |
| 1682 |
} |
| 1683 |
|
| 1684 |
#define CORRECTION_FILE_SIZE (33*33*33*3 + 2) |
| 1685 |
static uint8_t *hiti_get_correction_data(struct hiti_ctx *ctx, uint8_t mode, int colormode, int ribbonvendor) |
| 1686 |
{ |
| 1687 |
uint8_t *buf; |
| 1688 |
int ret, len; |
| 1689 |
|
| 1690 |
int mediaver = ribbonvendor & RRVC_VERSION_MASK; |
| 1691 |
int mediatype = ribbonvendor & RRVC_VENDOR_MASK; |
| 1692 |
|
| 1693 |
const char *modelname = hiti_modelcode(ctx->conn->type, ctx->erdc_rs.hwFeature1 & 0x80); |
| 1694 |
const char *colorname = NULL; |
| 1695 |
const char *modename; |
| 1696 |
const char *medianame; |
| 1697 |
char fname_base[24] = {0}; |
| 1698 |
|
| 1699 |
buf = malloc(CORRECTION_FILE_SIZE); |
| 1700 |
if (!buf) { |
| 1701 |
WARNING("Memory allocation failure!\n"); |
| 1702 |
return NULL; |
| 1703 |
} |
| 1704 |
|
| 1705 |
if (ctx->conn->type == P_HITI_CS2XX) { |
| 1706 |
colorname = "B"; // XXX many more, investigate more carefully. |
| 1707 |
} else if (ctx->conn->type == P_HITI_520 || |
| 1708 |
ctx->conn->type == P_HITI_525 || |
| 1709 |
ctx->conn->type == P_HITI_826 || |
| 1710 |
ctx->conn->type == P_HITI_630 || // XXX eventually? |
| 1711 |
ctx->conn->type == P_SWIFTFOTO_KSF10) { |
| 1712 |
if (colormode == HT_COLORMODE_METALLIC) |
| 1713 |
colorname = "M"; |
| 1714 |
else if (colormode == HT_COLORMODE_HIGHDENSITY) |
| 1715 |
colorname = "H"; |
| 1716 |
else if (colormode == HT_COLORMODE_TRANSPARENT) |
| 1717 |
colorname = "T"; |
| 1718 |
} |
| 1719 |
|
| 1720 |
if (!colorname) { |
| 1721 |
if (colormode == HT_COLORMODE_CLASSIC) { |
| 1722 |
colorname = "CL"; |
| 1723 |
} else if (colormode == HT_COLORMODE_IDPASS_VIVID) { |
| 1724 |
colorname = "P"; |
| 1725 |
} else { |
| 1726 |
colorname = "I"; |
| 1727 |
} // XXX PR, L, LR, C, SO, B, and more? |
| 1728 |
} |
| 1729 |
|
| 1730 |
if (mode) { |
| 1731 |
modename = "Q"; |
| 1732 |
} else { |
| 1733 |
modename = "P"; |
| 1734 |
} |
| 1735 |
|
| 1736 |
if (mediatype == 0x1000) { |
| 1737 |
medianame = "C"; |
| 1738 |
} else { |
| 1739 |
medianame = "M"; |
| 1740 |
} // XXX K/D ?? |
| 1741 |
|
| 1742 |
DEBUG("Locating correction data for model %d, mode %02x, media %02x, ver %02x, color %02x\n", |
| 1743 |
ctx->conn->type, mode, mediatype >> 8, mediaver, colormode); |
| 1744 |
|
| 1745 |
/* Prefer file with explicit '0' version, fall back to one without it. */ |
| 1746 |
while (mediaver >= -1) { |
| 1747 |
char full[2048]; |
| 1748 |
|
| 1749 |
/* Build base name */ |
| 1750 |
if (mediaver >= 0) |
| 1751 |
snprintf(fname_base, sizeof(fname_base)-1, "C%s%s%s%c%s.bin", |
| 1752 |
medianame, modename, colorname, |
| 1753 |
mediaver < 10 ? '0' + mediaver : 'a' + mediaver - 10, |
| 1754 |
modelname); |
| 1755 |
else |
| 1756 |
snprintf(fname_base, sizeof(fname_base)-1, "C%s%s%s%s.bin", medianame, modename, colorname, modelname); |
| 1757 |
|
| 1758 |
snprintf(full, sizeof(full), "%s/%s", corrtable_path, fname_base); |
| 1759 |
ret = dyesub_read_file2(full, buf, CORRECTION_FILE_SIZE, &len, 1); |
| 1760 |
if (!ret && len == CORRECTION_FILE_SIZE) { |
| 1761 |
break; |
| 1762 |
} |
| 1763 |
|
| 1764 |
mediaver--; |
| 1765 |
} |
| 1766 |
|
| 1767 |
if (mediaver < -1) { |
| 1768 |
WARNING("Unable to find suitable correction data file (%s) skipping\n", fname_base); |
| 1769 |
free(buf); |
| 1770 |
return NULL; |
| 1771 |
} |
| 1772 |
|
| 1773 |
DEBUG("Using correction data in (%s)\n", fname_base); |
| 1774 |
|
| 1775 |
return buf; |
| 1776 |
} |
| 1777 |
|
| 1778 |
static int hiti_seht2(struct hiti_ctx *ctx, uint8_t plane, |
| 1779 |
const uint8_t *buf, uint32_t buf_len) |
| 1780 |
{ |
| 1781 |
uint8_t cmdbuf[sizeof(struct hiti_seht2)]; |
| 1782 |
struct hiti_seht2 *cmd = (struct hiti_seht2 *)cmdbuf; |
| 1783 |
int ret, num = 0; |
| 1784 |
|
| 1785 |
buf_len += 5; |
| 1786 |
|
| 1787 |
cmd->hdr = 0xa5; |
| 1788 |
cmd->len = cpu_to_be16(buf_len >> 8); |
| 1789 |
cmd->flag = (CMD_FLAG_DEST | CMD_FLAG_REPLY); |
| 1790 |
cmd->cmd = cpu_to_be16(CMD_ESD_SEHT2); |
| 1791 |
cmd->lenb = buf_len & 0xff; |
| 1792 |
cmd->plane = plane; |
| 1793 |
|
| 1794 |
buf_len -= 5; |
| 1795 |
|
| 1796 |
/* Send over command */ |
| 1797 |
if ((ret = send_data(ctx->conn, (uint8_t*) cmd, sizeof(*cmd)))) { |
| 1798 |
return ret; |
| 1799 |
} |
| 1800 |
|
| 1801 |
__usleep(10*1000); |
| 1802 |
|
| 1803 |
/* Read back command */ |
| 1804 |
ret = read_data(ctx->conn, cmdbuf, 6, &num); |
| 1805 |
if (ret) |
| 1806 |
return ret; |
| 1807 |
|
| 1808 |
// XXX check resp length? |
| 1809 |
|
| 1810 |
/* Send payload, if any */ |
| 1811 |
if (buf_len) { |
| 1812 |
ret = send_data(ctx->conn, buf, buf_len); |
| 1813 |
} |
| 1814 |
|
| 1815 |
__usleep(200*1000); |
| 1816 |
|
| 1817 |
return ret; |
| 1818 |
} |
| 1819 |
|
| 1820 |
static int hiti_cvd(struct hiti_ctx *ctx, const uint8_t *buf, uint32_t buf_len) |
| 1821 |
{ |
| 1822 |
uint8_t cmdbuf[sizeof(struct hiti_cmd)]; |
| 1823 |
struct hiti_cmd *cmd = (struct hiti_cmd *)cmdbuf; |
| 1824 |
int ret, num = 0; |
| 1825 |
|
| 1826 |
cmd->hdr = 0xa5; |
| 1827 |
cmd->len = cpu_to_be16(buf_len + 3); |
| 1828 |
cmd->flag = (CMD_FLAG_DEST | CMD_FLAG_REPLY); |
| 1829 |
cmd->cmd = cpu_to_be16(CMD_EDM_CVD); |
| 1830 |
|
| 1831 |
/* Send over command */ |
| 1832 |
if ((ret = send_data(ctx->conn, (uint8_t*) cmd, sizeof(*cmd)))) { |
| 1833 |
return ret; |
| 1834 |
} |
| 1835 |
|
| 1836 |
__usleep(10*1000); |
| 1837 |
|
| 1838 |
/* Read back command */ |
| 1839 |
ret = read_data(ctx->conn, cmdbuf, 6, &num); |
| 1840 |
if (ret) |
| 1841 |
return ret; |
| 1842 |
|
| 1843 |
// XXX check resp length? |
| 1844 |
|
| 1845 |
/* Send payload, if any */ |
| 1846 |
if (buf_len) { |
| 1847 |
ret = send_data(ctx->conn, buf, buf_len); |
| 1848 |
} |
| 1849 |
|
| 1850 |
__usleep(200*1000); |
| 1851 |
|
| 1852 |
return ret; |
| 1853 |
} |
| 1854 |
|
| 1855 |
static void *hiti_heattablev1_find_entry(uint8_t *data, int type, int totallen) |
| 1856 |
{ |
| 1857 |
int offset = 0; |
| 1858 |
while (offset < totallen) { |
| 1859 |
struct hiti_heattable_hdr_v1 *hdr = (struct hiti_heattable_hdr_v1 *) (data + offset); |
| 1860 |
offset += sizeof(*hdr); |
| 1861 |
|
| 1862 |
if (hdr->type == type) |
| 1863 |
return data + offset; |
| 1864 |
offset += (le32_to_cpu(hdr->len) * 2); |
| 1865 |
} |
| 1866 |
return NULL; |
| 1867 |
} |
| 1868 |
|
| 1869 |
static int hiti_send_heat_data_v1(struct hiti_ctx *ctx, void *heatdata, int len, uint8_t matte) |
| 1870 |
{ |
| 1871 |
uint8_t *y, *m, *c, *o, *om, *cvd; |
| 1872 |
|
| 1873 |
int ret; |
| 1874 |
|
| 1875 |
y = hiti_heattablev1_find_entry(heatdata, HITI_HEATTABLE_V1_Y, len); |
| 1876 |
m = hiti_heattablev1_find_entry(heatdata, HITI_HEATTABLE_V1_M, len); |
| 1877 |
c = hiti_heattablev1_find_entry(heatdata, HITI_HEATTABLE_V1_C, len); |
| 1878 |
o = hiti_heattablev1_find_entry(heatdata, HITI_HEATTABLE_V1_O, len); |
| 1879 |
om = hiti_heattablev1_find_entry(heatdata, HITI_HEATTABLE_V1_OM, len); |
| 1880 |
cvd = hiti_heattablev1_find_entry(heatdata, HITI_HEATTABLE_V1_CVD, len); |
| 1881 |
|
| 1882 |
if (!y || !m || !c || !o || !om || !cvd) { |
| 1883 |
ERROR("Heattable incomplete\n"); |
| 1884 |
return CUPS_BACKEND_FAILED; |
| 1885 |
} |
| 1886 |
|
| 1887 |
/* Send over the heat tables */ |
| 1888 |
ret = hiti_seht2(ctx, 0, y, HITI_HEATTABLE_V1_PLANESIZE); |
| 1889 |
if (!ret) |
| 1890 |
ret = hiti_seht2(ctx, 1, m, HITI_HEATTABLE_V1_PLANESIZE); |
| 1891 |
if (!ret) |
| 1892 |
ret = hiti_seht2(ctx, 2, c, HITI_HEATTABLE_V1_PLANESIZE); |
| 1893 |
if (!ret) { |
| 1894 |
if (matte) |
| 1895 |
ret = hiti_seht2(ctx, 3, om, HITI_HEATTABLE_V1_PLANESIZE); |
| 1896 |
else |
| 1897 |
ret = hiti_seht2(ctx, 3, o, HITI_HEATTABLE_V1_PLANESIZE); |
| 1898 |
} |
| 1899 |
|
| 1900 |
/* And finally, send over the CVD data */ |
| 1901 |
if (!ret) |
| 1902 |
ret = hiti_cvd(ctx, cvd, HITI_HEATTABLE_V1_CVDSIZE); |
| 1903 |
|
| 1904 |
return ret; |
| 1905 |
} |
| 1906 |
|
| 1907 |
/* HiTi's funky interpolation table processing |
| 1908 |
|
| 1909 |
Note this is a standard "CUBE" LUT (33x33x33) so there are options |
| 1910 |
for making this faster! |
| 1911 |
*/ |
| 1912 |
struct rgb { |
| 1913 |
uint8_t r; |
| 1914 |
uint8_t g; |
| 1915 |
uint8_t b; |
| 1916 |
}; |
| 1917 |
|
| 1918 |
static uint32_t interp1089[33]; |
| 1919 |
static uint32_t interp33[33]; |
| 1920 |
static uint16_t interp256[256*9]; |
| 1921 |
|
| 1922 |
static void hiti_interp_init(void) |
| 1923 |
{ |
| 1924 |
int i; |
| 1925 |
uint16_t *pre, *cur; |
| 1926 |
|
| 1927 |
for (i = 0 ; i < 33 ; i++) { |
| 1928 |
interp1089[i] = i * 1089; |
| 1929 |
interp33[i] = i * 33; |
| 1930 |
} |
| 1931 |
memset(interp256, 0, sizeof(interp256)); |
| 1932 |
pre = &interp256[0]; |
| 1933 |
cur = &interp256[256]; |
| 1934 |
|
| 1935 |
for (i = 1 ; i < 9 ; i++) { |
| 1936 |
int j; |
| 1937 |
for (j = 0 ; j < 256 ; j++) { |
| 1938 |
cur[j] = pre[j] + j; |
| 1939 |
}; |
| 1940 |
pre += 256; |
| 1941 |
cur += 256; |
| 1942 |
} |
| 1943 |
} |
| 1944 |
|
| 1945 |
/* src and dst are RGB tuples */ |
| 1946 |
static void hiti_interp33_256(uint8_t *dst, const uint8_t *src, const uint8_t *pTable) |
| 1947 |
{ |
| 1948 |
struct rgb p1_pos, p2_pos, p3_pos, p4_pos; |
| 1949 |
struct rgb p1_val, p2_val, p3_val, p4_val; |
| 1950 |
uint8_t r_weight, g_weight, b_weight; |
| 1951 |
uint16_t w1, w2, w3, w4; |
| 1952 |
uint16_t *pw1, *pw2, *pw3, *pw4; |
| 1953 |
uint32_t pos; |
| 1954 |
|
| 1955 |
/* Get Grid position */ |
| 1956 |
p1_pos.r = src[0] >> 3; |
| 1957 |
p1_pos.g = src[1] >> 3; |
| 1958 |
p1_pos.b = src[2] >> 3; |
| 1959 |
|
| 1960 |
p4_pos.r = p1_pos.r + 1; |
| 1961 |
p4_pos.g = p1_pos.g + 1; |
| 1962 |
p4_pos.b = p1_pos.b + 1; |
| 1963 |
|
| 1964 |
/* Weights */ |
| 1965 |
if (src[0] == 255) |
| 1966 |
r_weight = 8; |
| 1967 |
else |
| 1968 |
r_weight = src[0] & 0x7; |
| 1969 |
|
| 1970 |
if (src[1] == 255) |
| 1971 |
g_weight = 8; |
| 1972 |
else |
| 1973 |
g_weight = src[1] & 0x7; |
| 1974 |
|
| 1975 |
if (src[2] == 255) |
| 1976 |
b_weight = 8; |
| 1977 |
else |
| 1978 |
b_weight = src[2] & 0x7; |
| 1979 |
|
| 1980 |
/* Work out relative weights and offsets */ |
| 1981 |
if (r_weight >= g_weight) { |
| 1982 |
if (g_weight >= b_weight) { /* R > G > B */ |
| 1983 |
w1 = 8 - r_weight; |
| 1984 |
w2 = r_weight - g_weight; |
| 1985 |
w3 = g_weight - b_weight; |
| 1986 |
w4 = b_weight; |
| 1987 |
p2_pos.r = p1_pos.r + 1; |
| 1988 |
p2_pos.g = p1_pos.g; |
| 1989 |
p2_pos.b = p1_pos.b; |
| 1990 |
p3_pos.r = p1_pos.r + 1; |
| 1991 |
p3_pos.g = p1_pos.g + 1; |
| 1992 |
p3_pos.b = p1_pos.b; |
| 1993 |
} else { |
| 1994 |
if (r_weight >= b_weight) { /* R > B > G */ |
| 1995 |
w1 = 8 - r_weight; |
| 1996 |
w2 = r_weight - b_weight; |
| 1997 |
w3 = b_weight - g_weight; |
| 1998 |
w4 = g_weight; |
| 1999 |
p2_pos.r = p1_pos.r + 1; |
| 2000 |
p2_pos.g = p1_pos.g; |
| 2001 |
p2_pos.b = p1_pos.b; |
| 2002 |
p3_pos.r = p1_pos.r + 1; |
| 2003 |
p3_pos.g = p1_pos.g; |
| 2004 |
p3_pos.b = p1_pos.b + 1; |
| 2005 |
} else { /* B > R > G */ |
| 2006 |
w1 = 8 - b_weight; |
| 2007 |
w2 = b_weight - r_weight; |
| 2008 |
w3 = r_weight - g_weight; |
| 2009 |
w4 = g_weight; |
| 2010 |
p2_pos.r = p1_pos.r; |
| 2011 |
p2_pos.g = p1_pos.g; |
| 2012 |
p2_pos.b = p1_pos.b + 1; |
| 2013 |
p3_pos.r = p1_pos.r + 1; |
| 2014 |
p3_pos.g = p1_pos.g; |
| 2015 |
p3_pos.b = p1_pos.b + 1; |
| 2016 |
} |
| 2017 |
} |
| 2018 |
} else { |
| 2019 |
if (r_weight >= b_weight) { /* G > R > B */ |
| 2020 |
w1 = 8 - g_weight; |
| 2021 |
w2 = g_weight - r_weight; |
| 2022 |
w3 = r_weight - b_weight; |
| 2023 |
w4 = b_weight; |
| 2024 |
p2_pos.r = p1_pos.r; |
| 2025 |
p2_pos.g = p1_pos.g + 1; |
| 2026 |
p2_pos.b = p1_pos.b; |
| 2027 |
p3_pos.r = p1_pos.r + 1; |
| 2028 |
p3_pos.g = p1_pos.g + 1; |
| 2029 |
p3_pos.b = p1_pos.b; |
| 2030 |
} else { |
| 2031 |
if (g_weight >= b_weight) { /* G > B > R */ |
| 2032 |
w1 = 8 - g_weight; |
| 2033 |
w2 = g_weight - b_weight; |
| 2034 |
w3 = b_weight - r_weight; |
| 2035 |
w4 = r_weight; |
| 2036 |
p2_pos.r = p1_pos.r; |
| 2037 |
p2_pos.g = p1_pos.g + 1; |
| 2038 |
p2_pos.b = p1_pos.b; |
| 2039 |
p3_pos.r = p1_pos.r; |
| 2040 |
p3_pos.g = p1_pos.g + 1; |
| 2041 |
p3_pos.b = p1_pos.b + 1; |
| 2042 |
} else { /* B > G > R */ |
| 2043 |
w1 = 8 - b_weight; |
| 2044 |
w2 = b_weight - g_weight; |
| 2045 |
w3 = g_weight - r_weight; |
| 2046 |
w4 = r_weight; |
| 2047 |
p2_pos.r = p1_pos.r; |
| 2048 |
p2_pos.g = p1_pos.g; |
| 2049 |
p2_pos.b = p1_pos.b + 1; |
| 2050 |
p3_pos.r = p1_pos.r; |
| 2051 |
p3_pos.g = p1_pos.g + 1; |
| 2052 |
p3_pos.b = p1_pos.b + 1; |
| 2053 |
} |
| 2054 |
} |
| 2055 |
} |
| 2056 |
|
| 2057 |
/* Work out values */ |
| 2058 |
pos = (interp1089[p1_pos.b] + interp33[p1_pos.g] + p1_pos.r) * 3; |
| 2059 |
p1_val.r = pTable[pos]; |
| 2060 |
p1_val.g = pTable[pos + 1]; |
| 2061 |
p1_val.b = pTable[pos + 2]; |
| 2062 |
pos = (interp1089[p2_pos.b] + interp33[p2_pos.g] + p2_pos.r) * 3; |
| 2063 |
p2_val.r = pTable[pos]; |
| 2064 |
p2_val.g = pTable[pos + 1]; |
| 2065 |
p2_val.b = pTable[pos + 2]; |
| 2066 |
pos = (interp1089[p3_pos.b] + interp33[p3_pos.g] + p3_pos.r) * 3; |
| 2067 |
p3_val.r = pTable[pos]; |
| 2068 |
p3_val.g = pTable[pos + 1]; |
| 2069 |
p3_val.b = pTable[pos + 2]; |
| 2070 |
pos = (interp1089[p4_pos.b] + interp33[p4_pos.g] + p4_pos.r) * 3; |
| 2071 |
p4_val.r = pTable[pos]; |
| 2072 |
p4_val.g = pTable[pos + 1]; |
| 2073 |
p4_val.b = pTable[pos + 2]; |
| 2074 |
|
| 2075 |
/* Final offsets into interpolation table */ |
| 2076 |
pw1 = &interp256[w1 << 8]; |
| 2077 |
pw2 = &interp256[w2 << 8]; |
| 2078 |
pw3 = &interp256[w3 << 8]; |
| 2079 |
pw4 = &interp256[w4 << 8]; |
| 2080 |
|
| 2081 |
/* And at long last.. final values */ |
| 2082 |
dst[0] = (pw1[p1_val.r] + pw2[p2_val.r] + pw3[p3_val.r] + pw4[p4_val.r]) >> 3; |
| 2083 |
dst[1] = (pw1[p1_val.g] + pw2[p2_val.g] + pw3[p3_val.g] + pw4[p4_val.g]) >> 3; |
| 2084 |
dst[2] = (pw1[p1_val.b] + pw2[p2_val.b] + pw3[p3_val.b] + pw4[p4_val.b]) >> 3; |
| 2085 |
|
| 2086 |
} |
| 2087 |
|
| 2088 |
static int hiti630_compute_score(double mean) |
| 2089 |
{ |
| 2090 |
int score = 9 - (int)(mean / 25.5); |
| 2091 |
if (score < 0) |
| 2092 |
return 0; |
| 2093 |
if (score > 9) |
| 2094 |
return 9; |
| 2095 |
return score; |
| 2096 |
} |
| 2097 |
|
| 2098 |
static int hiti630_check_quality_16(int *scores, double *below40) |
| 2099 |
{ |
| 2100 |
int total = 0; |
| 2101 |
|
| 2102 |
int i; |
| 2103 |
|
| 2104 |
for (i = 0 ; i < 16 ; i++) |
| 2105 |
total += scores[i]; |
| 2106 |
if (total >= 112) |
| 2107 |
return 1; |
| 2108 |
if (scores[12] + scores[13] + scores[14] + scores[15] >= 35) |
| 2109 |
return 2; |
| 2110 |
for (total = 0, i = 0 ; i < 8 ; i++) |
| 2111 |
total += scores[i]; |
| 2112 |
if (total >= 68) |
| 2113 |
return 3; |
| 2114 |
for (total = 0, i = 8 ; i < 16 ; i++) |
| 2115 |
total += scores[i]; |
| 2116 |
if (total >= 68) |
| 2117 |
return 4; |
| 2118 |
if (scores[4] + scores[8] + scores[12] >= 26) |
| 2119 |
return 5; |
| 2120 |
if (scores[7] + scores[11] + scores[15] >= 26) |
| 2121 |
return 6; |
| 2122 |
if (scores[0] + scores[4] + scores[7] >= 26) |
| 2123 |
return 7; |
| 2124 |
if (scores[3] + scores[7] + scores[11] >= 26) |
| 2125 |
return 8; |
| 2126 |
if (scores[0] + scores[1] + scores[4] + scores[5] >= 34) |
| 2127 |
return 9; |
| 2128 |
if (scores[1] + scores[2] + scores[5] + scores[6] >= 34) |
| 2129 |
return 10; |
| 2130 |
if (scores[2] + scores[3] + scores[6] + scores[7] >= 34) |
| 2131 |
return 11; |
| 2132 |
if (scores[4] + scores[5] + scores[8] + scores[9] >= 34) |
| 2133 |
return 12; |
| 2134 |
if (scores[5] + scores[6] + scores[9] + scores[10] >= 34) |
| 2135 |
return 13; |
| 2136 |
if (scores[6] + scores[7] + scores[10] + scores[11] >= 34) |
| 2137 |
return 14; |
| 2138 |
if (scores[8] + scores[9] + scores[12] + scores[13] >= 34) |
| 2139 |
return 15; |
| 2140 |
if (scores[9] + scores[10] + scores[13] + scores[14] >= 34) |
| 2141 |
return 16; |
| 2142 |
if (scores[10] + scores[11] + scores[14] + scores[15] >= 34) |
| 2143 |
return 17; |
| 2144 |
|
| 2145 |
double avgPct = 0.0; |
| 2146 |
for (i = 0 ; i < 16 ; i++) |
| 2147 |
avgPct += below40[i]; |
| 2148 |
avgPct /= 16; |
| 2149 |
if (avgPct >= 45.0) |
| 2150 |
return 18; // rule "17-1" |
| 2151 |
|
| 2152 |
return 0; |
| 2153 |
} |
| 2154 |
|
| 2155 |
static int hiti630_check_quality_32(int *scores, double *below40) |
| 2156 |
{ |
| 2157 |
int total = 0; |
| 2158 |
|
| 2159 |
int i; |
| 2160 |
|
| 2161 |
for (i = 0 ; i < 32; i++) |
| 2162 |
total += scores[i]; |
| 2163 |
if (total >= 232) |
| 2164 |
return 19; |
| 2165 |
for (total = 0, i = 16; i < 32; i++) |
| 2166 |
total += scores[i]; |
| 2167 |
if (total >= 112) |
| 2168 |
return 20; |
| 2169 |
if (scores[28] + scores[29] + scores[30] + scores[31] >= 35) |
| 2170 |
return 21; |
| 2171 |
if (scores[20] + scores[24] + scores[28] >= 26) |
| 2172 |
return 22; |
| 2173 |
if (scores[23] + scores[27] + scores[31] >= 26) |
| 2174 |
return 23; |
| 2175 |
if (scores[16] + scores[20] + scores[24] >= 26) |
| 2176 |
return 24; |
| 2177 |
if (scores[19] + scores[23] + scores[27] >= 26) |
| 2178 |
return 25; |
| 2179 |
for (total = 0, i = 12; i < 20; i++) |
| 2180 |
total += scores[i]; |
| 2181 |
if (total >= 68) |
| 2182 |
return 26; |
| 2183 |
for (total = 0, i = 16; i < 24; i++) |
| 2184 |
total += scores[i]; |
| 2185 |
if (total >= 68) |
| 2186 |
return 27; |
| 2187 |
for (total = 0, i = 24; i < 31; i++) |
| 2188 |
total += scores[i]; |
| 2189 |
if (total >= 68) |
| 2190 |
return 28; |
| 2191 |
if (scores[16] + scores[17] + scores[20] + scores[21] >= 34) |
| 2192 |
return 29; |
| 2193 |
if (scores[17] + scores[18] + scores[21] + scores[22] >= 34) |
| 2194 |
return 30; |
| 2195 |
if (scores[18] + scores[19] + scores[22] + scores[23] >= 34) |
| 2196 |
return 31; |
| 2197 |
if (scores[20] + scores[21] + scores[24] + scores[25] >= 34) |
| 2198 |
return 32; |
| 2199 |
if (scores[21] + scores[22] + scores[25] + scores[26] >= 34) |
| 2200 |
return 33; |
| 2201 |
if (scores[22] + scores[23] + scores[26] + scores[27] >= 34) |
| 2202 |
return 34; |
| 2203 |
if (scores[24] + scores[25] + scores[28] + scores[29] >= 34) |
| 2204 |
return 35; |
| 2205 |
if (scores[25] + scores[26] + scores[29] + scores[30] >= 34) |
| 2206 |
return 36; |
| 2207 |
if (scores[26] + scores[27] + scores[30] + scores[31] >= 34) |
| 2208 |
return 37; |
| 2209 |
|
| 2210 |
double avgPct = 0.0; |
| 2211 |
for (i = 16; i < 32 ; i++) |
| 2212 |
avgPct += below40[i]; |
| 2213 |
avgPct /= 16; |
| 2214 |
if (avgPct >= 45.0) |
| 2215 |
return 38; // rule "37-1" |
| 2216 |
|
| 2217 |
for (avgPct = 0.0, i = 0; i < 32 ; i++) |
| 2218 |
avgPct += below40[i]; |
| 2219 |
avgPct /= 16; |
| 2220 |
if (avgPct >= 45.0) |
| 2221 |
return 39; // rule "37-2" |
| 2222 |
|
| 2223 |
return 0; |
| 2224 |
} |
| 2225 |
|
| 2226 |
static int hiti630_analyze_channel(const uint8_t *imgdata, uint16_t cols, uint16_t rows, uint8_t bpp, uint8_t bshift) |
| 2227 |
{ |
| 2228 |
int segments, seg_rows, seg_cols; |
| 2229 |
int scores[32] = { 0 }; |
| 2230 |
int seg_w, seg_h; |
| 2231 |
double below40[32] = { 0.0 }; |
| 2232 |
|
| 2233 |
if (rows <= 1240) { |
| 2234 |
segments = 16; seg_rows = 4; seg_cols = 4; |
| 2235 |
} else { |
| 2236 |
segments = 32; seg_rows = 8; seg_cols = 4; |
| 2237 |
} |
| 2238 |
seg_w = cols /* - offset*2 */ / seg_cols; |
| 2239 |
seg_h = rows / seg_rows; |
| 2240 |
|
| 2241 |
for (int r = 0; r < seg_rows ; r++) { |
| 2242 |
for (int c = 0; c < seg_cols ; c++) { |
| 2243 |
int seg_idx = r * seg_cols + c; |
| 2244 |
uint64_t sum = 0; |
| 2245 |
int count = 0; |
| 2246 |
int below40_count = 0; |
| 2247 |
for (int y = r * seg_h ; y < (r+1)*seg_h ; y++) { |
| 2248 |
const uint8_t *rptr = imgdata + (y * cols * bpp /* + offset*bpp*2 */ ) /* + offset*bpp */; |
| 2249 |
int s = c * seg_w * bpp; |
| 2250 |
for (int x = 0; x < seg_w; x++, s += bpp) { |
| 2251 |
uint8_t val = rptr[s + bshift]; /* ie a specific pixel's channel */ |
| 2252 |
sum += val; |
| 2253 |
count ++; |
| 2254 |
if (val < 40) |
| 2255 |
below40_count++; |
| 2256 |
} |
| 2257 |
} |
| 2258 |
double mean = (double)sum / count; |
| 2259 |
scores[seg_idx] = hiti630_compute_score(mean); |
| 2260 |
below40[seg_idx] = (double) below40_count / count * 100.0; |
| 2261 |
} |
| 2262 |
} |
| 2263 |
|
| 2264 |
if (hiti630_check_quality_16(scores, below40)) |
| 2265 |
return 1; |
| 2266 |
if (segments == 32) |
| 2267 |
return hiti630_check_quality_32(scores, below40); |
| 2268 |
return 0; |
| 2269 |
} |
| 2270 |
|
| 2271 |
static int hitip630_analyze_quality(const uint8_t *imgdata, uint16_t cols, uint16_t rows, uint8_t bpp) |
| 2272 |
{ |
| 2273 |
if (hiti630_analyze_channel(imgdata, cols, rows, bpp, 0)) /* B */ |
| 2274 |
return 1; |
| 2275 |
if (hiti630_analyze_channel(imgdata, cols, rows, bpp, 1)) /* G */ |
| 2276 |
return 2; |
| 2277 |
if (hiti630_analyze_channel(imgdata, cols, rows, bpp, 2)) /* R */ |
| 2278 |
return 3; |
| 2279 |
|
| 2280 |
return 0; |
| 2281 |
} |
| 2282 |
|
| 2283 |
|
| 2284 |
static int hiti_read_parse(void *vctx, const void **vjob, int data_fd, int copies) |
| 2285 |
{ |
| 2286 |
struct hiti_ctx *ctx = vctx; |
| 2287 |
struct hiti_printjob *job = NULL; |
| 2288 |
int ret; |
| 2289 |
|
| 2290 |
if (!ctx) |
| 2291 |
return CUPS_BACKEND_FAILED; |
| 2292 |
|
| 2293 |
job = malloc(sizeof(*job)); |
| 2294 |
if (!job) { |
| 2295 |
ERROR("Memory allocation failure!\n"); |
| 2296 |
return CUPS_BACKEND_RETRY_CURRENT; |
| 2297 |
} |
| 2298 |
memset(job, 0, sizeof(*job)); |
| 2299 |
job->common.jobsize = sizeof(*job); |
| 2300 |
job->common.copies = copies; |
| 2301 |
|
| 2302 |
/* Read in header */ |
| 2303 |
ret = read(data_fd, &job->hdr, sizeof(job->hdr)); |
| 2304 |
if (ret < 0 || ret != sizeof(job->hdr)) { |
| 2305 |
hiti_cleanup_job(job); |
| 2306 |
if (ret == 0) |
| 2307 |
return CUPS_BACKEND_CANCEL; |
| 2308 |
|
| 2309 |
ERROR("Read failed (%d/%d)\n", |
| 2310 |
ret, (int)sizeof(job->hdr)); |
| 2311 |
perror("ERROR: Read failed"); |
| 2312 |
return ret; |
| 2313 |
} |
| 2314 |
|
| 2315 |
/* Byteswap everything */ |
| 2316 |
{ |
| 2317 |
uint32_t *ptr = (uint32_t*) &job->hdr; |
| 2318 |
int i; |
| 2319 |
for (i = 0 ; i < (int)(sizeof(job->hdr) / sizeof(uint32_t)) ; i++) |
| 2320 |
ptr[i] = le32_to_cpu(ptr[i]); |
| 2321 |
} |
| 2322 |
|
| 2323 |
/* Sanity check header */ |
| 2324 |
if (job->hdr.hdr_len != sizeof(job->hdr)) { |
| 2325 |
ERROR("Header length mismatch (%u/%d)!\n", job->hdr.hdr_len, (int)sizeof(job->hdr)); |
| 2326 |
hiti_cleanup_job(job); |
| 2327 |
return CUPS_BACKEND_CANCEL; |
| 2328 |
} |
| 2329 |
if (job->hdr.cookie != HDR_COOKIE) { |
| 2330 |
ERROR("Unrecognized header!\n"); |
| 2331 |
hiti_cleanup_job(job); |
| 2332 |
return CUPS_BACKEND_CANCEL; |
| 2333 |
} |
| 2334 |
|
| 2335 |
/* Use larger of our copy counts */ |
| 2336 |
if (job->common.copies < (int)job->hdr.copies) |
| 2337 |
job->common.copies = job->hdr.copies; |
| 2338 |
|
| 2339 |
/* Sanity check printer type vs job type */ |
| 2340 |
switch(ctx->conn->type) { |
| 2341 |
// XXX add P11x |
| 2342 |
case P_HITI_310: // XXX |
| 2343 |
case P_HITI_320: // XXX |
| 2344 |
case P_HITI_461: |
| 2345 |
if (job->hdr.model != 461) { |
| 2346 |
ERROR("Unrecognized header!\n"); |
| 2347 |
hiti_cleanup_job(job); |
| 2348 |
return CUPS_BACKEND_CANCEL; |
| 2349 |
} |
| 2350 |
break; |
| 2351 |
case P_HITI_51X: |
| 2352 |
if (job->hdr.model != 510) { |
| 2353 |
ERROR("Unrecognized header!\n"); |
| 2354 |
hiti_cleanup_job(job); |
| 2355 |
return CUPS_BACKEND_CANCEL; |
| 2356 |
} |
| 2357 |
break; |
| 2358 |
case P_HITI_520: |
| 2359 |
case P_HITI_525: |
| 2360 |
case P_HITI_530: // XXX |
| 2361 |
case P_HITI_826: |
| 2362 |
case P_SWIFTFOTO_KSF10: |
| 2363 |
if (job->hdr.model != 520) { |
| 2364 |
ERROR("Unrecognized header!\n"); |
| 2365 |
hiti_cleanup_job(job); |
| 2366 |
return CUPS_BACKEND_CANCEL; |
| 2367 |
} |
| 2368 |
break; |
| 2369 |
case P_HITI_630: |
| 2370 |
if (job->hdr.model != 630) { |
| 2371 |
ERROR("Unrecognized header!\n"); |
| 2372 |
hiti_cleanup_job(job); |
| 2373 |
return CUPS_BACKEND_CANCEL; |
| 2374 |
} |
| 2375 |
break; |
| 2376 |
case P_HITI_720: |
| 2377 |
case P_HITI_750: |
| 2378 |
if (job->hdr.model != 720) { |
| 2379 |
ERROR("Unrecognized header!\n"); |
| 2380 |
hiti_cleanup_job(job); |
| 2381 |
return CUPS_BACKEND_CANCEL; |
| 2382 |
} |
| 2383 |
break; |
| 2384 |
default: |
| 2385 |
break; |
| 2386 |
} |
| 2387 |
|
| 2388 |
/* Allocate a buffer */ |
| 2389 |
job->datalen = 0; |
| 2390 |
job->databuf = malloc(job->hdr.payload_len); |
| 2391 |
if (!job->databuf) { |
| 2392 |
ERROR("Memory allocation failure!\n"); |
| 2393 |
hiti_cleanup_job(job); |
| 2394 |
return CUPS_BACKEND_RETRY_CURRENT; |
| 2395 |
} |
| 2396 |
|
| 2397 |
/* Read in data */ |
| 2398 |
uint32_t remain = job->hdr.payload_len; |
| 2399 |
while (remain) { |
| 2400 |
ret = read(data_fd, job->databuf + job->datalen, remain); |
| 2401 |
if (ret < 0) { |
| 2402 |
ERROR("Read failed (%d/%u/%u)\n", |
| 2403 |
ret, remain, job->datalen); |
| 2404 |
perror("ERROR: Read failed"); |
| 2405 |
hiti_cleanup_job(job); |
| 2406 |
return CUPS_BACKEND_CANCEL; |
| 2407 |
} |
| 2408 |
job->datalen += ret; |
| 2409 |
remain -= ret; |
| 2410 |
} |
| 2411 |
|
| 2412 |
/* Sanity check against paper */ |
| 2413 |
switch (ctx->paper.type) { |
| 2414 |
case PAPER_TYPE_X4INCH: |
| 2415 |
// XXX P461/P320/P310 is 1280 |
| 2416 |
// XXX P11x is ??? |
| 2417 |
if (job->hdr.cols != ctx->erdc_rs.cols) { |
| 2418 |
ERROR("Illegal job on 4x6-inch paper!\n"); |
| 2419 |
hiti_cleanup_job(job); |
| 2420 |
return CUPS_BACKEND_CANCEL; |
| 2421 |
} |
| 2422 |
break; |
| 2423 |
case PAPER_TYPE_5INCH: |
| 2424 |
if (!(job->hdr.payload_flag & PAYLOAD_FLAG_YMCPLANAR) && |
| 2425 |
job->hdr.cols == 1548) |
| 2426 |
break; |
| 2427 |
/* Intentional fallthrough */ |
| 2428 |
case PAPER_TYPE_6INCH: |
| 2429 |
if (job->hdr.cols != ctx->erdc_rs.cols) { |
| 2430 |
ERROR("Illegal job on %d-inch paper!\n", ctx->paper.type == PAPER_TYPE_5INCH ? 5 : 6); |
| 2431 |
hiti_cleanup_job(job); |
| 2432 |
return CUPS_BACKEND_CANCEL; |
| 2433 |
} |
| 2434 |
break; |
| 2435 |
default: |
| 2436 |
ERROR("Unknown paper type (%d)!\n", ctx->paper.type); |
| 2437 |
hiti_cleanup_job(job); |
| 2438 |
return CUPS_BACKEND_CANCEL; |
| 2439 |
} |
| 2440 |
|
| 2441 |
/* Sanity check against ribbon type */ |
| 2442 |
switch (ctx->ribbon.type) { |
| 2443 |
case RIBBON_TYPE_4x6: |
| 2444 |
if (job->hdr.code != PRINT_TYPE_6x4 && |
| 2445 |
job->hdr.code != PRINT_TYPE_6x4_2UP && |
| 2446 |
job->hdr.code != PRINT_TYPE_6x4_3UP && |
| 2447 |
job->hdr.code != PRINT_TYPE_6x2) { |
| 2448 |
ERROR("Invalid ribbon type vs job (%02x/%02x)\n", |
| 2449 |
ctx->ribbon.type, job->hdr.code); |
| 2450 |
hiti_cleanup_job(job); |
| 2451 |
return CUPS_BACKEND_CANCEL; |
| 2452 |
} |
| 2453 |
break; |
| 2454 |
case RIBBON_TYPE_5x7: |
| 2455 |
if (job->hdr.code != PRINT_TYPE_5x7 && |
| 2456 |
job->hdr.code != PRINT_TYPE_5x3_5 && |
| •2457 |
job->hdr.code != PRINT_TYPE_5x5 && |
| 2458 |
job->hdr.code != PRINT_TYPE_5x7_2UP) { |
| 2459 |
ERROR("Invalid ribbon type vs job (%02x/%02x)\n", |
| 2460 |
ctx->ribbon.type, job->hdr.code); |
| 2461 |
hiti_cleanup_job(job); |
| 2462 |
return CUPS_BACKEND_CANCEL; |
| 2463 |
} |
| 2464 |
if (job->hdr.code == PRINT_TYPE_5x3_5) |
| 2465 |
job->common.can_combine = 1; |
| 2466 |
break; |
| 2467 |
case RIBBON_TYPE_6x8: |
| 2468 |
if (job->hdr.code != PRINT_TYPE_6x4 && |
| 2469 |
job->hdr.code != PRINT_TYPE_6x4_2UP && |
| 2470 |
job->hdr.code != PRINT_TYPE_6x4_3UP && |
| 2471 |
job->hdr.code != PRINT_TYPE_6x5 && |
| 2472 |
job->hdr.code != PRINT_TYPE_6x6 && |
| 2473 |
job->hdr.code != PRINT_TYPE_6x8 && |
| 2474 |
job->hdr.code != PRINT_TYPE_6x2 && |
| 2475 |
job->hdr.code != PRINT_TYPE_6x9_2UP && |
| 2476 |
job->hdr.code != PRINT_TYPE_6x9_4UP && |
| 2477 |
job->hdr.code != PRINT_TYPE_6x9_6UP && |
| 2478 |
/* HiTi now supplies 6x8" ribbons in 5x7" kits */ |
| 2479 |
job->hdr.code != PRINT_TYPE_5x7 && |
| 2480 |
job->hdr.code != PRINT_TYPE_5x3_5 && |
| 2481 |
job->hdr.code != PRINT_TYPE_5x7_2UP ) { |
| 2482 |
ERROR("Invalid ribbon type vs job (%02x/%02x)\n", |
| 2483 |
ctx->ribbon.type, job->hdr.code); |
| 2484 |
hiti_cleanup_job(job); |
| 2485 |
return CUPS_BACKEND_CANCEL; |
| 2486 |
} |
| 2487 |
if (job->hdr.code == PRINT_TYPE_6x4 || |
| 2488 |
job->hdr.code == PRINT_TYPE_6x4_2UP || |
| 2489 |
job->hdr.code == PRINT_TYPE_6x4_3UP || |
| 2490 |
/* 5x7" prints on 6x8" ribbons... */ |
| 2491 |
job->hdr.code == PRINT_TYPE_5x3_5) |
| 2492 |
job->common.can_combine = 1; |
| 2493 |
break; |
| 2494 |
case RIBBON_TYPE_6x9: |
| 2495 |
if (job->hdr.code != PRINT_TYPE_6x4 && |
| 2496 |
job->hdr.code != PRINT_TYPE_6x4_2UP && |
| 2497 |
job->hdr.code != PRINT_TYPE_6x4_3UP && |
| 2498 |
job->hdr.code != PRINT_TYPE_6x5 && |
| 2499 |
job->hdr.code != PRINT_TYPE_6x6 && |
| 2500 |
job->hdr.code != PRINT_TYPE_6x8 && |
| 2501 |
job->hdr.code != PRINT_TYPE_6x2 && |
| 2502 |
job->hdr.code != PRINT_TYPE_6x9 && |
| 2503 |
job->hdr.code != PRINT_TYPE_6x9_2UP && |
| 2504 |
job->hdr.code != PRINT_TYPE_6x9_4UP && |
| 2505 |
job->hdr.code != PRINT_TYPE_6x9_6UP) { |
| 2506 |
ERROR("Invalid ribbon type vs job (%02x/%02x)\n", |
| 2507 |
ctx->ribbon.type, job->hdr.code); |
| 2508 |
hiti_cleanup_job(job); |
| 2509 |
return CUPS_BACKEND_CANCEL; |
| 2510 |
} |
| 2511 |
if (job->hdr.code == PRINT_TYPE_6x4 || |
| 2512 |
job->hdr.code == PRINT_TYPE_6x4_2UP || |
| 2513 |
job->hdr.code == PRINT_TYPE_6x4_3UP) |
| 2514 |
job->common.can_combine = 1; |
| 2515 |
break; |
| 2516 |
default: |
| 2517 |
ERROR("Unknown ribbon type (%d)!\n", ctx->ribbon.type); |
| 2518 |
hiti_cleanup_job(job); |
| 2519 |
return CUPS_BACKEND_CANCEL; |
| 2520 |
} |
| 2521 |
|
| 2522 |
/* Set color mode / media class */ |
| 2523 |
if (job->hdr.payload_flag & PAYLOAD_FLAG_MEDIATYPE) { |
| 2524 |
job->colormode = job->hdr.payload_flag >> PAYLOAD_FLAG_DATA_SHIFT; |
| 2525 |
} else { |
| 2526 |
job->colormode = HT_COLORMODE_IDPASS_VIVID; |
| 2527 |
} |
| 2528 |
|
| 2529 |
int ribbonvendor = ctx->ribbonvendor; |
| 2530 |
if (job->hdr.payload_flag & PAYLOAD_FLAG_MEDIAVER) { |
| 2531 |
ctx->ribbonvendor &= ~RRVC_VERSION_MASK; |
| 2532 |
ctx->ribbonvendor |= ((job->hdr.payload_flag >> PAYLOAD_FLAG_DATA_SHIFT) & RRVC_VERSION_MASK); |
| 2533 |
} |
| 2534 |
|
| 2535 |
/* Convert input packed BGR data into YMC planar, if needed */ |
| 2536 |
if (!(job->hdr.payload_flag & PAYLOAD_FLAG_YMCPLANAR)) { |
| 2537 |
|
| 2538 |
/* Perform "quality" analysis */ |
| 2539 |
if (ctx->conn->type == P_HITI_630 && !job->hdr.quality) { |
| 2540 |
if (hitip630_analyze_quality(job->databuf, job->hdr.cols, job->hdr.rows, 3)) { |
| 2541 |
INFO("Promoting job to high quality mode\n"); |
| 2542 |
job->hdr.quality = 1; |
| 2543 |
// XXX how does this interact with metallic etc media? |
| 2544 |
} |
| 2545 |
} |
| 2546 |
|
| 2547 |
/* Load up correction data, if requested */ |
| 2548 |
uint8_t *corrdata = NULL; |
| 2549 |
if (!(job->hdr.payload_flag & PAYLOAD_FLAG_NOCORRECT)) { |
| 2550 |
corrdata = hiti_get_correction_data(ctx, job->hdr.quality, job->colormode, ribbonvendor); |
| 2551 |
if (corrdata) { |
| 2552 |
hiti_interp_init(); |
| 2553 |
INFO("Running input data through correction tables\n"); |
| 2554 |
} |
| 2555 |
} |
| 2556 |
|
| 2557 |
/* Printer expects FULL WIDTH data, even for 5" prints */ |
| 2558 |
int pad1, pad2; |
| 2559 |
pad1 = (ctx->erdc_rs.cols - job->hdr.cols) / 2; |
| 2560 |
pad2 = ctx->erdc_rs.cols - job->hdr.cols - pad1; |
| 2561 |
|
| 2562 |
uint8_t *ymcbuf = malloc(job->hdr.rows * ctx->erdc_rs.cols * 3); |
| 2563 |
uint32_t i, j; |
| 2564 |
|
| 2565 |
if (!ymcbuf) { |
| 2566 |
hiti_cleanup_job(job); |
| 2567 |
ERROR("Memory Allocation Failure!\n"); |
| 2568 |
return CUPS_BACKEND_FAILED; |
| 2569 |
} |
| 2570 |
|
| 2571 |
for (i = 0 ; i < job->hdr.rows ; i++) { |
| 2572 |
uint8_t *rowY = ymcbuf + ctx->erdc_rs.cols * i; |
| 2573 |
uint8_t *rowM = ymcbuf + ctx->erdc_rs.cols * (job->hdr.rows + i); |
| 2574 |
uint8_t *rowC = ymcbuf + ctx->erdc_rs.cols * (job->hdr.rows * 2 + i); |
| 2575 |
|
| 2576 |
/* Simple optimization */ |
| 2577 |
uint8_t oldrgb[3] = { 255, 255, 255 }; |
| 2578 |
uint8_t destrgb[3]; |
| 2579 |
|
| 2580 |
if (corrdata) { |
| 2581 |
hiti_interp33_256(destrgb, oldrgb, corrdata); |
| 2582 |
} |
| 2583 |
|
| 2584 |
/* Leading Padding */ |
| 2585 |
memset(rowY, 0, pad1); |
| 2586 |
rowY += pad1; |
| 2587 |
memset(rowM, 0, pad1); |
| 2588 |
rowM += pad1; |
| 2589 |
memset(rowC, 0, pad1); |
| 2590 |
rowC += pad1; |
| 2591 |
|
| 2592 |
for (j = 0 ; j < job->hdr.cols ; j++) { |
| 2593 |
uint8_t rgb[3]; |
| 2594 |
uint32_t base = (job->hdr.cols * i + j) * 3; |
| 2595 |
|
| 2596 |
/* Input data is BGR */ |
| 2597 |
rgb[2] = job->databuf[base]; |
| 2598 |
rgb[1] = job->databuf[base + 1]; |
| 2599 |
rgb[0] = job->databuf[base + 2]; |
| 2600 |
|
| 2601 |
if (corrdata) { |
| 2602 |
if (rgb[0] == oldrgb[0] && |
| 2603 |
rgb[1] == oldrgb[1] && |
| 2604 |
rgb[2] == oldrgb[2]) { |
| 2605 |
rgb[0] = destrgb[0]; |
| 2606 |
rgb[1] = destrgb[1]; |
| 2607 |
rgb[2] = destrgb[2]; |
| 2608 |
} else { |
| 2609 |
oldrgb[0] = rgb[0]; |
| 2610 |
oldrgb[1] = rgb[1]; |
| 2611 |
oldrgb[2] = rgb[2]; |
| 2612 |
hiti_interp33_256(rgb, rgb, corrdata); |
| 2613 |
destrgb[0] = rgb[0]; |
| 2614 |
destrgb[1] = rgb[1]; |
| 2615 |
destrgb[2] = rgb[2]; |
| 2616 |
} |
| 2617 |
} |
| 2618 |
|
| 2619 |
/* Finally convert to YMC */ |
| 2620 |
rowY[j] = 255 - rgb[2]; |
| 2621 |
rowM[j] = 255 - rgb[1]; |
| 2622 |
rowC[j] = 255 - rgb[0]; |
| 2623 |
} |
| 2624 |
|
| 2625 |
/* Trailing Padding */ |
| 2626 |
memset(rowY + job->hdr.cols, 0, pad2); |
| 2627 |
memset(rowM + job->hdr.cols, 0, pad2); |
| 2628 |
memset(rowC + job->hdr.cols, 0, pad2); |
| 2629 |
} |
| 2630 |
|
| 2631 |
/* Nuke the old BGR buffer and replace it with YMC buffer */ |
| 2632 |
free(job->databuf); |
| 2633 |
job->databuf = ymcbuf; |
| 2634 |
job->datalen = ctx->erdc_rs.cols * 3 * job->hdr.cols; |
| 2635 |
job->hdr.cols = ctx->erdc_rs.cols; |
| 2636 |
|
| 2637 |
if (corrdata) |
| 2638 |
free(corrdata); |
| 2639 |
} |
| 2640 |
|
| 2641 |
/* Read in heat table for job */ |
| 2642 |
job->heattable_buf = hiti_get_heat_data(ctx, job->hdr.quality, job->colormode, ribbonvendor, &job->heattable_len); |
| 2643 |
|
| 2644 |
if (job->heattable_buf && |
| 2645 |
ctx->heattable_type == HEATTABLE_TYPE_V2) { |
| 2646 |
ret = hiti_parse_heattable_v2(job); |
| 2647 |
if (ret) { |
| 2648 |
WARNING("Failed to parse v2 heattable, ignoring!\n"); |
| 2649 |
job->heattable_len = 0; |
| 2650 |
} |
| 2651 |
uint32_t ver_maj = -1; |
| 2652 |
uint32_t ver_min = -1; |
| 2653 |
|
| 2654 |
void *dat; |
| 2655 |
size_t len; |
| 2656 |
|
| 2657 |
dat = hiti_find_heattable_v2_entry(job, HEATTABLE_V2_ID_VER_MAJOR, &len); |
| 2658 |
if (dat) { |
| 2659 |
memcpy(&ver_maj, dat, sizeof(ver_maj)); |
| 2660 |
ver_maj = le32_to_cpu(ver_maj); |
| 2661 |
} |
| 2662 |
dat = hiti_find_heattable_v2_entry(job, HEATTABLE_V2_ID_VER_MINOR, &len); |
| 2663 |
if (dat) { |
| 2664 |
memcpy(&ver_min, dat, sizeof(ver_min)); |
| 2665 |
ver_min = le32_to_cpu(ver_min); |
| 2666 |
} |
| 2667 |
INFO("Heattable version %08x.%08x\n", ver_maj, ver_min); |
| 2668 |
|
| 2669 |
/* Assemble SHPTC table for specific job requirements */ |
| 2670 |
void *shptc_buf = malloc(HEATTABLE_V2_MAX_SIZE); |
| 2671 |
if (!shptc_buf) { |
| 2672 |
ERROR("Memory allocation failure\n"); |
| 2673 |
return CUPS_BACKEND_FAILED; |
| 2674 |
} |
| 2675 |
struct hiti_heattable_hdr_v2 *table = shptc_buf; |
| 2676 |
|
| 2677 |
int planes = HT_PLANE_Y | HT_PLANE_M | HT_PLANE_C | HT_CVD; |
| 2678 |
planes |= (job->hdr.overcoat) ? HT_PLANE_OM : HT_PLANE_OG; |
| 2679 |
|
| 2680 |
if (ctx->conn->type == P_HITI_630) |
| 2681 |
planes |= HT_PLANE_630X; |
| 2682 |
|
| 2683 |
ret = hiti_construct_heattable_v2(job, planes, job->colormode, table); |
| 2684 |
if (ret) { |
| 2685 |
job->heattable_len = 0; |
| 2686 |
} else { |
| 2687 |
int datalen = 1 + table->num_headers * sizeof(struct hiti_heattable_entry_v2); |
| 2688 |
|
| 2689 |
for (int i = 0 ; i < table->num_headers; i++) { |
| 2690 |
dat = hiti_find_heattable_v2_entry(job, table->entries[i].type, &len); |
| 2691 |
table->entries[i].len = cpu_to_le32(len); |
| 2692 |
table->entries[i].offset = cpu_to_le32(datalen); |
| 2693 |
memcpy(((uint8_t*)shptc_buf)+datalen, dat, len); |
| 2694 |
|
| 2695 |
if (dyesub_debug) |
| 2696 |
DEBUG("Job entry: %02x len %lu @ %d\n", table->entries[i].type, len, datalen); |
| 2697 |
|
| 2698 |
datalen += len; |
| 2699 |
} |
| 2700 |
free(job->heattable_buf); |
| 2701 |
job->heattable_buf = shptc_buf; |
| 2702 |
job->heattable_len = datalen; |
| 2703 |
|
| 2704 |
free(job->heattable_v2); |
| 2705 |
job->heattable_v2 = NULL; |
| 2706 |
job->num_heattable_entries = 0; |
| 2707 |
} |
| 2708 |
} |
| 2709 |
|
| 2710 |
*vjob = job; |
| 2711 |
|
| 2712 |
return CUPS_BACKEND_OK; |
| 2713 |
} |
| 2714 |
|
| 2715 |
static int calc_offset(int val, int mid, int max, int step) |
| 2716 |
{ |
| 2717 |
if (val == 0 || mid == 0) |
| 2718 |
goto done; |
| 2719 |
|
| 2720 |
if (val > max) |
| 2721 |
val = max; |
| 2722 |
else if (val < 0) |
| 2723 |
val = 0; |
| 2724 |
|
| 2725 |
val -= mid; |
| 2726 |
val *= step; |
| 2727 |
|
| 2728 |
done: |
| 2729 |
return val; |
| 2730 |
} |
| 2731 |
|
| 2732 |
static int hiti_main_loop(void *vctx, const void *vjob, int wait_for_return) |
| 2733 |
{ |
| 2734 |
struct hiti_ctx *ctx = vctx; |
| 2735 |
|
| 2736 |
int ret; |
| 2737 |
uint32_t err = 0; |
| 2738 |
uint8_t sts[3]; |
| 2739 |
struct hiti_job jobid; |
| 2740 |
|
| 2741 |
const struct hiti_printjob *job = vjob; |
| 2742 |
|
| 2743 |
if (!ctx) |
| 2744 |
return CUPS_BACKEND_FAILED; |
| 2745 |
if (!job) |
| 2746 |
return CUPS_BACKEND_FAILED; |
| 2747 |
|
| 2748 |
INFO("Waiting for printer idle\n"); |
| 2749 |
|
| 2750 |
do { |
| 2751 |
ret = hiti_query_status(ctx, sts, &err); |
| 2752 |
if (ret) |
| 2753 |
return ret; |
| 2754 |
|
| 2755 |
/* If we have an error state, bail! */ |
| 2756 |
if (err) { |
| 2757 |
ERROR("Printer reported alert: %08x (%s)\n", |
| 2758 |
err, hiti_errors(err)); |
| 2759 |
return CUPS_BACKEND_STOP; |
| 2760 |
} |
| 2761 |
|
| 2762 |
/* If we're able to accept jobs, proceed */ |
| 2763 |
if (!(sts[0] & (STATUS0_POWERON|STATUS0_BUSY))) |
| 2764 |
break; |
| 2765 |
|
| 2766 |
sleep(1); |
| 2767 |
} while(1); |
| 2768 |
|
| 2769 |
dump_markers(&ctx->marker, 1, 0); |
| 2770 |
|
| 2771 |
uint16_t resplen = 0; |
| 2772 |
uint16_t rows = job->hdr.rows; |
| 2773 |
uint16_t cols = ((4*job->hdr.cols) + 3) / 4; |
| 2774 |
|
| 2775 |
// XXX these two only need to change if rows > 3000 |
| 2776 |
uint16_t startLine = 0; |
| 2777 |
uint16_t numLines = rows; |
| 2778 |
|
| 2779 |
uint32_t sent = 0; |
| 2780 |
|
| 2781 |
/* Set up and send over Sublimation Format */ |
| 2782 |
struct hiti_efd_sf sf; |
| 2783 |
sf.mediaType = job->hdr.code; |
| 2784 |
sf.cols_res = cpu_to_be16(job->hdr.col_dpi); |
| 2785 |
sf.rows_res = cpu_to_be16(job->hdr.row_dpi); |
| 2786 |
sf.cols = cpu_to_be16(job->hdr.cols); |
| 2787 |
sf.rows = cpu_to_be16(rows); |
| 2788 |
sf.rows_offset = calc_offset(5, ctx->calibration.rows, 8, 4); |
| 2789 |
sf.cols_offset = calc_offset(ctx->calibration.cols, 6, 11, 4); |
| 2790 |
sf.colorSeq = SF_COLORSEQ_YMCO | (job->hdr.overcoat ? SF_COLORSEQ_MATTE : 0); |
| 2791 |
sf.copies = job->common.copies; |
| 2792 |
sf.printMode = ctx->sheet ? 0 : SF_PRINTMODE_BASE + (job->hdr.quality ? SF_PRINTMODE_FINE : 0); |
| 2793 |
memset(sf.zero, 0, sizeof(sf.zero)); |
| 2794 |
ret = hiti_docmd(ctx, CMD_EFD_SF, (uint8_t*) &sf, |
| 2795 |
ctx->sheet ? sizeof(sf) : sizeof(sf)-4 , |
| 2796 |
&resplen); |
| 2797 |
if (ret) |
| 2798 |
return CUPS_BACKEND_FAILED; |
| 2799 |
|
| 2800 |
// XXX on P461, P310/P322, P630: (and maybe 320?) |
| 2801 |
// request warning |
| 2802 |
// QJC |
| 2803 |
// then SF again |
| 2804 |
|
| 2805 |
if (ctx->conn->type == P_HITI_520 || ctx->conn->type == P_HITI_525 || ctx->conn->type == P_HITI_826 || ctx->conn->type == P_SWIFTFOTO_KSF10 || ctx->conn->type == P_HITI_630) { |
| 2806 |
uint8_t val = 0; /* table index */ |
| 2807 |
resplen = sizeof(&ctx->rhtv); |
| 2808 |
ret = hiti_docmd_resp(ctx, CMD_ERDC_RHTV, &val, |
| 2809 |
sizeof(val), (uint8_t*) &ctx->rhtv, &resplen); |
| 2810 |
if (ret) |
| 2811 |
return CUPS_BACKEND_FAILED; |
| 2812 |
ctx->rhtv.major = be16_to_cpu(ctx->rhtv.major); |
| 2813 |
ctx->rhtv.minor = be16_to_cpu(ctx->rhtv.minor); |
| 2814 |
// Unclear if we meaningfully _care_ about this in any way |
| 2815 |
} |
| 2816 |
|
| 2817 |
/* Initialize jobid structure */ |
| 2818 |
jobid.lun = 0; |
| 2819 |
jobid.jobid = cpu_to_be16(ctx->jobid); |
| 2820 |
|
| 2821 |
resplen = sizeof(jobid); |
| 2822 |
ret = hiti_docmd_resp(ctx, CMD_JC_SJ, (uint8_t*) &jobid, sizeof(jobid), |
| 2823 |
(uint8_t*) &jobid, &resplen); |
| 2824 |
if (ret) |
| 2825 |
return CUPS_BACKEND_FAILED; |
| 2826 |
|
| 2827 |
INFO("Printer returned Job ID %04x\n", be16_to_cpu(jobid.jobid)); |
| 2828 |
|
| 2829 |
if (job->heattable_len && !ctx->nodata) { |
| 2830 |
switch(ctx->heattable_type) { |
| 2831 |
case HEATTABLE_TYPE_V0: |
| 2832 |
if (job->heattable_len == HEATTABLE_S_SIZE || job->heattable_len == HEATTABLE_S2_SIZE) { |
| 2833 |
/* Send ESC_SHPTC with entire file contents */ |
| 2834 |
ret = hiti_shptc(ctx, job->heattable_buf, job->heattable_len); |
| 2835 |
} else { |
| 2836 |
ERROR("Unexpected heattable size (%d vs %d/%d)\n", job->heattable_len, HEATTABLE_S_SIZE, HEATTABLE_S2_SIZE); |
| 2837 |
ret = CUPS_BACKEND_FAILED; |
| 2838 |
} |
| 2839 |
break; |
| 2840 |
case HEATTABLE_TYPE_V1: |
| 2841 |
ret = hiti_send_heat_data_v1(ctx, job->heattable_buf, job->heattable_len, job->hdr.overcoat); |
| 2842 |
break; |
| 2843 |
case HEATTABLE_TYPE_V2: |
| 2844 |
/* Just send the computed blob over */ |
| 2845 |
ret = hiti_shptc(ctx, job->heattable_buf, job->heattable_len); |
| 2846 |
break; |
| 2847 |
} |
| 2848 |
#if 0 |
| 2849 |
if (ctx->conn->type == P_HITI_51X) { |
| 2850 |
uint8_t esd_unka[4] = { 0x00, 0x87, 0x00, 0x02 }; // XXX figure me out eventually? |
| 2851 |
ret = hiti_docmd(ctx, CMD_ESD_UNKA, esd_unka, sizeof(esd_unka), &resplen); |
| 2852 |
if (ret) |
| 2853 |
return CUPS_BACKEND_FAILED; |
| 2854 |
} |
| 2855 |
#endif |
| 2856 |
} |
| 2857 |
|
| 2858 |
/* If we don't have a heat file or the heat transfer failed, revert to default tables */ |
| 2859 |
if (!job->heattable_len || ret) { |
| 2860 |
if (ctx->conn->type != P_HITI_525 && ctx->conn->type != P_HITI_826 && ctx->conn->type != P_SWIFTFOTO_KSF10 && ctx->conn->type != P_HITI_630) { |
| 2861 |
uint8_t chs[2] = { 0, 1 }; /* Reverts to default tables */ |
| 2862 |
resplen = 0; |
| 2863 |
ret = hiti_docmd(ctx, CMD_EFD_CHS, chs, sizeof(chs), &resplen); |
| 2864 |
if (ret) |
| 2865 |
return CUPS_BACKEND_FAILED; |
| 2866 |
} |
| 2867 |
} |
| 2868 |
|
| 2869 |
/* Start Page */ |
| 2870 |
ret = hiti_docmd(ctx, CMD_EPC_SP, NULL, 0, &resplen); |
| 2871 |
if (ret) |
| 2872 |
return CUPS_BACKEND_FAILED; |
| 2873 |
|
| 2874 |
resend_y: |
| 2875 |
INFO("Sending yellow plane\n"); |
| 2876 |
ret = hiti_docmd(ctx, CMD_EPC_SYP, NULL, 0, &resplen); |
| 2877 |
if (ret) |
| 2878 |
return CUPS_BACKEND_FAILED; |
| 2879 |
ret = hiti_sepd(ctx, rows * cols, startLine, numLines); |
| 2880 |
if (ret) |
| 2881 |
return CUPS_BACKEND_FAILED; |
| 2882 |
ret = send_data(ctx->conn, job->databuf + sent, rows * cols); |
| 2883 |
if (ret) |
| 2884 |
return CUPS_BACKEND_FAILED; |
| 2885 |
__usleep(200*1000); |
| 2886 |
ret = hiti_query_status(ctx, sts, &err); |
| 2887 |
if (ret) |
| 2888 |
return ret; |
| 2889 |
if (err) { |
| 2890 |
ERROR("Printer reported alert: %08x (%s)\n", |
| 2891 |
err, hiti_errors(err)); |
| 2892 |
return CUPS_BACKEND_FAILED; |
| 2893 |
} |
| 2894 |
if (sts[0] & STATUS0_RESEND_DATA) { |
| 2895 |
WARNING("Printer requested resend\n"); |
| 2896 |
goto resend_y; |
| 2897 |
} |
| 2898 |
sent += rows * cols; |
| 2899 |
|
| 2900 |
resend_m: |
| 2901 |
INFO("Sending magenta plane\n"); |
| 2902 |
ret = hiti_docmd(ctx, CMD_EPC_SMP, NULL, 0, &resplen); |
| 2903 |
if (ret) |
| 2904 |
return CUPS_BACKEND_FAILED; |
| 2905 |
ret = hiti_sepd(ctx, rows * cols, startLine, numLines); |
| 2906 |
if (ret) |
| 2907 |
return CUPS_BACKEND_FAILED; |
| 2908 |
ret = send_data(ctx->conn, job->databuf + sent, rows * cols); |
| 2909 |
if (ret) |
| 2910 |
return CUPS_BACKEND_FAILED; |
| 2911 |
__usleep(200*1000); |
| 2912 |
ret = hiti_query_status(ctx, sts, &err); |
| 2913 |
if (ret) |
| 2914 |
return ret; |
| 2915 |
if (err) { |
| 2916 |
ERROR("Printer reported alert: %08x (%s)\n", |
| 2917 |
err, hiti_errors(err)); |
| 2918 |
return CUPS_BACKEND_FAILED; |
| 2919 |
} |
| 2920 |
if (sts[0] & STATUS0_RESEND_DATA) { |
| 2921 |
WARNING("Printer requested resend\n"); |
| 2922 |
goto resend_m; |
| 2923 |
} |
| 2924 |
sent += rows * cols; |
| 2925 |
|
| 2926 |
resend_c: |
| 2927 |
INFO("Sending cyan plane\n"); |
| 2928 |
ret = hiti_docmd(ctx, CMD_EPC_SCP, NULL, 0, &resplen); |
| 2929 |
if (ret) |
| 2930 |
return CUPS_BACKEND_FAILED; |
| 2931 |
ret = hiti_sepd(ctx, rows * cols, startLine, numLines); |
| 2932 |
if (ret) |
| 2933 |
return CUPS_BACKEND_FAILED; |
| 2934 |
ret = send_data(ctx->conn, job->databuf + sent, rows * cols); |
| 2935 |
if (ret) |
| 2936 |
return CUPS_BACKEND_FAILED; |
| 2937 |
__usleep(200*1000); |
| 2938 |
|
| 2939 |
ret = hiti_query_status(ctx, sts, &err); |
| 2940 |
if (ret) |
| 2941 |
return ret; |
| 2942 |
if (err) { |
| 2943 |
ERROR("Printer reported alert: %08x (%s)\n", |
| 2944 |
err, hiti_errors(err)); |
| 2945 |
return CUPS_BACKEND_FAILED; |
| 2946 |
} |
| 2947 |
if (sts[0] & STATUS0_RESEND_DATA) { |
| 2948 |
WARNING("Printer requested resend\n"); |
| 2949 |
goto resend_c; |
| 2950 |
} |
| 2951 |
sent += rows * cols; |
| 2952 |
|
| 2953 |
INFO("Sending Print start\n"); |
| 2954 |
ret = hiti_docmd(ctx, CMD_EPC_EP, NULL, 0, &resplen); |
| 2955 |
if (ret) |
| 2956 |
return CUPS_BACKEND_FAILED; |
| 2957 |
|
| 2958 |
resplen = 3; |
| 2959 |
ret = hiti_docmd_resp(ctx, CMD_JC_EJ, (uint8_t*) &jobid, sizeof(jobid), (uint8_t*) &jobid, &resplen); |
| 2960 |
if (ret) |
| 2961 |
return CUPS_BACKEND_FAILED; |
| 2962 |
|
| 2963 |
INFO("Waiting for printer acknowledgement\n"); |
| 2964 |
do { |
| 2965 |
struct hiti_job_qqa qqa; |
| 2966 |
sleep(1); |
| 2967 |
|
| 2968 |
ret = hiti_query_status(ctx, sts, &err); |
| 2969 |
if (ret) |
| 2970 |
return ret; |
| 2971 |
|
| 2972 |
if (err) { |
| 2973 |
ERROR("Printer reported alert: %08x (%s)\n", |
| 2974 |
err, hiti_errors(err)); |
| 2975 |
return CUPS_BACKEND_FAILED; |
| 2976 |
} |
| 2977 |
|
| 2978 |
if (!wait_for_return) { |
| 2979 |
INFO("Fast return mode enabled.\n"); |
| 2980 |
break; |
| 2981 |
} |
| 2982 |
|
| 2983 |
/* See if our job is done.. */ |
| 2984 |
ret = hiti_query_job_qa(ctx, &jobid, &qqa); |
| 2985 |
if (ret) |
| 2986 |
return ret; |
| 2987 |
|
| 2988 |
/* If our job is complete.. */ |
| 2989 |
if (qqa.count == 0 || qqa.row[0].job.jobid == 0) |
| 2990 |
break; |
| 2991 |
|
| 2992 |
for (int i = 0 ; i < qqa.count ; i++) { |
| 2993 |
if (qqa.row[i].job.jobid == jobid.jobid) { |
| 2994 |
if (qqa.row[i].status > QQA_STATUS_SUSPENDED) { |
| 2995 |
ERROR("Printer reported abnormal job status %02x\n", qqa.row[i].status); |
| 2996 |
return CUPS_BACKEND_FAILED; |
| 2997 |
} |
| 2998 |
} |
| 2999 |
} |
| 3000 |
} while(1); |
| 3001 |
|
| 3002 |
INFO("Print complete\n"); |
| 3003 |
|
| 3004 |
return CUPS_BACKEND_OK; |
| 3005 |
} |
| 3006 |
|
| 3007 |
static int hiti_dumpmatrix(struct hiti_ctx *ctx) |
| 3008 |
{ |
| 3009 |
int ret; |
| 3010 |
|
| 3011 |
if (ctx->conn->type == P_HITI_51X) { |
| 3012 |
ret = hiti_query_matrix_51x(ctx); |
| 3013 |
} else { |
| 3014 |
ret = hiti_query_matrix(ctx); |
| 3015 |
} |
| 3016 |
if (ret) |
| 3017 |
return CUPS_BACKEND_FAILED; |
| 3018 |
|
| 3019 |
int i; |
| 3020 |
DEBUG("MAT "); |
| 3021 |
for (i = 0 ; i < 512 ; i++) { |
| 3022 |
if (i != 0 && (i % 16 == 0)) { |
| 3023 |
DEBUG2("\n"); |
| 3024 |
DEBUG(" "); |
| 3025 |
} |
| 3026 |
DEBUG2("%02x ", ctx->matrix[i]); |
| 3027 |
} |
| 3028 |
DEBUG2("\n"); |
| 3029 |
|
| 3030 |
return CUPS_BACKEND_OK; |
| 3031 |
} |
| 3032 |
|
| 3033 |
static int hiti_cmdline_arg(void *vctx, int argc, char **argv) |
| 3034 |
{ |
| 3035 |
struct hiti_ctx *ctx = vctx; |
| 3036 |
int i, j = 0; |
| 3037 |
|
| 3038 |
if (!ctx) |
| 3039 |
return -1; |
| 3040 |
|
| 3041 |
while ((i = getopt(argc, argv, GETOPT_LIST_GLOBAL "irRsZ")) >= 0) { |
| 3042 |
switch(i) { |
| 3043 |
GETOPT_PROCESS_GLOBAL |
| 3044 |
case 'i': |
| 3045 |
hiti_get_info(ctx); |
| 3046 |
break; |
| 3047 |
case 'r': |
| 3048 |
hiti_doreset(ctx, RESET_SOFT); |
| 3049 |
break; |
| 3050 |
case 'R': |
| 3051 |
hiti_doreset(ctx, RESET_PRINTER); |
| 3052 |
break; |
| 3053 |
case 's': |
| 3054 |
hiti_get_status(ctx); |
| 3055 |
break; |
| 3056 |
case 'Z': |
| 3057 |
hiti_dumpmatrix(ctx); |
| 3058 |
break; |
| 3059 |
} |
| 3060 |
|
| 3061 |
if (j) return j; |
| 3062 |
} |
| 3063 |
|
| 3064 |
return CUPS_BACKEND_OK; |
| 3065 |
} |
| 3066 |
|
| 3067 |
static void hiti_cmdline(void) |
| 3068 |
{ |
| 3069 |
DEBUG("\t\t[ -i ] # Query printer information\n"); |
| 3070 |
DEBUG("\t\t[ -r ] # Soft Reset printer\n"); |
| 3071 |
DEBUG("\t\t[ -R ] # Reset printer\n"); |
| 3072 |
DEBUG("\t\t[ -s ] # Query printer status\n"); |
| 3073 |
// DEBUG("\t\t[ -Z ] # Dump matrix table\n"); |
| 3074 |
} |
| 3075 |
|
| 3076 |
static int hiti_query_version(struct hiti_ctx *ctx) |
| 3077 |
{ |
| 3078 |
int ret; |
| 3079 |
uint16_t len = 256; /* P525 has 93 byte payload, P461 has 97, others are 79? */ |
| 3080 |
uint8_t buf[256]; |
| 3081 |
|
| 3082 |
ret = hiti_docmd_resp(ctx, CMD_RDC_RS, NULL, 0, buf, &len); |
| 3083 |
if (ret) |
| 3084 |
return ret; |
| 3085 |
|
| 3086 |
/* Copy strings */ |
| 3087 |
strncpy(ctx->id, (char*) &buf[34], buf[33]); |
| 3088 |
strncpy(ctx->version, (char*) &buf[34 + buf[33] + 1], sizeof(ctx->version)); |
| 3089 |
ctx->version[9] = 0; |
| 3090 |
|
| 3091 |
/* Early P630 firmware had a trailing newline */ |
| 3092 |
if (ctx->version[8] == '\n') |
| 3093 |
ctx->version[8] = 0; |
| 3094 |
|
| 3095 |
return CUPS_BACKEND_OK; |
| 3096 |
} |
| 3097 |
|
| 3098 |
static int hiti_query_status(struct hiti_ctx *ctx, uint8_t *sts, uint32_t *err) |
| 3099 |
{ |
| 3100 |
int ret; |
| 3101 |
uint16_t len = 3; |
| 3102 |
uint16_t cmd; |
| 3103 |
|
| 3104 |
*err = 0; |
| 3105 |
|
| 3106 |
ret = hiti_docmd_resp(ctx, CMD_RDS_RSS, NULL, 0, sts, &len); |
| 3107 |
if (ret) |
| 3108 |
return ret; |
| 3109 |
|
| 3110 |
if (sts[2] & STATUS2_WARNING) |
| 3111 |
cmd = CMD_RDS_RW; |
| 3112 |
else if (sts[2] & STATUS2_DEVSERVICE) |
| 3113 |
cmd = CMD_RDS_DSRA; |
| 3114 |
else if (sts[2] & STATUS2_OPERATOR) |
| 3115 |
cmd = CMD_RDS_ROIRA; |
| 3116 |
else if (sts[1] & STATUS1_PAPERJAM) |
| 3117 |
cmd = CMD_RDS_RJA; |
| 3118 |
else if (sts[1] & STATUS1_INPUT) |
| 3119 |
cmd = CMD_RDS_RIA; |
| 3120 |
else if (sts[1] & STATUS1_SUPPLIES) |
| 3121 |
cmd = CMD_RDS_SA; |
| 3122 |
else |
| 3123 |
cmd = 0; |
| 3124 |
|
| 3125 |
/* Query extended status, if needed */ |
| 3126 |
if (cmd) { |
| 3127 |
uint8_t respbuf[17]; /* Enough for four errors */ |
| 3128 |
len = sizeof(respbuf); |
| 3129 |
|
| 3130 |
ret = hiti_docmd_resp(ctx, cmd, NULL, 0, respbuf, &len); |
| 3131 |
if (ret) |
| 3132 |
return ret; |
| 3133 |
|
| 3134 |
if (!respbuf[0]) |
| 3135 |
return CUPS_BACKEND_OK; |
| 3136 |
|
| 3137 |
if (respbuf[0] > 1) { |
| 3138 |
WARNING("Multiple Alerts detected, only returning the first!\n"); |
| 3139 |
} else if (len > 8) { |
| 3140 |
// XXX means we have ASCIIHEX in positions [5:8], convert to number.. |
| 3141 |
// eg "30 31 30 30" == Code 0100 |
| 3142 |
} |
| 3143 |
|
| 3144 |
memcpy(err, &respbuf[1], sizeof(*err)); |
| 3145 |
*err = be32_to_cpu(*err); |
| 3146 |
*err >>= 8; |
| 3147 |
} |
| 3148 |
|
| 3149 |
return CUPS_BACKEND_OK; |
| 3150 |
} |
| 3151 |
|
| 3152 |
static int hiti_query_summary(struct hiti_ctx *ctx, struct hiti_erdc_rs *rds) |
| 3153 |
{ |
| 3154 |
int ret; |
| 3155 |
uint16_t len = sizeof(*rds); |
| 3156 |
|
| 3157 |
ret = hiti_docmd_resp(ctx, CMD_ERDC_RS, NULL, 0, (uint8_t*)rds, &len); |
| 3158 |
if (ret) |
| 3159 |
return ret; |
| 3160 |
|
| 3161 |
rds->stride = be16_to_cpu(rds->stride); |
| 3162 |
rds->dpi_cols = be16_to_cpu(rds->dpi_cols); |
| 3163 |
rds->dpi_rows = be16_to_cpu(rds->dpi_rows); |
| 3164 |
rds->cols = be16_to_cpu(rds->cols); |
| 3165 |
rds->rows = be16_to_cpu(rds->rows); |
| 3166 |
rds->vertUnitInstalled = be16_to_cpu(rds->vertUnitInstalled); |
| 3167 |
rds->dpi_rows2 = be16_to_cpu(rds->dpi_rows2); |
| 3168 |
rds->dpi_rows3 = be16_to_cpu(rds->dpi_rows3); |
| 3169 |
return CUPS_BACKEND_OK; |
| 3170 |
} |
| 3171 |
|
| 3172 |
static int hiti_query_rpidm(struct hiti_ctx *ctx) |
| 3173 |
{ |
| 3174 |
int ret; |
| 3175 |
uint16_t len = sizeof(ctx->rpidm); |
| 3176 |
|
| 3177 |
ret = hiti_docmd_resp(ctx, CMD_ERDC_RPIDM, NULL, 0, (uint8_t*)&ctx->rpidm, &len); |
| 3178 |
if (ret) |
| 3179 |
return ret; |
| 3180 |
|
| 3181 |
ctx->rpidm.usb_pid = be16_to_cpu(ctx->rpidm.usb_pid); |
| 3182 |
|
| 3183 |
return CUPS_BACKEND_OK; |
| 3184 |
} |
| 3185 |
|
| 3186 |
static int hiti_query_hilightadj(struct hiti_ctx *ctx) |
| 3187 |
{ |
| 3188 |
int ret; |
| 3189 |
uint16_t len = sizeof(ctx->hilight_adj); |
| 3190 |
|
| 3191 |
ret = hiti_docmd_resp(ctx, CMD_ERDC_RHA, NULL, 0, ctx->hilight_adj, &len); |
| 3192 |
if (ret) |
| 3193 |
return ret; |
| 3194 |
|
| 3195 |
return CUPS_BACKEND_OK; |
| 3196 |
} |
| 3197 |
|
| 3198 |
static int hiti_query_unk8010(struct hiti_ctx *ctx) |
| 3199 |
{ |
| 3200 |
int ret; |
| 3201 |
uint16_t len = sizeof(ctx->unk_8010); |
| 3202 |
|
| 3203 |
ret = hiti_docmd_resp(ctx, CMD_ERDC_UNK0, NULL, 0, ctx->unk_8010, &len); |
| 3204 |
if (ret) |
| 3205 |
return ret; |
| 3206 |
|
| 3207 |
return CUPS_BACKEND_OK; |
| 3208 |
} |
| 3209 |
|
| 3210 |
static int hiti_query_unk800c(struct hiti_ctx *ctx) |
| 3211 |
{ |
| 3212 |
int ret; |
| 3213 |
uint16_t len = sizeof(ctx->unk_800c); |
| 3214 |
|
| 3215 |
ret = hiti_docmd_resp(ctx, CMD_ERDC_UNKC, NULL, 0, ctx->unk_800c, &len); |
| 3216 |
if (ret) |
| 3217 |
return ret; |
| 3218 |
|
| 3219 |
return CUPS_BACKEND_OK; |
| 3220 |
} |
| 3221 |
|
| 3222 |
static int hiti_query_calibration(struct hiti_ctx *ctx) |
| 3223 |
{ |
| 3224 |
int ret; |
| 3225 |
uint16_t len = sizeof(ctx->calibration); |
| 3226 |
|
| 3227 |
ret = hiti_docmd_resp(ctx, CMD_ERDC_RCC, NULL, 0, (uint8_t*)&ctx->calibration, &len); |
| 3228 |
if (ret) |
| 3229 |
return ret; |
| 3230 |
|
| 3231 |
return CUPS_BACKEND_OK; |
| 3232 |
} |
| 3233 |
|
| 3234 |
static int hiti_query_led_calibration(struct hiti_ctx *ctx) |
| 3235 |
{ |
| 3236 |
int ret; |
| 3237 |
uint16_t len; |
| 3238 |
|
| 3239 |
if (ctx->sheet) { |
| 3240 |
len = sizeof(ctx->led_calibration) - 4; |
| 3241 |
ret = hiti_docmd_resp(ctx, CMD_ERDC_RLC, NULL, 0, (uint8_t*)(&ctx->led_calibration)+4, &len); |
| 3242 |
} else { |
| 3243 |
len = sizeof(ctx->led_calibration); |
| 3244 |
ret = hiti_docmd_resp(ctx, CMD_ERDC_RLC, NULL, 0, (uint8_t*)&ctx->led_calibration, &len); |
| 3245 |
} |
| 3246 |
if (ret) |
| 3247 |
return ret; |
| 3248 |
|
| 3249 |
return CUPS_BACKEND_OK; |
| 3250 |
} |
| 3251 |
|
| 3252 |
static int hiti_query_ribbonvendor(struct hiti_ctx *ctx) |
| 3253 |
{ |
| 3254 |
int ret; |
| 3255 |
uint16_t len = 2; |
| 3256 |
|
| 3257 |
ret = hiti_docmd_resp(ctx, CMD_ERDC_RRVC, NULL, 0, (uint8_t*) &ctx->ribbonvendor, &len); |
| 3258 |
if (ret) |
| 3259 |
return ret; |
| 3260 |
|
| 3261 |
ctx->ribbonvendor = be16_to_cpu(ctx->ribbonvendor); |
| 3262 |
|
| 3263 |
return CUPS_BACKEND_OK; |
| 3264 |
} |
| 3265 |
|
| 3266 |
static int hiti_query_tphv(struct hiti_ctx *ctx) |
| 3267 |
{ |
| 3268 |
int ret; |
| 3269 |
uint16_t len = 2; |
| 3270 |
|
| 3271 |
ret = hiti_docmd_resp(ctx, CMD_ERDC_RTLV, NULL, 0, (uint8_t*) &ctx->rtlv, &len); |
| 3272 |
if (ret) |
| 3273 |
return ret; |
| 3274 |
|
| 3275 |
return CUPS_BACKEND_OK; |
| 3276 |
} |
| 3277 |
|
| 3278 |
static int hiti_query_supplies(struct hiti_ctx *ctx) |
| 3279 |
{ |
| 3280 |
int ret; |
| 3281 |
uint16_t len = sizeof(ctx->ribbon); |
| 3282 |
uint8_t arg = 0; |
| 3283 |
|
| 3284 |
ret = hiti_docmd_resp(ctx, CMD_RDS_RSUS, &arg, sizeof(arg), (uint8_t*)&ctx->ribbon, &len); |
| 3285 |
if (ret) |
| 3286 |
return ret; |
| 3287 |
|
| 3288 |
len = sizeof(ctx->paper); |
| 3289 |
ret = hiti_docmd_resp(ctx, CMD_RDS_RIS, NULL, 0, (uint8_t*)&ctx->paper, &len); |
| 3290 |
if (ret) |
| 3291 |
return ret; |
| 3292 |
|
| 3293 |
return CUPS_BACKEND_OK; |
| 3294 |
} |
| 3295 |
|
| 3296 |
static int hiti_query_statistics(struct hiti_ctx *ctx) |
| 3297 |
{ |
| 3298 |
int ret; |
| 3299 |
uint16_t len = 30; |
| 3300 |
uint8_t buf[256]; |
| 3301 |
int i; |
| 3302 |
|
| 3303 |
ret = hiti_docmd_resp(ctx, CMD_RDS_RPS, NULL, 0, buf, &len); |
| 3304 |
if (ret) |
| 3305 |
return ret; |
| 3306 |
|
| 3307 |
for (i = 0 ; i < buf[0] && i*5+1 < len ; i+= 5) { |
| 3308 |
/* uint8_t type |
| 3309 |
uint32_t val |
| 3310 |
*/ |
| 3311 |
if (buf[1 + i*5] == 0x03) { // Remaining prints |
| 3312 |
memcpy(&ctx->media_remain, &buf[1 + i*5 + 1], sizeof(ctx->media_remain)); |
| 3313 |
ctx->media_remain = be32_to_cpu(ctx->media_remain); |
| 3314 |
} |
| 3315 |
} |
| 3316 |
|
| 3317 |
return CUPS_BACKEND_OK; |
| 3318 |
} |
| 3319 |
|
| 3320 |
static int hiti_doreset(struct hiti_ctx *ctx, uint8_t type) |
| 3321 |
{ |
| 3322 |
int ret; |
| 3323 |
uint8_t buf[6]; |
| 3324 |
uint16_t len = 6; |
| 3325 |
|
| 3326 |
ret = hiti_docmd_resp(ctx, CMD_PCC_RP, &type, sizeof(type), buf, &len); |
| 3327 |
if (ret) |
| 3328 |
return ret; |
| 3329 |
|
| 3330 |
sleep(5); |
| 3331 |
|
| 3332 |
return CUPS_BACKEND_OK; |
| 3333 |
} |
| 3334 |
|
| 3335 |
static int hiti_query_matrix(struct hiti_ctx *ctx) |
| 3336 |
{ |
| 3337 |
int ret; |
| 3338 |
int i; |
| 3339 |
uint16_t len = 1; |
| 3340 |
|
| 3341 |
for (i = 0 ; i < 512 ; i++) { |
| 3342 |
uint16_t offset = cpu_to_be16(i); |
| 3343 |
|
| 3344 |
ret = hiti_docmd_resp(ctx, CMD_EFM_RD, (uint8_t*)&offset, sizeof(offset), &ctx->matrix[i], &len); |
| 3345 |
if (ret) |
| 3346 |
return ret; |
| 3347 |
} |
| 3348 |
|
| 3349 |
return CUPS_BACKEND_OK; |
| 3350 |
} |
| 3351 |
|
| 3352 |
static int hiti_query_matrix_51x(struct hiti_ctx *ctx) |
| 3353 |
{ |
| 3354 |
int ret; |
| 3355 |
int i; |
| 3356 |
uint16_t len = 1; |
| 3357 |
|
| 3358 |
uint8_t lun = 0; |
| 3359 |
ret = hiti_docmd(ctx, CMD_PCC_STP, (uint8_t*)&lun, sizeof(lun), &len); |
| 3360 |
if (ret) |
| 3361 |
return ret; |
| 3362 |
|
| 3363 |
for (i = 0 ; i < 512 ; i++) { |
| 3364 |
uint8_t offset = i % 256; |
| 3365 |
if (offset == 0) { |
| 3366 |
lun = i / 256; |
| 3367 |
ret = hiti_docmd(ctx, CMD_PCC_STP, (uint8_t*)&lun, sizeof(lun), &len); |
| 3368 |
if (ret) |
| 3369 |
return ret; |
| 3370 |
} |
| 3371 |
ret = hiti_docmd_resp(ctx, CMD_EFM_RNV, (uint8_t*)&offset, sizeof(offset), &ctx->matrix[i], &len); |
| 3372 |
if (ret) |
| 3373 |
return ret; |
| 3374 |
} |
| 3375 |
|
| 3376 |
lun = 0; |
| 3377 |
ret = hiti_docmd(ctx, CMD_PCC_STP, (uint8_t*)&lun, sizeof(lun), &len); |
| 3378 |
if (ret) |
| 3379 |
return ret; |
| 3380 |
|
| 3381 |
|
| 3382 |
return CUPS_BACKEND_OK; |
| 3383 |
} |
| 3384 |
|
| 3385 |
static int hiti_query_counter(struct hiti_ctx *ctx, uint8_t arg, uint32_t *resp, int num) |
| 3386 |
{ |
| 3387 |
int ret; |
| 3388 |
uint16_t len = sizeof(*resp) * num; |
| 3389 |
|
| 3390 |
ret = hiti_docmd_resp(ctx, CMD_ERDC_RPC, &arg, sizeof(arg), |
| 3391 |
(uint8_t*) resp, &len); |
| 3392 |
if (ret) |
| 3393 |
return ret; |
| 3394 |
|
| 3395 |
*resp = be32_to_cpu(*resp); |
| 3396 |
|
| 3397 |
return CUPS_BACKEND_OK; |
| 3398 |
} |
| 3399 |
|
| 3400 |
static int hiti_query_serno(struct dyesub_connection *conn, char *buf, int buf_len) |
| 3401 |
{ |
| 3402 |
int ret; |
| 3403 |
uint16_t rsplen = 18; |
| 3404 |
uint8_t rspbuf[18]; |
| 3405 |
|
| 3406 |
struct hiti_ctx ctx = { |
| 3407 |
.conn = conn |
| 3408 |
}; |
| 3409 |
|
| 3410 |
uint8_t arg = sizeof(rspbuf); |
| 3411 |
ret = hiti_docmd_resp(&ctx, CMD_ERDC_RSN, &arg, sizeof(arg), rspbuf, &rsplen); |
| 3412 |
if (ret) |
| 3413 |
return ret; |
| 3414 |
|
| 3415 |
/* Copy over serial number */ |
| 3416 |
strncpy(buf, (char*)rspbuf, buf_len); |
| 3417 |
|
| 3418 |
return CUPS_BACKEND_OK; |
| 3419 |
} |
| 3420 |
|
| 3421 |
static int hiti_query_markers(void *vctx, struct marker **markers, int *count) |
| 3422 |
{ |
| 3423 |
struct hiti_ctx *ctx = vctx; |
| 3424 |
int ret; |
| 3425 |
|
| 3426 |
if (markers) |
| 3427 |
*markers = &ctx->marker; |
| 3428 |
if (count) |
| 3429 |
*count = 1; |
| 3430 |
|
| 3431 |
ret = hiti_query_statistics(ctx); |
| 3432 |
if (ret) |
| 3433 |
return ret; |
| 3434 |
|
| 3435 |
if (ctx->sheet) { |
| 3436 |
ctx->marker.levelnow = CUPS_MARKER_UNKNOWN_OK; |
| 3437 |
// XXX alter this, check for errors and return 0 instead. |
| 3438 |
} else { |
| 3439 |
ctx->marker.levelnow = ctx->media_remain; |
| 3440 |
} |
| 3441 |
|
| 3442 |
return CUPS_BACKEND_OK; |
| 3443 |
} |
| 3444 |
|
| 3445 |
static int hiti_query_stats(void *vctx, struct printerstats *stats) |
| 3446 |
{ |
| 3447 |
struct hiti_ctx *ctx = vctx; |
| 3448 |
uint8_t sts[3]; |
| 3449 |
uint32_t err = 0; |
| 3450 |
uint32_t tmp[2] = {0, 0}; /* Second only used for P51x */ |
| 3451 |
|
| 3452 |
/* Update marker info */ |
| 3453 |
if (hiti_query_markers(ctx, NULL, NULL)) |
| 3454 |
return CUPS_BACKEND_FAILED; |
| 3455 |
if (hiti_query_status(ctx, sts, &err)) |
| 3456 |
return CUPS_BACKEND_FAILED; |
| 3457 |
|
| 3458 |
stats->mfg = "HiTi"; |
| 3459 |
stats->model = ctx->id; |
| 3460 |
stats->serial = ctx->serno; |
| 3461 |
stats->fwver = ctx->version; |
| 3462 |
|
| 3463 |
stats->decks = 1; |
| 3464 |
stats->mediatype[0] = ctx->marker.name; |
| 3465 |
stats->levelmax[0] = ctx->marker.levelmax; |
| 3466 |
stats->levelnow[0] = ctx->marker.levelnow; |
| 3467 |
stats->name[0] = "Roll"; |
| 3468 |
stats->cnt_life[0] = 0; |
| 3469 |
|
| 3470 |
if (hiti_query_counter(ctx, 1, tmp, ctx->erdc_rpc_len)) |
| 3471 |
return CUPS_BACKEND_FAILED; |
| 3472 |
|
| 3473 |
stats->cnt_life[0] += tmp[0]; |
| 3474 |
|
| 3475 |
if (err) |
| 3476 |
stats->status[0] = strdup(hiti_errors(err)); |
| 3477 |
else |
| 3478 |
stats->status[0] = strdup(hiti_status(sts)); |
| 3479 |
|
| 3480 |
return CUPS_BACKEND_OK; |
| 3481 |
} |
| 3482 |
|
| 3483 |
static void *hiti_find_heattable_v2_entry(const struct hiti_printjob *job, int id, size_t *len) |
| 3484 |
{ |
| 3485 |
int i; |
| 3486 |
for (i = 0; i < job->num_heattable_entries ; i++) { |
| 3487 |
if (job->heattable_v2[i].type == id) { |
| 3488 |
*len = job->heattable_v2[i].len; |
| 3489 |
return job->heattable_v2[i].data; |
| 3490 |
} |
| 3491 |
} |
| 3492 |
*len = 0; |
| 3493 |
return NULL; |
| 3494 |
} |
| 3495 |
|
| 3496 |
static int hiti_parse_heattable_v2(struct hiti_printjob *job) { |
| 3497 |
int i; |
| 3498 |
struct hiti_heattable_hdr_v2 *hdr; |
| 3499 |
uint32_t base = 0; |
| 3500 |
uint8_t match = 0x00; /* Or 0x20 when there's more than one? */ |
| 3501 |
|
| 3502 |
restart: |
| 3503 |
hdr = (struct hiti_heattable_hdr_v2 *) job->heattable_buf; |
| 3504 |
job->heattable_v2 = malloc(hdr->num_headers * sizeof(struct hiti_heattable_v2)); |
| 3505 |
if (!job->heattable_buf) { |
| 3506 |
ERROR("Memory allocation failed!\n"); |
| 3507 |
return CUPS_BACKEND_FAILED; |
| 3508 |
} |
| 3509 |
|
| 3510 |
job->num_heattable_entries = hdr->num_headers; |
| 3511 |
|
| 3512 |
for (i = 0 ; i < hdr->num_headers ; i++) { |
| 3513 |
job->heattable_v2[i].type = hdr->entries[i].type; |
| 3514 |
job->heattable_v2[i].data = job->heattable_buf + base + le32_to_cpu(hdr->entries[i].offset); |
| 3515 |
job->heattable_v2[i].len = le32_to_cpu(hdr->entries[i].len) * 2; |
| 3516 |
|
| 3517 |
if (dyesub_debug) |
| 3518 |
DEBUG("Heattable entry: %02x len %d @ %d\n", |
| 3519 |
job->heattable_v2[i].type, |
| 3520 |
job->heattable_v2[i].len, |
| 3521 |
le32_to_cpu(hdr->entries[i].offset)); |
| 3522 |
|
| 3523 |
if (hdr->entries[i].type == match) { |
| 3524 |
if (dyesub_debug) |
| 3525 |
DEBUG("Found embedded table type %0x02\n", match); |
| 3526 |
base = le32_to_cpu(hdr->entries[i].offset); |
| 3527 |
free(job->heattable_v2); |
| 3528 |
goto restart; |
| 3529 |
} |
| 3530 |
} |
| 3531 |
|
| 3532 |
return CUPS_BACKEND_OK; |
| 3533 |
}; |
| 3534 |
|
| 3535 |
#define APPEND_ENTRY(__type) do { \ |
| 3536 |
data = hiti_find_heattable_v2_entry(job, __type, &len); \ |
| 3537 |
if (data) { \ |
| 3538 |
table->entries[table->num_headers++].type = __type; \ |
| 3539 |
} \ |
| 3540 |
} while(0) |
| 3541 |
|
| 3542 |
#define APPEND_ENTRY_FAIL(__type) do { \ |
| 3543 |
data = hiti_find_heattable_v2_entry(job, __type, &len); \ |
| 3544 |
if (data) { \ |
| 3545 |
table->entries[table->num_headers++].type = __type; \ |
| 3546 |
} else { \ |
| 3547 |
ERROR("Missing required HEATv2 entry %02x\n", __type); \ |
| 3548 |
goto fail; \ |
| 3549 |
} \ |
| 3550 |
} while(0) |
| 3551 |
|
| 3552 |
#define APPEND_ENTRY_FAIL2(__type, __type2) do { \ |
| 3553 |
data = hiti_find_heattable_v2_entry(job, __type, &len); \ |
| 3554 |
if (data) { \ |
| 3555 |
table->entries[table->num_headers++].type = __type; \ |
| 3556 |
} else { \ |
| 3557 |
data = hiti_find_heattable_v2_entry(job, __type2, &len); \ |
| 3558 |
if (data) { \ |
| 3559 |
table->entries[table->num_headers++].type = __type2; \ |
| 3560 |
} else { \ |
| 3561 |
ERROR("Missing required HEATv2 entry %02x/%02x\n", __type,__type2); \ |
| 3562 |
goto fail; \ |
| 3563 |
} \ |
| 3564 |
} \ |
| 3565 |
} while(0) |
| 3566 |
|
| 3567 |
#define APPEND_ENTRY_FALLBACK2(__type, __type2, __var2) do { \ |
| 3568 |
data = hiti_find_heattable_v2_entry(job, __type, &len); \ |
| 3569 |
if (data) { \ |
| 3570 |
table->entries[table->num_headers++].type = __type; \ |
| 3571 |
} else if (!__var2) { \ |
| 3572 |
data = hiti_find_heattable_v2_entry(job, __type2, &len); \ |
| 3573 |
if (data) { \ |
| 3574 |
table->entries[table->num_headers++].type = __type2; \ |
| 3575 |
__var2 = 1; \ |
| 3576 |
} \ |
| 3577 |
} \ |
| 3578 |
} while(0) |
| 3579 |
|
| 3580 |
#define APPEND_ENTRY_FALLBACK3(__type, __type2, __var2, __type3, __var3) do { \ |
| 3581 |
data = hiti_find_heattable_v2_entry(job, __type, &len); \ |
| 3582 |
if (data) { \ |
| 3583 |
table->entries[table->num_headers++].type = __type; \ |
| 3584 |
} else if (!__var2) { \ |
| 3585 |
data = hiti_find_heattable_v2_entry(job, __type2, &len); \ |
| 3586 |
if (data) { \ |
| 3587 |
table->entries[table->num_headers++].type = __type2; \ |
| 3588 |
__var2 = 1; \ |
| 3589 |
} else if (!__var3) { \ |
| 3590 |
data = hiti_find_heattable_v2_entry(job, __type3, &len); \ |
| 3591 |
if (data) { \ |
| 3592 |
table->entries[table->num_headers++].type = __type3; \ |
| 3593 |
__var3 = 1; \ |
| 3594 |
} \ |
| 3595 |
} \ |
| 3596 |
} \ |
| 3597 |
} while(0) |
| 3598 |
|
| 3599 |
static int hiti_construct_heattable_v2(const struct hiti_printjob *job, int planes, int colormode, struct hiti_heattable_hdr_v2 *table) |
| 3600 |
{ |
| 3601 |
size_t len; |
| 3602 |
void *data; |
| 3603 |
|
| 3604 |
int hac_ymc = 0, hac_all = 0; |
| 3605 |
int ls_ymc = 0, ls_all = 0; |
| 3606 |
int gl_ymc = 0, gl_all = 0; |
| 3607 |
int en_ymc = 0, en_all = 0; |
| 3608 |
|
| 3609 |
table->num_headers = 0; |
| 3610 |
|
| 3611 |
/* Version is required */ |
| 3612 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_VER_MAJOR); |
| 3613 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_VER_MINOR); |
| 3614 |
|
| 3615 |
if (planes & HT_PLANE_Y) { |
| 3616 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_HT_D_Y); |
| 3617 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_HAC_Y, HEATTABLE_V2_ID_HAC_YMC, hac_ymc, HEATTABLE_V2_ID_HAC_ALL, hac_all); |
| 3618 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_LS_Y, HEATTABLE_V2_ID_LS_YMC, ls_ymc, HEATTABLE_V2_ID_LS_ALL, ls_all); |
| 3619 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_GL_Y, HEATTABLE_V2_ID_GL_YMC, gl_ymc, HEATTABLE_V2_ID_GL_ALL, gl_all); |
| 3620 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_EN_Y, HEATTABLE_V2_ID_EN_YMC, en_ymc, HEATTABLE_V2_ID_EN_ALL, en_all); |
| 3621 |
} |
| 3622 |
if (planes & HT_PLANE_M) { |
| 3623 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_HT_D_M); |
| 3624 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_HAC_M, HEATTABLE_V2_ID_HAC_YMC, hac_ymc, HEATTABLE_V2_ID_HAC_ALL, hac_all); |
| 3625 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_LS_M, HEATTABLE_V2_ID_LS_YMC, ls_ymc, HEATTABLE_V2_ID_LS_ALL, ls_all); |
| 3626 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_GL_M, HEATTABLE_V2_ID_GL_YMC, gl_ymc, HEATTABLE_V2_ID_GL_ALL, gl_all); |
| 3627 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_EN_M, HEATTABLE_V2_ID_EN_YMC, en_ymc, HEATTABLE_V2_ID_EN_ALL, en_all); |
| 3628 |
} |
| 3629 |
if (planes & HT_PLANE_C) { |
| 3630 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_HT_D_C); |
| 3631 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_HAC_C, HEATTABLE_V2_ID_HAC_YMC, hac_ymc, HEATTABLE_V2_ID_HAC_ALL, hac_all); |
| 3632 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_LS_C, HEATTABLE_V2_ID_LS_YMC, ls_ymc, HEATTABLE_V2_ID_LS_ALL, ls_all); |
| 3633 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_GL_C, HEATTABLE_V2_ID_GL_YMC, gl_ymc, HEATTABLE_V2_ID_GL_ALL, gl_all); |
| 3634 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_EN_C, HEATTABLE_V2_ID_EN_YMC, en_ymc, HEATTABLE_V2_ID_EN_ALL, en_all); |
| 3635 |
} |
| 3636 |
if (planes & HT_PLANE_K) { |
| 3637 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_HT_D_K); |
| 3638 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_HAC_DK, HEATTABLE_V2_ID_HAC_YMC, hac_ymc, HEATTABLE_V2_ID_HAC_ALL, hac_all); |
| 3639 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_LS_DK, HEATTABLE_V2_ID_LS_YMC, ls_ymc, HEATTABLE_V2_ID_LS_ALL, ls_all); |
| 3640 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_GL_DK, HEATTABLE_V2_ID_GL_YMC, gl_ymc, HEATTABLE_V2_ID_GL_ALL, gl_all); |
| 3641 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_EN_DK, HEATTABLE_V2_ID_EN_YMC, en_ymc, HEATTABLE_V2_ID_EN_ALL, en_all); |
| 3642 |
} |
| 3643 |
|
| 3644 |
if (planes & HT_PLANE_RK) { |
| 3645 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_HT_R_RK); |
| 3646 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_HAC_RK, HEATTABLE_V2_ID_HAC_YMC, hac_ymc, HEATTABLE_V2_ID_HAC_ALL, hac_all); |
| 3647 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_LS_RK, HEATTABLE_V2_ID_LS_YMC, ls_ymc, HEATTABLE_V2_ID_LS_ALL, ls_all); |
| 3648 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_GL_RK, HEATTABLE_V2_ID_GL_YMC, gl_ymc, HEATTABLE_V2_ID_GL_ALL, gl_all); |
| 3649 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_EN_RK, HEATTABLE_V2_ID_EN_YMC, en_ymc, HEATTABLE_V2_ID_EN_ALL, en_all); |
| 3650 |
} else if (planes & HT_PLANE_R) { |
| 3651 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_HT_R_R); |
| 3652 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_HAC_R, HEATTABLE_V2_ID_HAC_YMC, hac_ymc, HEATTABLE_V2_ID_HAC_ALL, hac_all); |
| 3653 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_LS_R, HEATTABLE_V2_ID_LS_YMC, ls_ymc, HEATTABLE_V2_ID_LS_ALL, ls_all); |
| 3654 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_GL_R, HEATTABLE_V2_ID_GL_YMC, gl_ymc, HEATTABLE_V2_ID_GL_ALL, gl_all); |
| 3655 |
APPEND_ENTRY_FALLBACK3(HEATTABLE_V2_ID_EN_R, HEATTABLE_V2_ID_EN_YMC, en_ymc, HEATTABLE_V2_ID_EN_ALL, en_all); |
| 3656 |
} |
| 3657 |
|
| 3658 |
if (planes & HT_PLANE_OG) { |
| 3659 |
APPEND_ENTRY_FAIL2(HEATTABLE_V2_ID_HT_D_O, HEATTABLE_V2_ID_HT_D_KO); |
| 3660 |
APPEND_ENTRY_FALLBACK2(HEATTABLE_V2_ID_HAC_O, HEATTABLE_V2_ID_HAC_ALL, hac_all); |
| 3661 |
APPEND_ENTRY_FALLBACK2(HEATTABLE_V2_ID_LS_O, HEATTABLE_V2_ID_LS_ALL, ls_all); |
| 3662 |
APPEND_ENTRY_FALLBACK2(HEATTABLE_V2_ID_GL_O, HEATTABLE_V2_ID_GL_ALL, gl_all); |
| 3663 |
APPEND_ENTRY_FALLBACK2(HEATTABLE_V2_ID_EN_O, HEATTABLE_V2_ID_EN_ALL, en_all); |
| 3664 |
} else if (planes & HT_PLANE_OK) { |
| 3665 |
APPEND_ENTRY_FAIL2(HEATTABLE_V2_ID_HT_D_KO, HEATTABLE_V2_ID_HT_D_O); |
| 3666 |
APPEND_ENTRY_FALLBACK2(HEATTABLE_V2_ID_HAC_O, HEATTABLE_V2_ID_HAC_ALL, hac_all); |
| 3667 |
APPEND_ENTRY_FALLBACK2(HEATTABLE_V2_ID_LS_O, HEATTABLE_V2_ID_LS_ALL, ls_all); |
| 3668 |
APPEND_ENTRY_FALLBACK2(HEATTABLE_V2_ID_GL_O, HEATTABLE_V2_ID_GL_ALL, gl_all); |
| 3669 |
APPEND_ENTRY_FALLBACK2(HEATTABLE_V2_ID_EN_O, HEATTABLE_V2_ID_EN_ALL, en_all); |
| 3670 |
} else if (planes & HT_PLANE_OM) { |
| 3671 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_HT_D_MO); |
| 3672 |
APPEND_ENTRY_FALLBACK2(HEATTABLE_V2_ID_HAC_MO, HEATTABLE_V2_ID_HAC_ALL, hac_all); |
| 3673 |
APPEND_ENTRY_FALLBACK2(HEATTABLE_V2_ID_LS_MO, HEATTABLE_V2_ID_LS_ALL, ls_all); |
| 3674 |
APPEND_ENTRY_FALLBACK2(HEATTABLE_V2_ID_GL_MO, HEATTABLE_V2_ID_GL_ALL, gl_all); |
| 3675 |
APPEND_ENTRY_FALLBACK2(HEATTABLE_V2_ID_EN_MO, HEATTABLE_V2_ID_EN_ALL, en_all); |
| 3676 |
} |
| 3677 |
if (planes & HT_PLANE_FO) { |
| 3678 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_HT_R_FO); |
| 3679 |
APPEND_ENTRY_FALLBACK2(HEATTABLE_V2_ID_HAC_FO, HEATTABLE_V2_ID_HAC_ALL, hac_all); |
| 3680 |
APPEND_ENTRY_FALLBACK2(HEATTABLE_V2_ID_LS_FO, HEATTABLE_V2_ID_LS_ALL, ls_all); |
| 3681 |
APPEND_ENTRY_FALLBACK2(HEATTABLE_V2_ID_GL_FO, HEATTABLE_V2_ID_GL_ALL, gl_all); |
| 3682 |
APPEND_ENTRY_FALLBACK2(HEATTABLE_V2_ID_EN_FO, HEATTABLE_V2_ID_EN_ALL, en_all); |
| 3683 |
} |
| 3684 |
if (planes & HT_PLANE_L) { |
| 3685 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_HT_R_L); |
| 3686 |
} |
| 3687 |
|
| 3688 |
if (planes & HT_CVD) { |
| 3689 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_CVD); |
| 3690 |
} |
| 3691 |
|
| 3692 |
if (colormode == HT_COLORMODE_CLASSIC) { |
| 3693 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_CT_CLASSIC); |
| 3694 |
} else if (colormode == HT_COLORMODE_IDPASS_VIVID) { |
| 3695 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_CT_IDPASS); |
| 3696 |
} else { |
| 3697 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_CT_INVERT); |
| 3698 |
} |
| 3699 |
|
| 3700 |
APPEND_ENTRY(HEATTABLE_V2_ID_TC_COMPENSATE); |
| 3701 |
|
| 3702 |
if (planes & HT_PLANE_630X) { |
| 3703 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_OP1); |
| 3704 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_OP2); |
| 3705 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_SMEAR); |
| 3706 |
APPEND_ENTRY_FAIL(HEATTABLE_V2_ID_MSKL_RATE); |
| 3707 |
} |
| 3708 |
|
| 3709 |
return 0; |
| 3710 |
|
| 3711 |
fail: |
| 3712 |
table->num_headers = 0; |
| 3713 |
return 1; |
| 3714 |
} |
| 3715 |
|
| 3716 |
static void hiti_teardown(void *vctx) { |
| 3717 |
struct hiti_ctx *ctx = vctx; |
| 3718 |
free(ctx); |
| 3719 |
} |
| 3720 |
|
| 3721 |
#define JOB_EQUIV(__x) if (job1->__x != job2->__x) goto done |
| 3722 |
|
| 3723 |
static void *hiti_combine_jobs(const void *vjob1, |
| 3724 |
const void *vjob2) |
| 3725 |
{ |
| 3726 |
const struct hiti_printjob *job1 = vjob1; |
| 3727 |
const struct hiti_printjob *job2 = vjob2; |
| 3728 |
struct hiti_printjob *newjob = NULL; |
| 3729 |
uint16_t newrows; |
| 3730 |
int32_t newpad; |
| 3731 |
uint16_t newmode; |
| 3732 |
|
| 3733 |
if (!job1 || !job2) |
| 3734 |
goto done; |
| 3735 |
|
| 3736 |
/* Make sure the two jobs can be combined */ |
| 3737 |
JOB_EQUIV(colormode); |
| 3738 |
JOB_EQUIV(hdr.cols); |
| 3739 |
JOB_EQUIV(hdr.rows); |
| 3740 |
JOB_EQUIV(hdr.quality); |
| 3741 |
JOB_EQUIV(hdr.code); |
| 3742 |
JOB_EQUIV(hdr.overcoat); |
| 3743 |
JOB_EQUIV(hdr.payload_flag); |
| 3744 |
JOB_EQUIV(hdr.payload_len); |
| 3745 |
|
| 3746 |
if (job1->hdr.cols == 1844 && job1->hdr.rows == 1072) { |
| 3747 |
/* 2x 3.5x5" -> 1x 5x7-div2 */ |
| 3748 |
newrows = 2152; |
| 3749 |
newpad = 8; |
| 3750 |
newmode = PRINT_TYPE_5x7_2UP; |
| 3751 |
} else if (job1->hdr.cols == 1844 && job1->hdr.rows == 1240) { |
| 3752 |
/* 2x 4x6 -> 1x 8x6-div2 */ |
| 3753 |
newrows = 2492; |
| 3754 |
newpad = 12; |
| 3755 |
newmode = PRINT_TYPE_6x9_2UP; |
| 3756 |
} else if (job1->hdr.cols == 1844 && job1->hdr.rows == 1248) { |
| 3757 |
/* 2x 4x6-div2 -> 1x 8x6-div4 */ |
| 3758 |
/* 2x 4x6-div3 -> 1x 8x6-div6 */ |
| 3759 |
newrows = 2492; |
| 3760 |
newpad = -4; // XXX better handle this? |
| 3761 |
if (job1->hdr.code == PRINT_TYPE_6x4_3UP) |
| 3762 |
newmode = PRINT_TYPE_6x9_6UP; |
| 3763 |
else |
| 3764 |
newmode = PRINT_TYPE_6x9_4UP; |
| 3765 |
} else { |
| 3766 |
goto done; |
| 3767 |
} |
| 3768 |
|
| 3769 |
newpad *= job1->hdr.cols; |
| 3770 |
|
| 3771 |
/* At this point it's kosher to proceed */ |
| 3772 |
|
| 3773 |
DEBUG("Combining jobs to save media\n"); |
| 3774 |
|
| 3775 |
/* Allocate new job, duplicate job1's parameters */ |
| 3776 |
newjob = malloc(sizeof(*newjob)); |
| 3777 |
if (!newjob) { |
| 3778 |
ERROR("Memory allocation failure!\n"); |
| 3779 |
goto done; |
| 3780 |
} |
| 3781 |
memcpy(newjob, job1, sizeof(*newjob)); |
| 3782 |
|
| 3783 |
newjob->heattable_buf = malloc(job1->heattable_len); |
| 3784 |
if (!newjob->heattable_buf) { |
| 3785 |
ERROR("Memory allocation failure!\n"); |
| 3786 |
hiti_cleanup_job(newjob); |
| 3787 |
newjob = NULL; |
| 3788 |
goto done; |
| 3789 |
} |
| 3790 |
memcpy(newjob->heattable_buf, job1->heattable_buf, job1->heattable_len); |
| 3791 |
|
| 3792 |
/* Set up new job, where it differs */ |
| 3793 |
newjob->hdr.rows = newrows; |
| 3794 |
newjob->hdr.code = newmode; |
| 3795 |
newjob->datalen = 0; |
| 3796 |
newjob->databuf = malloc(newjob->hdr.rows * newjob->hdr.cols * 3); |
| 3797 |
|
| 3798 |
if (!newjob->databuf) { |
| 3799 |
ERROR("Memory allocation failed!\n"); |
| 3800 |
hiti_cleanup_job(newjob); |
| 3801 |
newjob = NULL; |
| 3802 |
goto done; |
| 3803 |
} |
| 3804 |
|
| 3805 |
uint32_t planelen = job1->hdr.rows * job1->hdr.cols; |
| 3806 |
|
| 3807 |
/* Copy over Y planes */ |
| 3808 |
memcpy(newjob->databuf + newjob->datalen, job1->databuf, planelen); |
| 3809 |
newjob->datalen += planelen; |
| 3810 |
if (newpad > 0) |
| 3811 |
memset(newjob->databuf + newjob->datalen, 0, newpad); |
| 3812 |
newjob->datalen += newpad; |
| 3813 |
memcpy(newjob->databuf + newjob->datalen, job2->databuf, planelen); |
| 3814 |
newjob->datalen += planelen; |
| 3815 |
|
| 3816 |
/* Copy over M planes */ |
| 3817 |
memcpy(newjob->databuf + newjob->datalen, job1->databuf + planelen, planelen); |
| 3818 |
newjob->datalen += planelen; |
| 3819 |
if (newpad > 0) |
| 3820 |
memset(newjob->databuf + newjob->datalen, 0, newpad); |
| 3821 |
newjob->datalen += newpad; |
| 3822 |
memcpy(newjob->databuf + newjob->datalen, job2->databuf + planelen, planelen); |
| 3823 |
newjob->datalen += planelen; |
| 3824 |
|
| 3825 |
/* Copy over C planes */ |
| 3826 |
memcpy(newjob->databuf + newjob->datalen, job1->databuf + planelen + planelen, planelen); |
| 3827 |
newjob->datalen += planelen; |
| 3828 |
if (newpad > 0) |
| 3829 |
memset(newjob->databuf + newjob->datalen, 0, newpad); |
| 3830 |
newjob->datalen += newpad; |
| 3831 |
memcpy(newjob->databuf + newjob->datalen, job2->databuf + planelen + planelen, planelen); |
| 3832 |
newjob->datalen += planelen; |
| 3833 |
|
| 3834 |
/* All done */ |
| 3835 |
|
| 3836 |
done: |
| 3837 |
return newjob; |
| 3838 |
} |
| 3839 |
|
| 3840 |
#undef JOB_EQUIV |
| 3841 |
|
| 3842 |
static const char *hiti_prefixes[] = { |
| 3843 |
"hiti", // Family name |
| 3844 |
"hiti-p52x", /* Just in case */ |
| 3845 |
NULL |
| 3846 |
}; |
| 3847 |
|
| 3848 |
static const struct device_id hiti_devices[] = { |
| 3849 |
{ 0x0d16, 0x0309, P_HITI_CS2XX, NULL, "hiti-cs200e"}, |
| 3850 |
{ 0x0d16, 0x030a, P_HITI_CS2XX, NULL, "hiti-cs220e"}, |
| 3851 |
{ 0x0d16, 0x030b, P_HITI_CS2XX, NULL, "hiti-cs230e"}, |
| 3852 |
{ 0x0d16, 0x030c, P_HITI_CS2XX, NULL, "hiti-cs250e"}, |
| 3853 |
{ 0x0d16, 0x030d, P_HITI_CS2XX, NULL, "hiti-cs290e"}, |
| 3854 |
{ 0x0d16, 0x0007, P_HITI_51X, NULL, "hiti-p510k"}, |
| 3855 |
{ 0x0d16, 0x000b, P_HITI_51X, NULL, "hiti-p510l"}, |
| 3856 |
{ 0x0d16, 0x000d, P_HITI_51X, NULL, "hiti-p518a"}, |
| 3857 |
{ 0x0d16, 0x010e, P_HITI_51X, NULL, "hiti-p510s"}, |
| 3858 |
{ 0x0d16, 0x0111, P_HITI_51X, NULL, "hiti-p510si"}, |
| 3859 |
{ 0x0d16, 0x0112, P_HITI_51X, NULL, "hiti-p518s"}, |
| 3860 |
{ 0x0d16, 0x0502, P_HITI_520, NULL, "hiti-p520l"}, |
| 3861 |
{ 0x0d16, 0x0503, P_HITI_310, NULL, "hiti-p310l"}, |
| 3862 |
{ 0x0d16, 0x050a, P_HITI_310, NULL, "hiti-p310w"}, |
| 3863 |
{ 0x0d16, 0x050c, P_HITI_320, NULL, "hiti-p320w"}, |
| •3864 |
{ 0x0d16, 0x050a, P_HITI_310, NULL, "hiti-p322w"}, /* Duplicate */ |
| 3865 |
{ 0x0d16, 0x0509, P_HITI_461, NULL, "hiti-p461"}, |
| 3866 |
{ 0x0d16, 0x050e, P_HITI_525, NULL, "hiti-p525l"}, |
| 3867 |
{ 0x0d16, 0x000f, P_HITI_530, NULL, "hiti-p530d"}, |
| 3868 |
{ 0x0d16, 0x0009, P_HITI_720, NULL, "hiti-p720l"}, |
| 3869 |
{ 0x0d16, 0x000a, P_HITI_720, NULL, "hiti-p728l"}, |
| 3870 |
{ 0x0d16, 0x0501, P_HITI_750, NULL, "hiti-p750l"}, |
| 3871 |
{ 0x0d16, 0x0510, P_HITI_826, NULL, "joyspace-u826"}, /* OEM variant of P525 */ |
| 3872 |
{ 0x0d16, 0x0511, P_HITI_630, NULL, "hiti-p630"}, |
| •3873 |
{ 0x0d16, 0x0511, P_HITI_630, NULL, "hiti-p630a"}, /* Duplicate */ |
| 3874 |
// { 0x0d16, XXXXX, P_HITI_630, NULL, "hiti-p630c"}, // placeholder |
| 3875 |
{ 0x0d16, 0x0512, P_SWIFTFOTO_KSF10, NULL, "swiftfoto-ksf10r"}, /* OEM variant of P525 */ |
| 3876 |
{ 0x0d16, 0xc000, P_HITI_51X, NULL, "yashica-yp120"}, |
| 3877 |
{ 0x0d16, 0xd000, P_HITI_51X, NULL, "touchtunes-p510tt"}, |
| 3878 |
{ 0, 0, 0, NULL, NULL} |
| 3879 |
/* |
| 3880 |
#define USB_PID_HITI_P110S 0x0110 |
| 3881 |
#define USB_PID_HITI_X610 0x0800 |
| 3882 |
*/ |
| 3883 |
|
| 3884 |
}; |
| 3885 |
|
| 3886 |
const struct dyesub_backend hiti_backend = { |
| 3887 |
.name = "HiTi Photo Printers", |
| •3888 |
.version = "0.97", |
| 3889 |
.uri_prefixes = hiti_prefixes, |
| 3890 |
.cmdline_usage = hiti_cmdline, |
| 3891 |
.cmdline_arg = hiti_cmdline_arg, |
| 3892 |
.init = hiti_init, |
| 3893 |
.teardown = hiti_teardown, |
| 3894 |
.attach = hiti_attach, |
| 3895 |
.cleanup_job = hiti_cleanup_job, |
| 3896 |
.read_parse = hiti_read_parse, |
| 3897 |
.main_loop = hiti_main_loop, |
| 3898 |
.query_serno = hiti_query_serno, |
| 3899 |
.query_markers = hiti_query_markers, |
| 3900 |
.query_stats = hiti_query_stats, |
| 3901 |
.combine_jobs = hiti_combine_jobs, |
| 3902 |
.devices = hiti_devices, |
| 3903 |
}; |
| 3904 |
|
| 3905 |
/* TODO: |
| 3906 |
|
| 3907 |
- Figure out 5x5 prints |
| 3908 |
- Confirm 6x2" print dimensions (windows?) |
| 3909 |
- Job control (QJC, RSJ) -- and canceling? |
| 3910 |
- Set highlight adjustment & H/V alignment from cmdline |
| 3911 |
* Figure out how to set H/V alignment! |
| 3912 |
- Figure out if driver needs to consume highlight adjustment |
| 3913 |
* Feed into gamma correction? |
| 3914 |
* Feed [un]modified into some printer cmd? |
| 3915 |
- Figure out Windows spool format (probably never) |
| 3916 |
- GP Spool parsing improvements |
| 3917 |
* Add additional 'reserved' fields for future use? |
| 3918 |
- Further performance optimizations in LUT color conversion code |
| 3919 |
* Rework to take advantage of auto-vectorization? |
| 3920 |
* Pre-compute then cache entire map on disk? |
| 3921 |
* Use external "Cube LUT" implementation? |
| 3922 |
- Commands UNK_8008, UNK_8010, UNK_800C, ESD_SEHT, CMD_EDM_* |
| 3923 |
- Test with P720, P750 |
| 3924 |
- Incorporate changes for CS-series card printers |
| 3925 |
- More "Matrix table" decoding work |
| 3926 |
- More work on other "sheet type" models |
| 3927 |
- P110S ("P4x6" 1248x1836) |
| 3928 |
- P320 series ("P4x6" 1280*1818) |
| 3929 |
- Others? |
| 3930 |
- More work on remaining "roll type" models |
| 3931 |
- P530D |
| 3932 |
- X610 |
| 3933 |
- Others? |
| 3934 |
- More work on P461 Prinhome |
| 3935 |
- Quality mode |
| 3936 |
- Figure out when to use Heat tables with 'p' quality tags |
| 3937 |
- Figure out how to send over the "raw" matte overcoat data. (Partial matte is now possible on P52x/P630?) |
| 3938 |
- P630 Quality analysis on YMC planar data |
| 3939 |
*/ |