static int do_print(void) { int status = 0; stp_vars_t *v; const stp_printer_t *the_printer; int left, right, top, bottom; int x, y; int width, height; int retval; stp_parameter_list_t params; int count; int i; char tmp[32]; initialize_global_parameters(); global_vars = stp_vars_create(); stp_set_outfunc(global_vars, writefunc); stp_set_errfunc(global_vars, writefunc); stp_set_outdata(global_vars, stdout); stp_set_errdata(global_vars, stderr); setlocale(LC_ALL, "C"); retval = yyparse(); setlocale(LC_ALL, ""); if (retval) return retval + 1; if (!global_did_something) return 1; v = stp_vars_create(); the_printer = stp_get_printer_by_driver(global_printer); if (!the_printer) { int j; fprintf(stderr, "Unknown printer %s\nValid printers are:\n", global_printer); for (j = 0; j < stp_printer_model_count(); j++) { the_printer = stp_get_printer_by_index(j); fprintf(stderr, "%-16s%s\n", stp_printer_get_driver(the_printer), stp_printer_get_long_name(the_printer)); } return 2; } bytes_written = 0; if (global_output) { if (strcmp(global_output, "-") == 0) output = stdout; else if (strcmp(global_output, "") == 0) output = NULL; else if (global_output[0] == '|') { close_output(); write_to_process = 1; output = popen(global_output+1, "w"); if (! output) { fprintf(stderr, "popen '%s' failed: %s\n", global_output, strerror(errno)); output = NULL; } free(global_output); global_output = NULL; } else { close_output(); output = fopen(global_output, "wb"); if (! output) { fprintf(stderr, "Create %s failed: %s\n", global_output, strerror(errno)); output = NULL; } free(global_output); global_output = NULL; } } stp_set_printer_defaults(v, the_printer); stp_set_outfunc(v, writefunc); stp_set_errfunc(v, writefunc); stp_set_outdata(v, output); stp_set_errdata(v, stderr); stp_set_string_parameter(v, "InputImageType", global_image_type); sprintf(tmp, "%d", global_bit_depth); stp_set_string_parameter(v, "ChannelBitDepth", tmp); if (strcmp(global_image_type, "Raw") == 0) { sprintf(tmp, "%d", global_channel_depth); stp_set_string_parameter(v, "RawChannels", tmp); } stp_set_float_parameter(v, "Density", global_density); stp_set_string_parameter(v, "Quality", "None"); stp_set_string_parameter(v, "ImageType", "None"); params = stp_get_parameter_list(v); count = stp_parameter_list_count(params); for (i = 0; i < count; i++) { const stp_parameter_t *p = stp_parameter_list_param(params, i); if (p->p_type == STP_PARAMETER_TYPE_STRING_LIST) { const char *val = stp_get_string_parameter(global_vars, p->name); if (val && strlen(val) > 0) { stp_set_string_parameter(v, p->name, val); } } else if (p->p_type == STP_PARAMETER_TYPE_INT && stp_check_int_parameter(global_vars, p->name, STP_PARAMETER_ACTIVE)) { int val = stp_get_int_parameter(global_vars, p->name); stp_set_int_parameter(v, p->name, val); } else if (p->p_type == STP_PARAMETER_TYPE_BOOLEAN && stp_check_boolean_parameter(global_vars, p->name, STP_PARAMETER_ACTIVE)) { int val = stp_get_boolean_parameter(global_vars, p->name); stp_set_boolean_parameter(v, p->name, val); } else if (p->p_type == STP_PARAMETER_TYPE_CURVE && stp_check_curve_parameter(global_vars, p->name, STP_PARAMETER_ACTIVE)) { const stp_curve_t *val = stp_get_curve_parameter(global_vars, p->name); stp_set_curve_parameter(v, p->name, val); } else if (p->p_type == STP_PARAMETER_TYPE_DOUBLE && stp_check_float_parameter(global_vars, p->name, STP_PARAMETER_ACTIVE)) { double val = stp_get_float_parameter(global_vars, p->name); stp_set_float_parameter(v, p->name, val); } } stp_set_page_width(v, stp_get_page_width(global_vars)); stp_set_page_height(v, stp_get_page_height(global_vars)); stp_parameter_list_destroy(params); if (stp_check_string_parameter(v, "PageSize", STP_PARAMETER_ACTIVE) && !strcmp(stp_get_string_parameter(v, "PageSize"), "Auto")) { stp_parameter_t desc; stp_describe_parameter(v, "PageSize", &desc); if (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST) stp_set_string_parameter(v, "PageSize", desc.deflt.str); stp_parameter_description_destroy(&desc); } stp_set_printer_defaults_soft(v, the_printer); stp_get_imageable_area(v, &left, &right, &bottom, &top); stp_describe_resolution(v, &x, &y); if (x < 0) x = 300; if (y < 0) y = 300; width = right - left; height = bottom - top; switch (global_size_mode) { case SIZE_PT: top += (int) (global_xtop + .5); left += (int) (global_xleft + .5); width = (int) (global_hsize + .5); height = (int) (global_vsize + .5); break; case SIZE_IN: top += (int) ((global_xtop * 72) + .5); left += (int) ((global_xleft * 72) + .5); width = (int) ((global_hsize * 72) + .5); height = (int) ((global_vsize * 72) + .5); break; case SIZE_MM: top += (int) ((global_xtop * 72 / 25.4) + .5); left += (int) ((global_xleft * 72 / 25.4) + .5); width = (int) ((global_hsize * 72 / 25.4) + .5); height = (int) ((global_vsize * 72 / 25.4) + .5); break; case SIZE_RELATIVE: default: top += height * global_xtop; left += width * global_xleft; width *= global_hsize; height *= global_vsize; break; } stp_set_width(v, width); stp_set_height(v, height); #if 0 width = (width / global_steps) * global_steps; height = (height / global_n_testpatterns) * global_n_testpatterns; #endif if (global_steps > width) global_steps = width; global_printer_width = width * x / 72; global_printer_height = height * y / 72; global_band_height = global_printer_height / global_n_testpatterns; if (global_band_height == 0) global_band_height = 1; stp_set_left(v, left); stp_set_top(v, top); stp_merge_printvars(v, stp_printer_get_defaults(the_printer)); if (stp_verify(v)) { bytes_written = 0; if (start_job) { stp_start_job(v, &theImage); start_job = 0; } if (stp_print(v, &theImage) != 1) { if (!global_quiet) fputs("FAILED", stderr); failures++; status = 2; if (global_halt_on_error) return status; } else if (bytes_written == 0) { if (!global_quiet) fputs("FAILED: No output", stderr); failures++; status = 2; if (global_halt_on_error) return status; } else passes++; if (end_job) { stp_end_job(v, &theImage); end_job = 0; } } else { if (! global_fail_verify_ok) { if (!global_quiet) fputs("FAILED", stderr); failures++; status = 2; if (global_halt_on_error) return status; } else { if (!global_quiet) fputs("(skipped)", stderr); skipped++; } } if (!global_quiet) fputc('\n', stderr); stp_vars_destroy(v); stp_free(static_testpatterns); static_testpatterns = NULL; return status; }
struct stp_vars *guten_prepare_printer(const stp_printer_t *printer) { const struct stp_vars *gvars_defaults; struct stp_vars *gvars; gvars_defaults = stp_printer_get_defaults(printer); gvars = stp_vars_create_copy(gvars_defaults); stp_set_outdata(gvars, stdout); stp_set_outfunc(gvars, gfunc_print); stp_set_errdata(gvars, stderr); stp_set_errfunc(gvars, gfunc_error); stp_parameter_list_t *list = stp_get_parameter_list(gvars); size_t count = stp_parameter_list_count(list); int i; for(i=0; i<count; i++) { const stp_parameter_t *par = stp_parameter_list_param(list, i); stp_parameter_t pardesc; stp_describe_parameter(gvars, par->name, &pardesc); if(pardesc.is_mandatory) { switch(pardesc.p_type) { case STP_PARAMETER_TYPE_STRING_LIST: { stp_set_string_parameter(gvars, pardesc.name, pardesc.deflt.str); break; } case STP_PARAMETER_TYPE_INT: { stp_set_int_parameter(gvars, pardesc.name, pardesc.deflt.integer); break; } case STP_PARAMETER_TYPE_BOOLEAN: { stp_set_boolean_parameter(gvars, pardesc.name, pardesc.deflt.boolean); break; } case STP_PARAMETER_TYPE_DOUBLE: { stp_set_float_parameter(gvars, pardesc.name, pardesc.deflt.dbl); break; } case STP_PARAMETER_TYPE_CURVE: { stp_set_curve_parameter(gvars, pardesc.name, pardesc.deflt.curve); break; } case STP_PARAMETER_TYPE_FILE: { stp_set_file_parameter(gvars, pardesc.name, pardesc.deflt.str); break; } /* case STP_PARAMETER_TYPE_RAW: { stp_set_raw_parameter(gvars, pardesc.name, pardesc.deflt.str); break; } */ case STP_PARAMETER_TYPE_ARRAY: { stp_set_array_parameter(gvars, pardesc.name, pardesc.deflt.array); break; } case STP_PARAMETER_TYPE_DIMENSION: { stp_set_dimension_parameter(gvars, pardesc.name, pardesc.deflt.dimension); break; } default: {} } } } stp_parameter_list_destroy(list); return gvars; }
static int run_one_weavetest(int physjets, int physsep, int hpasses, int vpasses, int subpasses, int nrows, int first_line, int phys_lines, int color_jet_arrangement, int strategy, int quiet) { int i; int j; stp_weave_t w; stp_vars_t *v; int errors[26]; char errcodes[26]; int total_errors = 0; int lastpass = -1; int newestpass = -1; int *passstarts; int *logpassstarts; int *passends; int *passcounts; signed char *physpassstuff; signed char *rowdetail; int *current_slot; int vmod; int head_offset[8]; int last_good_pass; v = stp_vars_create(); stp_set_outfunc(v, writefunc); stp_set_errfunc(v, writefunc); stp_set_outdata(v, stdout); stp_set_errdata(v, stdout); memset(errors, 0, sizeof(int) * 26); #if 0 if (physjets < hpasses * vpasses * subpasses) { return 0; } #endif for(i=0; i<8; i++) head_offset[i] = 0; switch (color_jet_arrangement) { case 1: /* C80-type */ head_offset[0] = (physjets+1)*physsep; head_offset[1] = (physjets+1)*physsep; head_offset[2] = 2*(physjets+1)*physsep; phys_lines += 2*(physjets+1)*physsep; break; case 2: /* Offset by 1 (f360) */ if (physsep % 2 == 0) { head_offset[1] = physsep / 2; head_offset[2] = physsep / 2; phys_lines += physsep / 2; } break; case 3: /* Offset by 1 or 2 (cx3650-type) */ if (physsep % 3 == 0) { head_offset[1] = physsep * 2 / 3; head_offset[2] = physsep / 3; phys_lines += physsep * 2 / 3; } break; default: /* Normal */ break; } stp_initialize_weave(v, physjets, physsep, hpasses, vpasses, subpasses, 7, 1, 128, nrows, first_line, phys_lines, head_offset, strategy, flush_pass, stp_fill_tiff, stp_pack_tiff, stp_compute_tiff_linewidth); passstarts = stp_malloc(sizeof(int) * (nrows + physsep)); logpassstarts = stp_malloc(sizeof(int) * (nrows + physsep)); passends = stp_malloc(sizeof(int) * (nrows + physsep)); passcounts = stp_malloc(sizeof(int) * (nrows + physsep)); passes_flushed = stp_malloc(sizeof(int) * (nrows + physsep)); vmod = 2 * physsep * hpasses * vpasses * subpasses; if (vmod == 0) vmod = 1; current_slot = stp_malloc(sizeof(int) * vmod); physpassstuff = stp_malloc((nrows + physsep)); rowdetail = stp_malloc((nrows + physsep) * physjets); memset(rowdetail, 0, (nrows + physsep) * physjets); memset(physpassstuff, -1, (nrows + physsep)); memset(current_slot, 0, (sizeof(int) * vmod)); if (!quiet) { print_header(); printf("%15s %5s %5s %5s %10s %10s %10s %10s\n", "", "row", "pass", "jet", "missing", "logical", "physstart", "physend"); } for (i = 0; i < vmod; i++) current_slot[i] = -1; for (i = 0; i < (nrows + physsep); i++) { passes_flushed[i] = 0; logpassstarts[i] = INT_MIN; passstarts[i] = -1; passends[i] = -1; } memset(errcodes, ' ', 26); for (i = 0; i < nrows; i++) { for (j = 0; j < hpasses * vpasses * subpasses; j++) { int physrow; stp_weave_parameters_by_row(v, i+first_line, j, &w); physrow = w.logicalpassstart + physsep * w.jet; errcodes[0] = (w.pass < 0 ? (errors[0]++, 'A') : ' '); errcodes[1] = (w.jet < 0 || w.jet > physjets - 1 ? (errors[1]++, 'B') : ' '); errcodes[2] = (w.physpassstart > w.row ? (errors[2]++, 'C') : ' '); errcodes[3] = (w.physpassend < w.row ? (errors[3]++, 'D') : ' '); #if 0 errcodes[4] = (w.physpassend == w.row && lastpass + 1 != w.pass ? (errors[4]++, 'E') : ' '); #endif errcodes[5] = (w.pass >= 0 && w.pass < nrows && passstarts[w.pass] != -1 && passstarts[w.pass] != w.physpassstart ? (errors[5]++, 'F') : ' '); errcodes[6] = (w.pass >= 0 && w.pass < nrows && passends[w.pass] != -1 && passends[w.pass] != w.physpassend ? (errors[6]++, 'G') : ' '); errcodes[7] = (w.row != physrow ? (errors[7]++, 'H') : ' '); errcodes[8] = (w.missingstartrows < 0 || w.missingstartrows > physjets - 1 ? (errors[8]++, 'I') : ' '); errcodes[9] = (w.physpassstart < 0 ? (errors[9]++, 'J') : ' '); errcodes[10] = (w.missingstartrows > w.jet ? (errors[10]++, 'K') : ' '); errcodes[11] = (w.pass >= 0 && w.pass < nrows && physpassstuff[w.pass] >= 0 && physpassstuff[w.pass] != j ? (errors[11]++, 'L') : ' '); errcodes[12] = (w.pass >= 0 && w.pass < nrows && w.jet >= 0 && w.jet < physjets && rowdetail[w.pass * physjets + w.jet] == 1 ? (errors[12]++, 'M') : ' '); errcodes[13] = (current_slot[w.pass % vmod] != -1 && current_slot[w.pass % vmod] != w.pass ? (errors[13]++, 'N') : ' '); errcodes[14] = (w.physpassstart == w.row && w.jet != w.missingstartrows ? (errors[14]++, 'O') : ' '); errcodes[15] = ((w.logicalpassstart < 0) || (w.logicalpassstart + physsep * (physjets - 1) >= phys_lines) ? (errors[15]++, 'P') : ' '); errcodes[16] = '\0'; if (!quiet) { printf("%15s%5d %5d %5d %10d %10d %10d %10d\n", errcodes, w.row, w.pass, w.jet, w.missingstartrows, w.logicalpassstart, w.physpassstart, w.physpassend); fflush(stdout); } if (w.pass >= 0 && w.pass < (nrows + physsep)) { if (w.physpassend == w.row) { lastpass = w.pass; passends[w.pass] = -2; current_slot[w.pass % vmod] = -1; } else { passends[w.pass] = w.physpassend; current_slot[w.pass % vmod] = w.pass; } passstarts[w.pass] = w.physpassstart; logpassstarts[w.pass] = w.logicalpassstart; if (w.jet >= 0 && w.jet < physjets) rowdetail[w.pass * physjets + w.jet] = 1; if (physpassstuff[w.pass] == -1) physpassstuff[w.pass] = j; if (w.pass > newestpass) newestpass = w.pass; } } } if (!quiet) printf("Unterminated passes:\n"); for (i = 0; i <= newestpass; i++) if (passends[i] >= -1 && passends[i] < nrows && logpassstarts[i] != INT_MIN) { if (!quiet) printf("%d %d\n", i, passends[i]); errors[16]++; } if (!quiet) { printf("Last terminated pass: %d\n", lastpass); printf("Pass starts:\n"); } last_good_pass = 0; errcodes[3] = '\0'; for (i = 0; i <= newestpass; i++) { if (logpassstarts[i] != INT_MIN) { if (i > 0) errcodes[0] = logpassstarts[i] < logpassstarts[last_good_pass] ? (errors[17]++, 'Q') : ' '; errcodes[1] = passes_flushed[i] ? (errors[18]++, 'R') : ' '; errcodes[2] = ' '; if (!quiet) printf("%s %d %d\n", errcodes, i, logpassstarts[i]); last_good_pass = i; } else if (!quiet) { errcodes[0] = ' '; errcodes[1] = ' '; errcodes[2] = '*'; printf("%s %d\n", errcodes, i); } } for (i = 0; i < 26; i++) total_errors += errors[i]; stp_free(rowdetail); stp_free(physpassstuff); stp_free(current_slot); stp_free(passcounts); stp_free(passends); stp_free(logpassstarts); stp_free(passstarts); stp_free(passes_flushed); if (!quiet || (quiet == 1 && total_errors > 0)) printf("%d total error%s\n", total_errors, total_errors == 1 ? "" : "s"); stp_vars_destroy(v); return total_errors; }