diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-01-13 12:49:30 -0800 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-01-13 12:49:30 -0800 |
commit | e7ffff71f7e23d5bb6cf2cf4ed5be5ed87eccbc8 (patch) | |
tree | 0723f13596e794e95aa68985e4806fa337f5c023 | |
parent | 4c3c754d9ea5b3c66e58a884cc17c75fbafee38b (diff) | |
download | pesconvert-e7ffff71f7e23d5bb6cf2cf4ed5be5ed87eccbc8.tar.gz |
Teach pesconvert a few command line options
-rw-r--r-- | cairo.c | 11 | ||||
-rw-r--r-- | main.c | 42 | ||||
-rw-r--r-- | pes.h | 2 |
3 files changed, 46 insertions, 9 deletions
@@ -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 @@ void output_cairo(struct pes *pes) block = block->next; } - cairo_surface_write_to_png(surface, "out.png"); + cairo_surface_write_to_png(surface, filename); } @@ -23,6 +23,8 @@ static void die(const char *fmt, ...) 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 @@ int main(int argc, char **argv) .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; } @@ -36,6 +36,6 @@ int parse_pes(struct region *region, struct pes *pes); /* 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 */ |