This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 3a66b0d92c78955b31e8b825f3b2049ffdf3487a (commit) via 9176505d3276942f16192b028d57ca9571c81797 (commit) from 57c57c59cd6ce43a4df21a9309cdbb7cd5e1bf16 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/3a66b0d92c78955b31e8b825f3b2049ffdf34...
commit 3a66b0d92c78955b31e8b825f3b2049ffdf3487a Merge: 9176505 57c57c5 Author: Jiri BlueBear Dluhos jiri.bluebear.dluhos@gmail.com Date: Tue Dec 18 22:59:03 2012 +0100
Merge branch 'master' of ssh://repo.or.cz/srv/git/gfxprim
http://repo.or.cz/w/gfxprim.git/commit/9176505d3276942f16192b028d57ca9571c81...
commit 9176505d3276942f16192b028d57ca9571c81797 Author: Jiri BlueBear Dluhos jiri.bluebear.dluhos@gmail.com Date: Tue Dec 18 22:58:16 2012 +0100
First stab at analytic line clipping.
diff --git a/include/gfx/GP_LineClip.h b/include/gfx/GP_LineClip.h new file mode 100644 index 0000000..32ad6af --- /dev/null +++ b/include/gfx/GP_LineClip.h @@ -0,0 +1,31 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * Gfxprim is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * + * jiri.bluebear.dluhos@gmail.com * + * * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#ifndef GP_LINECLIP_H +#define GP_LINECLIP_H + +int GP_LineClip(int *px0, int *py0, int *px1, int *py1, int xmax, int ymax); + +#endif diff --git a/libs/gfx/GP_Line.gen.c.t b/libs/gfx/GP_Line.gen.c.t index edc5382..668d89f 100644 --- a/libs/gfx/GP_Line.gen.c.t +++ b/libs/gfx/GP_Line.gen.c.t @@ -36,6 +36,7 @@ #include "gfx/GP_VLine.h" #include "gfx/GP_HLine.h" #include "gfx/GP_Line.h" +#include "gfx/GP_LineClip.h"
/* * The classical Bresenham line drawing algorithm. @@ -48,6 +49,14 @@ void GP_Line_Raw_{{ ps.suffix }}(GP_Context *context, int x0, int y0, int x1, int y1, GP_Pixel pixval) { + if (!GP_LineClip(&x0, &y0, &x1, &y1, context->w - 1, context->h - 1)) + return; + + GP_ASSERT(x0 >= 0 && x0 <= (int) context->w-1); + GP_ASSERT(x1 >= 0 && x1 <= (int) context->w-1); + GP_ASSERT(y0 >= 0 && y0 <= (int) context->h-1); + GP_ASSERT(y1 >= 0 && y1 <= (int) context->h-1); + /* special cases: vertical line, horizontal line, single point */ if (x0 == x1) { if (y0 == y1) { @@ -93,10 +102,10 @@ void GP_Line_Raw_{{ ps.suffix }}(GP_Context *context, int x0, int y0, for (x = x0; x <= x1; x++) {
if (steep) - GP_PutPixel_Raw_Clipped_{{ ps.suffix }}(context, y, x, + GP_PutPixel_Raw_{{ ps.suffix }}(context, y, x, pixval); else - GP_PutPixel_Raw_Clipped_{{ ps.suffix }}(context, x, y, + GP_PutPixel_Raw_{{ ps.suffix }}(context, x, y, pixval);
error -= deltay; diff --git a/libs/gfx/GP_LineClip.c b/libs/gfx/GP_LineClip.c new file mode 100644 index 0000000..6a1f76e --- /dev/null +++ b/libs/gfx/GP_LineClip.c @@ -0,0 +1,129 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * Gfxprim is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * + * jiri.bluebear.dluhos@gmail.com * + * * + * Copyright (C) 2009-2010 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include "core/GP_Common.h" +#include "core/GP_Types.h" +#include "gfx/GP_LineClip.h" + +int GP_LineClip(int *px0, int *py0, int *px1, int *py1, int xmax, int ymax) +{ + float x0 = (float) *px0; + float y0 = (float) *py0; + float x1 = (float) *px1; + float y1 = (float) *py1; + + /* horizontal and vertical line are special cases */ + if (y0 == y1) { + + /* orient the line from left to right */ + if (x1 < x0) { + GP_SWAP(x0, x1); + GP_SWAP(y0, y1); + } + + /* check if it is not completely outside */ + if (x1 < 0 || x0 > xmax || y0 < 0 || y0 > ymax) + return 0; + + x0 = GP_MAX(x0, 0); + x1 = GP_MIN(x1, xmax); + goto give_result; + } + if (x0 == x1) { + + /* orient the line from top to down */ + if (x1 < x0) { + GP_SWAP(x0, x1); + GP_SWAP(y0, y1); + } + + /* check if it is not completely outside */ + if (y1 < 0 || y0 > ymax || x0 < 0 || x0 > xmax) + return 0; + + /* clip it to the valid range */ + y0 = GP_MAX(y0, 0); + y1 = GP_MIN(y1, ymax); + goto give_result; + } + + /* orient the line from left to right */ + if (x1 < x0) { + GP_SWAP(x0, x1); + GP_SWAP(y0, y1); + } + + if (x1 < 0 || x0 > xmax || (y0 < 0 && y1 < 0) || (y0 > ymax && y1 > ymax)) { + + /* the line lies completely outside the rectangle */ + return 0; + } + + float dx = (float)(x1 - x0); + float dy = (float)(y1 - y0); + float dyx = dy/dx; + float dxy = dx/dy; + + /* clip the line against the left and right side of the rectangle */ + if (x0 < 0) { + y0 = y0 - x0*dyx; + x0 = 0; + } + if (x1 > xmax) { + x1 = xmax; + y1 = y0 + (x1-x0)*dyx; + } + + if (y0 < 0.0f) { + x0 = x0 - y0*dxy; + y0 = 0.0f; + } else if (y0 > ymax) { + x0 = x0 + (ymax-y0)*dxy; + y0 = ymax; + } + + if (y1 < 0.0f) { + x1 = x1 - y1*dxy; + y1 = 0.0f; + } + else if (y1 > ymax) { + x1 = x1 - (y1 - ymax)*dxy; + y1 = ymax; + } + + if (x0 < 0 || x0 > xmax || x1 < 0 || x1 > xmax) { + + /* the line misses the clip rectangle around the corner */ + return 0; + } + +give_result: + + *px0 = (int) x0; + *py0 = (int) y0; + *px1 = (int) x1; + *py1 = (int) y1; + return 1; +}
-----------------------------------------------------------------------
Summary of changes: .../GP_TextStyle.c => include/gfx/GP_LineClip.h | 17 +-- libs/gfx/GP_Line.gen.c.t | 13 ++- include/core/GP_Core.h => libs/gfx/GP_LineClip.c | 154 +++++++++++++------- 3 files changed, 120 insertions(+), 64 deletions(-) copy libs/text/GP_TextStyle.c => include/gfx/GP_LineClip.h (85%) copy include/core/GP_Core.h => libs/gfx/GP_LineClip.c (50%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.