Debian Codegraph @

test/escp2-weavetest.c

raw symbols SCIP
1 /*
2 *
3 * Print plug-in EPSON ESC/P2 driver for the GIMP.
4 *
5 * Copyright 1999-2000 Robert Krawitz ([email protected])
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 *
20 * Test for the soft weave algorithm. This program calculates the weave
21 * parameters for each input line and verifies that a number of conditions
22 * are met. Currently, the conditions checked are:
23 *
24 * 1) Pass # is >= 0
25 * 2) The nozzle is within the physical bounds of the printer
26 * 3) The computed starting row of the pass is not greater than the row
27 * index itself.
28 * 4) The computed end of the pass is not less than the row index itself.
29 * 5) If this row is the last row of a pass, that the last pass completed
30 * was one less than the current pass that we're just completing.
31 * 6) For a given pass, the computed starting row of the pass is the same
32 * for all rows comprising the pass.
33 * 7) For a given pass, the computed last row of the pass is the same
34 * for all rows comprising the pass.
35 * 8) The input row is the same as the row computed by the algorithm.
36 * 9) If there are phantom rows within the pass (unused jets before the
37 * first jet that is actually printing anything), then the number of
38 * phantom rows is not less than zero nor greater than or equal to the
39 * number of physical jets in the printer.
40 * 10) The physical starting row of the pass (disregarding any phantom
41 * rows) is at least zero.
42 * 11) If there are phantom rows, the number of phantom rows is less than
43 * the current nozzle number.
44 * 12) If we are using multiple subpasses for each row, that each row within
45 * this pass is part of the same logical subpass. Thus, if the pass in
46 * question is the first subpass for a given row, that it is the first
47 * subpass for ALL rows comprising the pass. This doesn't matter if we're
48 * simply overlaying data; it's important if we have to shift the print head
49 * slightly between each pass to accomplish high-resolution printing.
50 * 13) We are not overprinting a specified (row, subpass) pair.
51 *
52 * In addition to these per-row checks, we calculate the following global
53 * correctness checks:
54 *
55 * 1) No pass starts (logically) at a later row than an earlier pass.
56 */
57
58 #ifdef HAVE_CONFIG_H
59 #include <config.h>
60 #endif
61 #include <stdlib.h>
62 #include <stdio.h>
63 #include <unistd.h>
64 #include <string.h>
65 #include <limits.h>
66
67 #define DEBUG_SIGNAL
68 #define MIN(x, y) ((x) <= (y) ? (x) : (y))
69 #include <gutenprint/gutenprint.h>
70 #include <gutenprint-internal.h>
71
72 const char header[] = "Legend:\n"
73 "A Negative pass number.\n"
74 "B Jet number out of range.\n"
75 "C Starting row of this pass after the current row.\n"
76 "D Ending row of this pass before the current row.\n"
77 "E Current row is the ending row of the pass, and the pass number is not\n"
78 " one greater than the previous completed pass.\n"
79 "F The current pass's starting row is not consistent with the previously\n"
80 " observed starting row of this pass.\n"
81 "G The current pass's ending row is not consistent with the previously\n"
82 " observed ending row of this pass.\n"
83 "H The current row does not match the computed current row based on jet and\n"
84 " start of pass.\n"
85 "I The number of missing start rows is less than zero or greater than or\n"
86 " equal to the actual number of jets.\n"
87 "J The first printed row of this pass is less than zero.\n"
88 "K The number of missing start rows of this pass is greater than the\n"
89 " jet used to print the current row.\n"
90 "L The subpass printed by the current pass is not consistent with an earlier\n"
91 " record of the subpass printed by this pass.\n"
92 "M The same physical row is being printed more than once.\n"
93 "N Two different active passes are in the same slot.\n"
94 "O Number of missing start rows is incorrect.\n"
95 "P Physical row number out of bounds.\n"
96 "Q Pass starts earlier than a prior pass.\n"
97 "R Pass is never flushed.\n"
98 "S Pass is flushed but not created.\n";
99
100 int *passes_flushed;
101
102 static void
103 print_header(void)
104 {
105 printf("%s", header);
106 }
107
108 static void
109 flush_pass(stp_vars_t *v, int passno, int vertical_subpass)
110 {
111 (void)v;
112 (void)vertical_subpass;
113 passes_flushed[passno] = 1;
114 }
115
116 static void
117 writefunc(void *file, const char *buf, size_t bytes)
118 {
119 FILE *prn = (FILE *)file;
120 fwrite(buf, 1, bytes, prn);
121 }
122
123 static int
124 run_one_weavetest(int physjets, int physsep, int hpasses, int vpasses,
125 int subpasses, int nrows, int first_line, int phys_lines,
126 int color_jet_arrangement, int strategy, int quiet)
127 {
128 int i;
129 int j;
130 stp_weave_t w;
131 stp_vars_t *v;
132 int errors[26];
133 char errcodes[26];
134 int total_errors = 0;
135 int lastpass = -1;
136 int newestpass = -1;
137 int *passstarts;
138 int *logpassstarts;
139 int *passends;
140 int *passcounts;
141 signed char *physpassstuff;
142 signed char *rowdetail;
143 int *current_slot;
144 int vmod;
145 int head_offset[8];
146 int last_good_pass;
147
148 v = stp_vars_create();
149 stp_set_outfunc(v, writefunc);
150 stp_set_errfunc(v, writefunc);
151 stp_set_outdata(v, stdout);
152 stp_set_errdata(v, stdout);
153
154 memset(errors, 0, sizeof(int) * 26);
155 #if 0
156 if (physjets < hpasses * vpasses * subpasses)
157 {
158 return 0;
159 }
160 #endif
161
162 for(i=0; i<8; i++)
163 head_offset[i] = 0;
164
165 switch (color_jet_arrangement)
166 {
167 case 1: /* C80-type */
168 head_offset[0] = (physjets+1)*physsep;
169 head_offset[1] = (physjets+1)*physsep;
170 head_offset[2] = 2*(physjets+1)*physsep;
171 phys_lines += 2*(physjets+1)*physsep;
172 break;
173 case 2: /* Offset by 1 (f360) */
174 if (physsep % 2 == 0)
175 {
176 head_offset[1] = physsep / 2;
177 head_offset[2] = physsep / 2;
178 phys_lines += physsep / 2;
179 }
180 break;
181 case 3: /* Offset by 1 or 2 (cx3650-type) */
182 if (physsep % 3 == 0)
183 {
184 head_offset[1] = physsep * 2 / 3;
185 head_offset[2] = physsep / 3;
186 phys_lines += physsep * 2 / 3;
187 }
188 break;
189 default: /* Normal */
190 break;
191 }
192
193
194 stp_initialize_weave(v, physjets, physsep, hpasses, vpasses, subpasses,
195 7, 1, 128, nrows, first_line,
196 phys_lines, head_offset, strategy, flush_pass,
197 stp_fill_tiff, stp_pack_tiff,
198 stp_compute_tiff_linewidth);
199
200 passstarts = stp_malloc(sizeof(int) * (nrows + physsep));
201 logpassstarts = stp_malloc(sizeof(int) * (nrows + physsep));
202 passends = stp_malloc(sizeof(int) * (nrows + physsep));
203 passcounts = stp_malloc(sizeof(int) * (nrows + physsep));
204 passes_flushed = stp_malloc(sizeof(int) * (nrows + physsep));
205 vmod = 2 * physsep * hpasses * vpasses * subpasses;
206 if (vmod == 0)
207 vmod = 1;
208 current_slot = stp_malloc(sizeof(int) * vmod);
209 physpassstuff = stp_malloc((nrows + physsep));
210 rowdetail = stp_malloc((nrows + physsep) * physjets);
211 memset(rowdetail, 0, (nrows + physsep) * physjets);
212 memset(physpassstuff, -1, (nrows + physsep));
213 memset(current_slot, 0, (sizeof(int) * vmod));
214 if (!quiet)
215 {
216 print_header();
217 printf("%15s %5s %5s %5s %10s %10s %10s %10s\n", "", "row", "pass",
218 "jet", "missing", "logical", "physstart", "physend");
219 }
220 for (i = 0; i < vmod; i++)
221 current_slot[i] = -1;
222 for (i = 0; i < (nrows + physsep); i++)
223 {
224 passes_flushed[i] = 0;
225 logpassstarts[i] = INT_MIN;
226 passstarts[i] = -1;
227 passends[i] = -1;
228 }
229 memset(errcodes, ' ', 26);
230 for (i = 0; i < nrows; i++)
231 {
232 for (j = 0; j < hpasses * vpasses * subpasses; j++)
233 {
234 int physrow;
235 stp_weave_parameters_by_row(v, i+first_line, j, &w);
236 physrow = w.logicalpassstart + physsep * w.jet;
237
238 errcodes[0] = (w.pass < 0 ? (errors[0]++, 'A') : ' ');
239 errcodes[1] = (w.jet < 0 || w.jet > physjets - 1 ?
240 (errors[1]++, 'B') : ' ');
241 errcodes[2] = (w.physpassstart > w.row ? (errors[2]++, 'C') : ' ');
242 errcodes[3] = (w.physpassend < w.row ? (errors[3]++, 'D') : ' ');
243 #if 0
244 errcodes[4] = (w.physpassend == w.row && lastpass + 1 != w.pass ?
245 (errors[4]++, 'E') : ' ');
246 #endif
247 errcodes[5] = (w.pass >= 0 && w.pass < nrows &&
248 passstarts[w.pass] != -1 &&
249 passstarts[w.pass] != w.physpassstart ?
250 (errors[5]++, 'F') : ' ');
251 errcodes[6] = (w.pass >= 0 && w.pass < nrows &&
252 passends[w.pass] != -1 &&
253 passends[w.pass] != w.physpassend ?
254 (errors[6]++, 'G') : ' ');
255 errcodes[7] = (w.row != physrow ? (errors[7]++, 'H') : ' ');
256 errcodes[8] = (w.missingstartrows < 0 ||
257 w.missingstartrows > physjets - 1 ?
258 (errors[8]++, 'I') : ' ');
259 errcodes[9] = (w.physpassstart < 0 ? (errors[9]++, 'J') : ' ');
260 errcodes[10] = (w.missingstartrows > w.jet ?
261 (errors[10]++, 'K') : ' ');
262 errcodes[11] = (w.pass >= 0 && w.pass < nrows &&
263 physpassstuff[w.pass] >= 0 &&
264 physpassstuff[w.pass] != j ?
265 (errors[11]++, 'L') : ' ');
266 errcodes[12] = (w.pass >= 0 && w.pass < nrows && w.jet >= 0 &&
267 w.jet < physjets &&
268 rowdetail[w.pass * physjets + w.jet] == 1 ?
269 (errors[12]++, 'M') : ' ');
270 errcodes[13] = (current_slot[w.pass % vmod] != -1 &&
271 current_slot[w.pass % vmod] != w.pass ?
272 (errors[13]++, 'N') : ' ');
273 errcodes[14] = (w.physpassstart == w.row &&
274 w.jet != w.missingstartrows ?
275 (errors[14]++, 'O') : ' ');
276 errcodes[15] = ((w.logicalpassstart < 0) ||
277 (w.logicalpassstart + physsep * (physjets - 1) >=
278 phys_lines) ?
279 (errors[15]++, 'P') : ' ');
280 errcodes[16] = '\0';
281
282 if (!quiet)
283 {
284 printf("%15s%5d %5d %5d %10d %10d %10d %10d\n",
285 errcodes, w.row, w.pass, w.jet, w.missingstartrows,
286 w.logicalpassstart, w.physpassstart, w.physpassend);
287 fflush(stdout);
288 }
289 if (w.pass >= 0 && w.pass < (nrows + physsep))
290 {
291 if (w.physpassend == w.row)
292 {
293 lastpass = w.pass;
294 passends[w.pass] = -2;
295 current_slot[w.pass % vmod] = -1;
296 }
297 else
298 {
299 passends[w.pass] = w.physpassend;
300 current_slot[w.pass % vmod] = w.pass;
301 }
302 passstarts[w.pass] = w.physpassstart;
303 logpassstarts[w.pass] = w.logicalpassstart;
304 if (w.jet >= 0 && w.jet < physjets)
305 rowdetail[w.pass * physjets + w.jet] = 1;
306 if (physpassstuff[w.pass] == -1)
307 physpassstuff[w.pass] = j;
308 if (w.pass > newestpass)
309 newestpass = w.pass;
310 }
311 }
312 }
313 if (!quiet)
314 printf("Unterminated passes:\n");
315 for (i = 0; i <= newestpass; i++)
316 if (passends[i] >= -1 && passends[i] < nrows && logpassstarts[i] != INT_MIN)
317 {
318 if (!quiet)
319 printf("%d %d\n", i, passends[i]);
320 errors[16]++;
321 }
322 if (!quiet)
323 {
324 printf("Last terminated pass: %d\n", lastpass);
325 printf("Pass starts:\n");
326 }
327 last_good_pass = 0;
328 errcodes[3] = '\0';
329 for (i = 0; i <= newestpass; i++)
330 {
331 if (logpassstarts[i] != INT_MIN)
332 {
333 if (i > 0)
334 errcodes[0] = logpassstarts[i] < logpassstarts[last_good_pass] ?
335 (errors[17]++, 'Q') : ' ';
336 errcodes[1] = passes_flushed[i] ? (errors[18]++, 'R') : ' ';
337 errcodes[2] = ' ';
338 if (!quiet)
339 printf("%s %d %d\n", errcodes, i, logpassstarts[i]);
340 last_good_pass = i;
341 }
342 else if (!quiet)
343 {
344 errcodes[0] = ' ';
345 errcodes[1] = ' ';
346 errcodes[2] = '*';
347 printf("%s %d\n", errcodes, i);
348 }
349 }
350 for (i = 0; i < 26; i++)
351 total_errors += errors[i];
352 stp_free(rowdetail);
353 stp_free(physpassstuff);
354 stp_free(current_slot);
355 stp_free(passcounts);
356 stp_free(passends);
357 stp_free(logpassstarts);
358 stp_free(passstarts);
359 stp_free(passes_flushed);
360 if (!quiet || (quiet == 1 && total_errors > 0))
361 printf("%d total error%s\n", total_errors, total_errors == 1 ? "" : "s");
362 stp_vars_destroy(v);
363 return total_errors;
364 }
365
366 static int
367 run_weavetest_from_stdin(void)
368 {
369 int nrows;
370 int physjets;
371 int physsep;
372 int hpasses, vpasses, subpasses;
373 int first_line, phys_lines;
374 int color_jet_arrangement;
375 int strategy;
376 int previous_strategy = -1;
377 int previous_jets = -1;
378 int previous_separation = -1;
379 int total_cases = 0;
380 int failures = 0;
381 char linebuf[4096];
382 const char *spinner = "/-\\|";
383 int rotor = 0;
384 int do_spinner = isatty(fileno(stdout));
385 while (fgets(linebuf, 4096, stdin))
386 {
387 int retval;
388 (void) sscanf(linebuf, "%d%d%d%d%d%d%d%d%d%d", &physjets, &physsep,
389 &hpasses, &vpasses, &subpasses, &nrows, &first_line,
390 &phys_lines, &color_jet_arrangement, &strategy);
391 fflush(stdout);
392 if (vpasses * subpasses > physjets)
393 continue;
394 retval = run_one_weavetest(physjets, physsep, hpasses, vpasses,
395 subpasses, nrows, first_line, phys_lines,
396 color_jet_arrangement, strategy, 2);
397 if (getenv("QUIET"))
398 {
399 /* Assume that we're running within run-weavetest, and */
400 /* print out the heartbeat */
401
402 if (previous_strategy != strategy)
403 {
404 printf("%s%d:", previous_strategy == -1 ? "" : "\n", strategy);
405 previous_jets = -1;
406 previous_separation = -1;
407 }
408 if (previous_jets != physjets)
409 {
410 printf("%d", physjets);
411 previous_separation = -1;
412 }
413 if (previous_separation != physsep)
414 printf(".");
415 if (do_spinner)
416 {
417 putchar((int) (spinner[rotor++]));
418 putchar((int) '\b');
419 rotor &= 3;
420 }
421 previous_strategy = strategy;
422 previous_jets = physjets;
423 previous_separation = physsep;
424 }
425 if (!getenv("QUIET") || retval)
426 {
427 printf("%d %d %d %d %d %d %d %d %d %d ", physjets, physsep,
428 hpasses, vpasses, subpasses, nrows, first_line,
429 phys_lines, color_jet_arrangement, strategy);
430 if (retval)
431 printf("%d total error%s", retval, retval == 1 ? "" : "s");
432 putc('\n', stdout);
433 }
434
435 total_cases++;
436 if (retval)
437 failures++;
438 fflush(stdout);
439 }
440 printf("%sTotal cases: %d, failures: %d\n",
441 (getenv("QUIET") ? "\n" : ""), total_cases, failures);
442 return (failures ? 1 : 0);
443 }
444
445 static int
446 run_weavetest_from_cmdline(int argc, char **argv)
447 {
448 if (argc != 11)
449 {
450 fprintf(stderr, "Usage: %s jets separation hpasses vpasses subpasses rows start end arrangement strategy\n",
451 argv[0]);
452 return 2;
453 }
454 else
455 {
456 int quiet = 0;
457 int physjets = atoi(argv[1]);
458 int physsep = atoi(argv[2]);
459 int hpasses = atoi(argv[3]);
460 int vpasses = atoi(argv[4]);
461 int subpasses = atoi(argv[5]);
462 int nrows = atoi(argv[6]);
463 int first_line = atoi(argv[7]);
464 int phys_lines = atoi(argv[8]);
465 int color_jet_arrangement = atoi(argv[9]);
466 int strategy = atoi(argv[10]);
467 int status;
468 if (getenv("QUIET"))
469 quiet = 2;
470 status = run_one_weavetest(physjets, physsep, hpasses, vpasses,
471 subpasses, nrows, first_line, phys_lines,
472 color_jet_arrangement, strategy, quiet);
473 if (status)
474 return 1;
475 else
476 return 0;
477 }
478 }
479
480 int
481 main(int argc, char **argv)
482 {
483 stp_init();
484
485 if (argc == 1)
486 return run_weavetest_from_stdin();
487 else
488 return run_weavetest_from_cmdline(argc, argv);
489 }