summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-01-13 12:49:30 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2010-01-13 12:49:30 -0800
commite7ffff71f7e23d5bb6cf2cf4ed5be5ed87eccbc8 (patch)
tree0723f13596e794e95aa68985e4806fa337f5c023
parent4c3c754d9ea5b3c66e58a884cc17c75fbafee38b (diff)
downloadpesconvert-e7ffff71f7e23d5bb6cf2cf4ed5be5ed87eccbc8.tar.gz
Teach pesconvert a few command line options
-rw-r--r--cairo.c11
-rw-r--r--main.c42
-rw-r--r--pes.h2
3 files changed, 46 insertions, 9 deletions
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 @@ void output_cairo(struct pes *pes)
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 @@ 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], &region))
- 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(&region, &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, &region))
+ die("Unable to read file %s (%s)\n", arg, strerror(errno));
+
+ if (parse_pes(&region, &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 @@ 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 */