[gimp] app: don't use PROJ_ROUND() for pixel-adjusting canvas item drawing
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: don't use PROJ_ROUND() for pixel-adjusting canvas item drawing
- Date: Mon, 4 Oct 2010 19:48:47 +0000 (UTC)
commit b74811324ad42bcf68c05f007bf070ff8903592e
Author: Michael Natterer <mitch gimp org>
Date: Mon Oct 4 21:44:05 2010 +0200
app: don't use PROJ_ROUND() for pixel-adjusting canvas item drawing
When PROJ_ROUND()ing e.g. 3.8, it ends up at 4, then we added the 0.5
offset to draw a nice cairo line in the middle of the pixel,
effectively drawing a line that's meant to be at 3.8 at 4.5. Instead,
we now use floor(x)+0.5 now which snaps the above example to 3.5.
Also, calculate arcs like we calculate rectangles (transform the arc's
bounding box and pixel-align that, then recalculate the center), so
arcs properly align with rectangles.
app/display/gimpcanvasarc.c | 12 ++++++++----
app/display/gimpcanvascorner.c | 8 ++++----
app/display/gimpcanvashandle.c | 4 ++--
app/display/gimpcanvasline.c | 8 ++++----
app/display/gimpcanvaspolygon.c | 4 ++--
app/display/gimpcanvasrectangle.c | 8 ++++----
6 files changed, 24 insertions(+), 20 deletions(-)
---
diff --git a/app/display/gimpcanvasarc.c b/app/display/gimpcanvasarc.c
index 7650e01..7aaabcd 100644
--- a/app/display/gimpcanvasarc.c
+++ b/app/display/gimpcanvasarc.c
@@ -236,10 +236,6 @@ gimp_canvas_arc_transform (GimpCanvasItem *item,
gdouble x2, y2;
gimp_display_shell_transform_xy_f (shell,
- private->center_x,
- private->center_y,
- center_x, center_y);
- gimp_display_shell_transform_xy_f (shell,
private->center_x - private->radius_x,
private->center_y - private->radius_y,
&x1, &y1);
@@ -248,6 +244,14 @@ gimp_canvas_arc_transform (GimpCanvasItem *item,
private->center_y + private->radius_y,
&x2, &y2);
+ x1 = floor (x1);
+ y1 = floor (y1);
+ x2 = ceil (x2);
+ y2 = ceil (y2);
+
+ *center_x = (x1 + x2) / 2.0;
+ *center_y = (y1 + y2) / 2.0;
+
*radius_x = (x2 - x1) / 2.0;
*radius_y = (y2 - y1) / 2.0;
diff --git a/app/display/gimpcanvascorner.c b/app/display/gimpcanvascorner.c
index 5e49234..db6f92a 100644
--- a/app/display/gimpcanvascorner.c
+++ b/app/display/gimpcanvascorner.c
@@ -267,10 +267,10 @@ gimp_canvas_corner_transform (GimpCanvasItem *item,
rw -= rx;
rh -= ry;
- rx = PROJ_ROUND (rx) + 0.5;
- ry = PROJ_ROUND (ry) + 0.5;
- rw = PROJ_ROUND (rw) - 1.0;
- rh = PROJ_ROUND (rh) - 1.0;
+ rx = floor (rx) + 0.5;
+ ry = floor (ry) + 0.5;
+ rw = ceil (rw) - 1.0;
+ rh = ceil (rh) - 1.0;
top_and_bottom_handle_x_offset = (rw - private->corner_width) / 2;
left_and_right_handle_y_offset = (rh - private->corner_height) / 2;
diff --git a/app/display/gimpcanvashandle.c b/app/display/gimpcanvashandle.c
index fbe7a37..49667b7 100644
--- a/app/display/gimpcanvashandle.c
+++ b/app/display/gimpcanvashandle.c
@@ -406,8 +406,8 @@ gimp_canvas_handle_transform (GimpCanvasItem *item,
break;
}
- *x = PROJ_ROUND (*x) + 0.5;
- *y = PROJ_ROUND (*y) + 0.5;
+ *x = floor (*x) + 0.5;
+ *y = floor (*y) + 0.5;
}
static void
diff --git a/app/display/gimpcanvasline.c b/app/display/gimpcanvasline.c
index a60c953..325d763 100644
--- a/app/display/gimpcanvasline.c
+++ b/app/display/gimpcanvasline.c
@@ -200,10 +200,10 @@ gimp_canvas_line_transform (GimpCanvasItem *item,
private->x2, private->y2,
x2, y2);
- *x1 = PROJ_ROUND (*x1) + 0.5;
- *y1 = PROJ_ROUND (*y1) + 0.5;
- *x2 = PROJ_ROUND (*x2) + 0.5;
- *y2 = PROJ_ROUND (*y2) + 0.5;
+ *x1 = floor (*x1) + 0.5;
+ *y1 = floor (*y1) + 0.5;
+ *x2 = floor (*x2) + 0.5;
+ *y2 = floor (*y2) + 0.5;
}
static void
diff --git a/app/display/gimpcanvaspolygon.c b/app/display/gimpcanvaspolygon.c
index 282d51b..019d71b 100644
--- a/app/display/gimpcanvaspolygon.c
+++ b/app/display/gimpcanvaspolygon.c
@@ -213,8 +213,8 @@ gimp_canvas_polygon_transform (GimpCanvasItem *item,
&points[i].x,
&points[i].y);
- points[i].x = PROJ_ROUND (points[i].x) + 0.5;
- points[i].y = PROJ_ROUND (points[i].y) + 0.5;
+ points[i].x = floor (points[i].x) + 0.5;
+ points[i].y = floor (points[i].y) + 0.5;
}
}
diff --git a/app/display/gimpcanvasrectangle.c b/app/display/gimpcanvasrectangle.c
index 71202b7..872a5f4 100644
--- a/app/display/gimpcanvasrectangle.c
+++ b/app/display/gimpcanvasrectangle.c
@@ -232,10 +232,10 @@ gimp_canvas_rectangle_transform (GimpCanvasItem *item,
}
else
{
- *x = PROJ_ROUND (*x) + 0.5;
- *y = PROJ_ROUND (*y) + 0.5;
- *w = PROJ_ROUND (*w) - 1.0;
- *h = PROJ_ROUND (*h) - 1.0;
+ *x = floor (*x) + 0.5;
+ *y = floor (*y) + 0.5;
+ *w = ceil (*w) - 1.0;
+ *h = ceil (*h) - 1.0;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]