summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-01-13 13:27:34 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2010-01-13 13:27:34 -0800
commit6e7a7fca8268b4c65e22122f8987da2f0e747754 (patch)
tree0b0d4df61a7ea12f224ae27d534eebe1ae544813
parent66ff8cb8a56396ab8b5958b3411a36228010e1fb (diff)
downloadpesconvert-6e7a7fca8268b4c65e22122f8987da2f0e747754.tar.gz
Fix some trivial scaling problems
I used to scale everything to be square. That was fine for testing, but not so great for actual use. This makes it all look better when the input isn't square. It also scales the width of the line properly. And in honor of this actually being useful (it's installed on Tove's machine now), let's sign off on it all. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--cairo.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/cairo.c b/cairo.c
index 01b4441..bd4d3d3 100644
--- a/cairo.c
+++ b/cairo.c
@@ -2,24 +2,26 @@
#include "pes.h"
-#define X(stitch) ((double)((stitch)->x - pes->min_x) * outw / width)
-#define Y(stitch) ((double)((stitch)->y - pes->min_y) * outh / height)
+#define X(stitch) (((stitch)->x - pes->min_x) * scale)
+#define Y(stitch) (((stitch)->y - pes->min_y) * scale)
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 = width, outh = height;
+ int width = pes->max_x - pes->min_x, outw;
+ int height = pes->max_y - pes->min_y, outh;
+ double scale = 1.0;
struct pes_block *block;
cairo_surface_t *surface;
cairo_t *cr;
if (size > 0) {
- outw = size;
- outh = size;
+ int maxd = width > height ? width : height;
+ scale = (double) size / maxd;
}
+ outw = width * scale;
+ outh = height * scale;
- surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, outw, outh);
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, outw+1, outh+1);
cr = cairo_create (surface);
block = pes->blocks;
@@ -35,7 +37,7 @@ void output_cairo(struct pes *pes, const char *filename, int size)
++stitch;
cairo_line_to(cr, X(stitch), Y(stitch));
}
- cairo_set_line_width (cr, 0.2);
+ cairo_set_line_width(cr, scale);
cairo_stroke(cr);
block = block->next;