hiti: Refactor the p51x heat table loading code a bit

This commit is contained in:
Solomon Peachy 2022-10-27 05:17:40 -04:00
parent adc7d669a1
commit e5df30205c

View file

@ -258,20 +258,25 @@ struct hiti_heattable_v1a { /* P51x (older) */
STATIC_ASSERT(sizeof(struct hiti_heattable_v1a) == 11008);
struct hiti_heattable_v1b_hdr {
uint8_t type;
uint32_t len; /* Length in 16-bit words, LE */
} __attribute((packed));
struct hiti_heattable_v1b { /* P51x (newer) */
uint8_t y_hdr[5]; // 01 01 04 00 00
struct hiti_heattable_v1b_hdr y_hdr; // 01 01 04 00 00
uint8_t y[2050]; /* 256 doubles, 2 checksum */
uint8_t m_hdr[5]; // 02 01 04 00 00
struct hiti_heattable_v1b_hdr m_hdr; // 02 01 04 00 00
uint8_t m[2050]; /* 256 doubles, 2 checksum */
uint8_t c_hdr[5]; // 03 01 04 00 00
struct hiti_heattable_v1b_hdr c_hdr; // 03 01 04 00 00
uint8_t c[2050]; /* 256 doubles, 2 checksum */
uint8_t o_hdr[5]; // 04 01 04 00 00
struct hiti_heattable_v1b_hdr o_hdr; // 04 01 04 00 00
uint8_t o[2050]; /* 256 doubles, 2 checksum */
uint8_t om_hdr[5]; // 05 01 04 00 00
struct hiti_heattable_v1b_hdr om_hdr; // 05 01 04 00 00
uint8_t om[2050]; /* 256 doubles, 2 checksum */
uint8_t u_hdr[5]; // 07 01 04 00 00 // Unknown purpose
struct hiti_heattable_v1b_hdr u_hdr; // 07 01 04 00 00
uint8_t u[2050]; /* 256 doubles, 2 checksum */ // unknown purpose
uint8_t cvd_hdr[5]; // 00 00 00 00 00
struct hiti_heattable_v1b_hdr cvd_hdr; // 08 23 01 00 00
uint8_t cvd[582]; /* 58 u16 * 5 (y/m/c/o/om) + 2 byte checksum? */
} __attribute__((packed));
@ -1541,51 +1546,46 @@ static int hiti_send_heat_data(struct hiti_ctx *ctx, uint8_t mode, uint8_t matte
fname = hiti_get_heat_file(ctx, mode);
if (fname) {
char full[2048];
snprintf(full, sizeof(full), "%s/%s", corrtable_path, fname);
if (!fname) {
WARNING("Heattable filename missing, skipping?\n");
return CUPS_BACKEND_OK;
}
ret = dyesub_read_file(full, (uint8_t*) &table, sizeof(table), &len);
if (ret) {
return ret;
}
switch(len) {
case sizeof(struct hiti_heattable_v1a):
y = table.v1a.y;
m = table.v1a.m;
c = table.v1a.c;
o = table.v1a.o;
om = table.v1a.om;
cvd = table.v1a.cvd;
break;
case sizeof(struct hiti_heattable_v1b):
y = table.v1b.y;
m = table.v1b.m;
c = table.v1b.c;
o = table.v1b.o;
om = table.v1b.om;
cvd = table.v1b.cvd;
break;
default:
ERROR("Heattable len mismatch (%d)\n", len);
return CUPS_BACKEND_FAILED;
}
} else {
memset(&table, 0, sizeof(table));
char full[2048];
snprintf(full, sizeof(full), "%s/%s", corrtable_path, fname);
ret = dyesub_read_file(full, (uint8_t*) &table, sizeof(table), &len);
if (ret)
return ret;
switch(len) {
case sizeof(struct hiti_heattable_v1a):
y = table.v1a.y;
m = table.v1a.m;
c = table.v1a.c;
o = table.v1a.o;
om = table.v1a.om;
cvd = table.v1a.cvd;
break;
case sizeof(struct hiti_heattable_v1b):
y = table.v1b.y;
m = table.v1b.m;
c = table.v1b.c;
o = table.v1b.o;
om = table.v1b.om;
cvd = table.v1b.cvd;
break;
default:
ERROR("Heattable len mismatch (%d)\n", len);
return CUPS_BACKEND_FAILED;
}
/* Send over the heat tables */
ret = hiti_seht2(ctx, 0, y, sizeof(table.v1a.om));
ret = hiti_seht2(ctx, 0, y, sizeof(table.v1a.y));
if (!ret)
ret = hiti_seht2(ctx, 1, m, sizeof(table.v1a.om));
ret = hiti_seht2(ctx, 1, m, sizeof(table.v1a.m));
if (!ret)
ret = hiti_seht2(ctx, 2, c, sizeof(table.v1a.om));
ret = hiti_seht2(ctx, 2, c, sizeof(table.v1a.c));
if (!ret) {
if (matte)
ret = hiti_seht2(ctx, 3, om, sizeof(table.v1a.om));
@ -2777,7 +2777,7 @@ static const char *hiti_prefixes[] = {
const struct dyesub_backend hiti_backend = {
.name = "HiTi Photo Printers",
.version = "0.45",
.version = "0.46",
.uri_prefixes = hiti_prefixes,
.cmdline_usage = hiti_cmdline,
.cmdline_arg = hiti_cmdline_arg,