Teach pesconvert a few command line options
diff --git a/cairo.c b/cairo.c index 14c932a..01b4441 100644 --- a/cairo.c +++ b/cairo.c
@@ -5,15 +5,20 @@ #define X(stitch) ((double)((stitch)->x - pes->min_x) * outw / width) #define Y(stitch) ((double)((stitch)->y - pes->min_y) * outh / height) -void output_cairo(struct pes *pes) +void output_cairo(struct pes *pes, const char *filename, int size) { int width = pes->max_x - pes->min_x + 1; int height = pes->max_y - pes->min_y + 1; - int outw = 256, outh = 256; + int outw = width, outh = height; struct pes_block *block; cairo_surface_t *surface; cairo_t *cr; + if (size > 0) { + outw = size; + outh = size; + } + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, outw, outh); cr = cairo_create (surface); @@ -35,5 +40,5 @@ block = block->next; } - cairo_surface_write_to_png(surface, "out.png"); + cairo_surface_write_to_png(surface, filename); }
diff --git a/main.c b/main.c index e51401d..e9731da 100644 --- a/main.c +++ b/main.c
@@ -23,6 +23,8 @@ int main(int argc, char **argv) { + int i, outputsize = -1; + const char *output = NULL; struct region region; struct pes pes = { .min_x = 65535, .max_x = -65535, @@ -32,13 +34,43 @@ .listp = &pes.blocks, }; - if (read_path(argv[1], ®ion)) - die("Unable to read file %s (%s)\n", argv[1]?argv[1]:"<stdin>", strerror(errno)); + for (i = 1; i < argc; i++) { + const char *arg = argv[i]; - if (parse_pes(®ion, &pes) < 0) - die("Unable to parse PES file\n"); + if (*arg == '-') { + switch (arg[1]) { + case 's': + outputsize = atoi(argv[i+1]); + i++; + continue; + } + die("Unknown argument '%s'\n", arg); + } - output_cairo(&pes); + if (!pes.blocks) { + if (read_path(arg, ®ion)) + die("Unable to read file %s (%s)\n", arg, strerror(errno)); + + if (parse_pes(®ion, &pes) < 0) + die("Unable to parse PES file\n"); + continue; + } + + if (!output) { + output = arg; + continue; + } + + die("Too many arguments (%s)\n", arg); + } + + if (!pes.blocks) + die("Need an input PES file\n"); + + if (!output) + die("Need a png output file name\n"); + + output_cairo(&pes, output, outputsize); return 0; }
diff --git a/pes.h b/pes.h index 4656d41..1030475 100644 --- a/pes.h +++ b/pes.h
@@ -36,6 +36,6 @@ /* Output */ void output_svg(struct pes *pes); void output_png(struct pes *pes); -void output_cairo(struct pes *pes); +void output_cairo(struct pes *pes, const char *filename, int size); #endif /* PES_H */