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 6722436c25bf3899cc2c3c2b44ed0382e04a7fff (commit)
from d5cdf89dd42290ce846e29309879a9263aa9e023 (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/6722436c25bf3899cc2c3c2b44ed0382e04a…
commit 6722436c25bf3899cc2c3c2b44ed0382e04a7fff
Author: BlueBear <jiri.bluebear.dluhos(a)gmail.com>
Date: Sun May 8 20:54:39 2011 +0200
Better sanity checks for text routines.
diff --git a/core/GP_Font.h b/core/GP_Font.h
index 91ecd3b..0354948 100644
--- a/core/GP_Font.h
+++ b/core/GP_Font.h
@@ -102,6 +102,13 @@ typedef struct GP_Font {
uint8_t *data;
} GP_Font;
+#define GP_CHECK_FONT(font) do { + GP_CHECK(font->data, "invalid font: NULL font data"); + GP_CHECK(font->height > 0, "invalid font: height == 0"); + GP_CHECK(font->baseline <= font->height, "invalid font: baseline exceeds height"); + GP_CHECK(font->bytes_per_line > 0, "invalid font: bytes_per_line == 0"); +} while(0)
+
/* Data describing a single character. */
typedef struct GP_CharData {
diff --git a/core/GP_Text.c b/core/GP_Text.c
index e3bcbb2..f9bc779 100644
--- a/core/GP_Text.c
+++ b/core/GP_Text.c
@@ -43,9 +43,8 @@ GP_RetCode GP_Text(GP_Context *context, const GP_TextStyle *style,
int x, int y, int align, const char *str, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
+ GP_CHECK_TEXT_STYLE(style);
- if (style != NULL && style->font == NULL)
- return GP_ENULLPTR;
if (str == NULL)
return GP_ENULLPTR;
@@ -96,9 +95,8 @@ GP_RetCode GP_TText(GP_Context *context, const GP_TextStyle *style,
int x, int y, int align, const char *str, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
+ GP_CHECK_TEXT_STYLE(style);
- if (style != NULL && style->font == NULL)
- return GP_ENULLPTR;
if (str == NULL)
return GP_ENULLPTR;
@@ -147,9 +145,8 @@ GP_RetCode GP_BoxCenteredText(GP_Context *context, const GP_TextStyle *style,
int x, int y, int w, int h, const char *str, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
+ GP_CHECK_TEXT_STYLE(style);
- if (style != NULL && style->font == NULL)
- return GP_ENULLPTR;
if (str == NULL)
return GP_ENULLPTR;
@@ -170,9 +167,8 @@ GP_RetCode GP_TBoxCenteredText(GP_Context *context, const GP_TextStyle *style,
int x, int y, int w, int h, const char *str, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
+ GP_CHECK_TEXT_STYLE(style);
- if (style != NULL && style->font == NULL)
- return GP_ENULLPTR;
if (str == NULL)
return GP_ENULLPTR;
diff --git a/core/GP_TextStyle.h b/core/GP_TextStyle.h
index 8e33eb9..d79a326 100644
--- a/core/GP_TextStyle.h
+++ b/core/GP_TextStyle.h
@@ -64,7 +64,8 @@ void GP_DefaultTextStyle(GP_TextStyle *style);
#define GP_CHECK_TEXT_STYLE(style) do { GP_CHECK(style, "NULL style specified"); - GP_CHECK(style->font, "NULL font specified in style"); + GP_CHECK(style->font, "invalid text style: font is NULL"); + GP_CHECK_FONT(style->font); } while(0)
#endif /* GP_TEXTSTYLE_H */
-----------------------------------------------------------------------
Summary of changes:
core/GP_Font.h | 7 +++++++
core/GP_Text.c | 12 ++++--------
core/GP_TextStyle.h | 3 ++-
3 files changed, 13 insertions(+), 9 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
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 d5cdf89dd42290ce846e29309879a9263aa9e023 (commit)
from 037f2ffabeabd1a2522169b7b766333a64680762 (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/d5cdf89dd42290ce846e29309879a9263aa9…
commit d5cdf89dd42290ce846e29309879a9263aa9e023
Author: BlueBear <jiri.bluebear.dluhos(a)gmail.com>
Date: Sun May 8 17:33:29 2011 +0200
Fixed stupid typo in GP_ASSERT; minor cleanups
diff --git a/core/GP_Common.h b/core/GP_Common.h
index 24039b6..c6005f8 100644
--- a/core/GP_Common.h
+++ b/core/GP_Common.h
@@ -50,50 +50,55 @@
})
/*
- * Checks the condition and aborts immediately if it is not satisfied,
- * printing the condition and location in the source.
- * (Intended for checking for bugs within the library itself.
- * GP_CHECK is used for reporting user errors, like invalid arguments.)
+ * The standard likely() and unlikely() used in Kernel
*/
-#define GP_ASSERT(cond) do { - if ((cond)) { - fprintf(stderr, "*** gfxprim: %s:%d: in %s: BUG - assertion failed: %sn", - __FILE__, __LINE__, __FUNCTION__, #cond); - abort(); - } - } while (0)
+#ifndef likely
+ #ifdef __GNUC__
+ #define likely(x) __builtin_expect(!!(x),1)
+ #define unlikely(x) __builtin_expect(!!(x),0)
+ #else
+ #define likely(x) x
+ #define unlikely(x) x
+ #endif
+#endif
/*
- * Abort and print abort location to stderr
+ * Aborts and prints the message along with the location in code
+ * to stderr. Used for fatal errors.
*/
#define GP_ABORT(msg) do { fprintf(stderr, "*** gfxprim: aborted: %s:%d: in %s: %sn", - __FILE__, __LINE__, __FUNCTION__, #msg); + __FILE__, __LINE__, __FUNCTION__, msg); abort(); } while (0)
/*
+ * Checks the condition and aborts immediately if it is not satisfied,
+ * printing the condition and location in the source.
+ * (Intended for checking for bugs within the library itself.
+ * GP_CHECK is used for reporting user errors, like invalid arguments.)
+ */
+#define GP_ASSERT(cond) do { + if (unlikely(!(cond))) { + fprintf(stderr, "*** gfxprim: %s:%d: in %s: BUG: assertion failed: %sn", + __FILE__, __LINE__, __FUNCTION__, #cond); + abort(); + } +} while (0)
+
+/*
* Perform a runtime check, on failure abort and print a message.
* (This macro is intended for checks for user-caused errors,
* like invalid arguments, leaving the library in improper state etc.
* For internal sanity checks, use GP_ASSERT.)
*/
#define GP_CHECK(cond, msg) do { - if (!(cond)) { - fprintf(stderr, "*** gfxprim: %s:%d: in %s: %sn", - __FILE__, __LINE__, __FUNCTION__, #msg); - abort(); - } - } while (0)
-
-/*
- * The standard likely() and unlikely() used in Kernel
- * TODO: Define as no-op for non-GCC compilers
- */
-#ifndef likely
-#define likely(x) __builtin_expect((x),1)
-#define unlikely(x) __builtin_expect((x),0)
-#endif
+ if (unlikely(!(cond))) { + fprintf(stderr, "*** gfxprim: %s:%d: in %s: %sn", + __FILE__, __LINE__, __FUNCTION__, msg); + abort(); + } +} while (0)
/*
* Swap a and b using an intermediate variable
-----------------------------------------------------------------------
Summary of changes:
core/GP_Common.h | 61 +++++++++++++++++++++++++++++------------------------
1 files changed, 33 insertions(+), 28 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
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 50ac1f21f85e66b3d2a8a0a6047971c474c250a4 (commit)
from 2274cefa956331bb30fc65f72522f7a4d4ec0e28 (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/50ac1f21f85e66b3d2a8a0a6047971c474c2…
commit 50ac1f21f85e66b3d2a8a0a6047971c474c250a4
Author: BlueBear <jiri.bluebear.dluhos(a)gmail.com>
Date: Thu May 5 22:15:20 2011 +0200
Added the GP_BUG_ON macro.
diff --git a/core/GP_Common.h b/core/GP_Common.h
index 6f06121..b93e921 100644
--- a/core/GP_Common.h
+++ b/core/GP_Common.h
@@ -50,6 +50,18 @@
})
/*
+ * Checks the condition and aborts immediately if it is true,
+ * printing the condition and location in the source.
+ */
+#define GP_BUG_ON(test) do { + if ((test)) { + fprintf(stderr, "*** gfxprim: BUG: %s:%d: in %s: %sn", + __FILE__, __LINE__, __FUNCTION__, #test); + abort(); + } + } while (0)
+
+/*
* Abort and print abort location to stderr
*/
#define GP_ABORT(msg) do {
-----------------------------------------------------------------------
Summary of changes:
core/GP_Common.h | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
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 037f2ffabeabd1a2522169b7b766333a64680762 (commit)
from 21f013df6c1f9ff561304ef0543589baefd79a9b (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/037f2ffabeabd1a2522169b7b766333a6468…
commit 037f2ffabeabd1a2522169b7b766333a64680762
Author: BlueBear <jiri.bluebear.dluhos(a)gmail.com>
Date: Sun May 8 14:59:20 2011 +0200
Tetragons now drawn with the polygon routine.
diff --git a/core/GP.h b/core/GP.h
index 9600772..8254d49 100644
--- a/core/GP.h
+++ b/core/GP.h
@@ -52,7 +52,6 @@
#include "GP_FillRect.h"
#include "GP_Triangle.h"
#include "GP_Tetragon.h"
-#include "GP_FillTetragon.h"
#include "GP_Circle.h"
#include "GP_FillCircle.h"
#include "GP_Ellipse.h"
diff --git a/core/GP_FillTetragon.c b/core/GP_FillTetragon.c
deleted file mode 100644
index 9f7e36a..0000000
--- a/core/GP_FillTetragon.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*****************************************************************************
- * 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(a)gmail.com> *
- * *
- * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-#include "GP.h"
-
-void GP_FillTetragon(GP_Context * context, int x0, int y0, int x1, int y1,
- int x2, int y2, int x3, int y3, GP_Pixel pixel)
-{
- GP_CHECK_CONTEXT(context);
-
- //TODO: fix this!
- GP_FillTriangle(context, x0, y0, x1, y1, x2, y2, pixel);
- GP_FillTriangle(context, x3, y3, x1, y1, x2, y2, pixel);
-}
-
-void GP_TFillTetragon(GP_Context* context, int x0, int y0, int x1, int y1,
- int x2, int y2, int x3, int y3, GP_Pixel pixel)
-{
- GP_CHECK_CONTEXT(context);
-
- GP_TRANSFORM_POINT(context, x0, y0);
- GP_TRANSFORM_POINT(context, x1, y1);
- GP_TRANSFORM_POINT(context, x2, y2);
- GP_TRANSFORM_POINT(context, x3, y3);
-
- GP_FillTetragon(context, x0, y0, x1, y1, x2, y2, x3, y3, pixel);
-}
diff --git a/core/GP_FillTetragon.h b/core/GP_FillTetragon.h
deleted file mode 100644
index 0335648..0000000
--- a/core/GP_FillTetragon.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*****************************************************************************
- * 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(a)gmail.com> *
- * *
- * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-#ifndef GP_FILLTETRAGON_H
-#define GP_FILLTETRAGON_H
-
-#include "GP_Context.h"
-
-void GP_FillTetragon(GP_Context *context, int x0, int y0, int x1, int y1,
- int x2, int y2, int x3, int y3, GP_Pixel pixel);
-
-void GP_TFillTetragon(GP_Context *context, int x0, int y0, int x1, int y1,
- int x2, int y2, int x3, int y3, GP_Pixel pixel);
-
-#endif /* GP_FILLTETRAGON_H */
diff --git a/core/GP_Tetragon.c b/core/GP_Tetragon.c
index 4618002..2f0b777 100644
--- a/core/GP_Tetragon.c
+++ b/core/GP_Tetragon.c
@@ -48,3 +48,26 @@ void GP_TTetragon(GP_Context *context, int x0, int y0, int x1, int y1,
GP_Tetragon(context, x0, y0, x1, y1, x2, y2, x3, y3, pixel);
}
+
+void GP_FillTetragon(GP_Context *context, int x0, int y0, int x1, int y1,
+ int x2, int y2, int x3, int y3, GP_Pixel pixel)
+{
+ GP_CHECK_CONTEXT(context);
+
+ int xy[8] = { x0, y0, x1, y1, x2, y2, x3, y3 };
+ GP_FillPolygon(context, 4, (const int *) xy, pixel);
+}
+
+void GP_TFillTetragon(GP_Context* context, int x0, int y0, int x1, int y1,
+ int x2, int y2, int x3, int y3, GP_Pixel pixel)
+{
+ GP_CHECK_CONTEXT(context);
+
+ GP_TRANSFORM_POINT(context, x0, y0);
+ GP_TRANSFORM_POINT(context, x1, y1);
+ GP_TRANSFORM_POINT(context, x2, y2);
+ GP_TRANSFORM_POINT(context, x3, y3);
+
+ int xy[8] = { x0, y0, x1, y1, x2, y2, x3, y3 };
+ GP_FillPolygon(context, 4, (const int *) xy, pixel);
+}
diff --git a/core/GP_Tetragon.h b/core/GP_Tetragon.h
index 5ed30d0..f69aee8 100644
--- a/core/GP_Tetragon.h
+++ b/core/GP_Tetragon.h
@@ -34,4 +34,10 @@ void GP_Tetragon(GP_Context *context, int x0, int y0, int x1, int y1,
void GP_TTetragon(GP_Context *context, int x0, int y0, int x1, int y1,
int x2, int y2, int x3, int y3, GP_Pixel pixel);
+void GP_FillTetragon(GP_Context *context, int x0, int y0, int x1, int y1,
+ int x2, int y2, int x3, int y3, GP_Pixel pixel);
+
+void GP_TFillTetragon(GP_Context *context, int x0, int y0, int x1, int y1,
+ int x2, int y2, int x3, int y3, GP_Pixel pixel);
+
#endif /* GP_TETRAGON_H */
diff --git a/targets/sdl/tests/randomshapetest.c b/targets/sdl/tests/randomshapetest.c
index 3cb267f..b46125d 100644
--- a/targets/sdl/tests/randomshapetest.c
+++ b/targets/sdl/tests/randomshapetest.c
@@ -59,7 +59,8 @@ Uint32 timer_callback(__attribute__((unused)) Uint32 interval,
#define SHAPE_ELLIPSE 2
#define SHAPE_TRIANGLE 3
#define SHAPE_RECTANGLE 4
-#define SHAPE_LAST 4
+#define SHAPE_TETRAGON 5
+#define SHAPE_LAST 5
static int shape = SHAPE_FIRST;
/* Draw outlines? */
@@ -144,6 +145,23 @@ void draw_random_rectangle(GP_Pixel pixel)
}
}
+void draw_random_tetragon(GP_Pixel pixel)
+{
+ int x0, y0, x1, y1, x2, y2, x3, y3;
+ random_point(display, &x0, &y0);
+ random_point(display, &x1, &y1);
+ random_point(display, &x2, &y2);
+ random_point(display, &x3, &y3);
+
+ if (fill_flag) {
+ GP_FillTetragon(&context, x0, y0, x1, y1, x2, y2, x3, y3, pixel);
+ }
+
+ if (outline_flag) {
+ GP_Tetragon(&context, x0, y0, x1, y1, x2, y2, x3, y3, pixel);
+ }
+}
+
void clear_screen(void)
{
SDL_LockSurface(display);
@@ -178,6 +196,10 @@ void redraw_screen(void)
case SHAPE_RECTANGLE:
draw_random_rectangle(pixel);
break;
+
+ case SHAPE_TETRAGON:
+ draw_random_tetragon(pixel);
+ break;
}
SDL_UnlockSurface(display);
diff --git a/targets/sdl/tests/shapetest.c b/targets/sdl/tests/shapetest.c
index 6e17cc1..fb85b2e 100644
--- a/targets/sdl/tests/shapetest.c
+++ b/targets/sdl/tests/shapetest.c
@@ -136,8 +136,9 @@ void draw_testing_triangle(int x, int y, int xradius, int yradius)
if (outline == 1)
GP_TTriangle(&context, x0, y0, x1, y1, x2, y2, yellow);
- if (fill)
+ if (fill) {
GP_TFillTriangle(&context, x0, y0, x1, y1, x2, y2, red);
+ }
if (outline == 2)
GP_TTriangle(&context, x0, y0, x1, y1, x2, y2, white);
-----------------------------------------------------------------------
Summary of changes:
core/GP.h | 1 -
core/GP_FillTetragon.c | 49 -----------------------------------
core/GP_FillTetragon.h | 37 --------------------------
core/GP_Tetragon.c | 23 ++++++++++++++++
core/GP_Tetragon.h | 6 ++++
targets/sdl/tests/randomshapetest.c | 24 ++++++++++++++++-
targets/sdl/tests/shapetest.c | 3 +-
7 files changed, 54 insertions(+), 89 deletions(-)
delete mode 100644 core/GP_FillTetragon.c
delete mode 100644 core/GP_FillTetragon.h
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
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 b0f09bfef85c7a22ed6feba890e085634a6517e2 (commit)
via e72092bb7d6f87d5d739cc1697da79cd69c6a2a7 (commit)
from 50ac1f21f85e66b3d2a8a0a6047971c474c250a4 (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/b0f09bfef85c7a22ed6feba890e085634a65…
commit b0f09bfef85c7a22ed6feba890e085634a6517e2
Author: BlueBear <jiri.bluebear.dluhos(a)gmail.com>
Date: Sat May 7 19:35:10 2011 +0200
Filled triangles are now drawn with polygons.
diff --git a/core/GP.h b/core/GP.h
index 1be9710..9600772 100644
--- a/core/GP.h
+++ b/core/GP.h
@@ -51,7 +51,6 @@
#include "GP_Rect.h"
#include "GP_FillRect.h"
#include "GP_Triangle.h"
-#include "GP_FillTriangle.h"
#include "GP_Tetragon.h"
#include "GP_FillTetragon.h"
#include "GP_Circle.h"
diff --git a/core/GP_FillTriangle.c b/core/GP_FillTriangle.c
deleted file mode 100644
index 3b483d6..0000000
--- a/core/GP_FillTriangle.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*****************************************************************************
- * 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(a)gmail.com> *
- * *
- * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-#include "GP.h"
-#include "GP_FnPerBpp.h"
-#include "algo/FillTriangle.algo.h"
-
-#include <math.h>
-#include <stdlib.h>
-
-/* Generate drawing functions for various bit depths. */
-DEF_FILLTRIANGLE_FN(GP_FillTriangle1bpp, GP_Context *, GP_Pixel, GP_HLine1bpp, GP_PutPixel1bpp)
-DEF_FILLTRIANGLE_FN(GP_FillTriangle2bpp, GP_Context *, GP_Pixel, GP_HLine2bpp, GP_PutPixel2bpp)
-DEF_FILLTRIANGLE_FN(GP_FillTriangle4bpp, GP_Context *, GP_Pixel, GP_HLine4bpp, GP_PutPixel4bpp)
-DEF_FILLTRIANGLE_FN(GP_FillTriangle8bpp, GP_Context *, GP_Pixel, GP_HLine8bpp, GP_PutPixel8bpp)
-DEF_FILLTRIANGLE_FN(GP_FillTriangle16bpp, GP_Context *, GP_Pixel, GP_HLine16bpp, GP_PutPixel16bpp)
-DEF_FILLTRIANGLE_FN(GP_FillTriangle24bpp, GP_Context *, GP_Pixel, GP_HLine24bpp, GP_PutPixel24bpp)
-DEF_FILLTRIANGLE_FN(GP_FillTriangle32bpp, GP_Context *, GP_Pixel, GP_HLine32bpp, GP_PutPixel32bpp)
-
-void GP_FillTriangle(GP_Context * context, int x0, int y0, int x1, int y1,
- int x2, int y2, GP_Pixel pixel)
-{
- GP_CHECK_CONTEXT(context);
-
- GP_FN_PER_BPP(GP_FillTriangle, context, x0, y0, x1, y1, x2, y2, pixel);
-}
-
-void GP_TFillTriangle(GP_Context* context, int x0, int y0, int x1, int y1,
- int x2, int y2, GP_Pixel pixel)
-{
- GP_CHECK_CONTEXT(context);
-
- GP_TRANSFORM_POINT(context, x0, y0);
- GP_TRANSFORM_POINT(context, x1, y1);
- GP_TRANSFORM_POINT(context, x2, y2);
-
- GP_FillTriangle(context, x0, y0, x1, y1, x2, y2, pixel);
-}
diff --git a/core/GP_FillTriangle.h b/core/GP_FillTriangle.h
deleted file mode 100644
index 11e0b4f..0000000
--- a/core/GP_FillTriangle.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*****************************************************************************
- * 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(a)gmail.com> *
- * *
- * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-#ifndef GP_FILLTRIANGLE_H
-#define GP_FILLTRIANGLE_H
-
-#include "GP_Context.h"
-#include "GP_Common.h"
-
-void GP_FillTriangle(GP_Context *context, int x0, int y0, int x1, int y1,
- int x2, int y2, GP_Pixel pixel);
-
-void GP_TFillTriangle(GP_Context *context, int x0, int y0, int x1, int y1,
- int x2, int y2, GP_Pixel pixel);
-
-#endif /* GP_FILLTRIANGLE_H */
diff --git a/core/GP_Triangle.c b/core/GP_Triangle.c
index 82caa55..4734617 100644
--- a/core/GP_Triangle.c
+++ b/core/GP_Triangle.c
@@ -46,3 +46,25 @@ void GP_TTriangle(GP_Context *context, int x0, int y0, int x1, int y1,
GP_Triangle(context, x0, y0, x1, y1, x2, y2, pixel);
}
+
+void GP_FillTriangle(GP_Context * context, int x0, int y0, int x1, int y1,
+ int x2, int y2, GP_Pixel pixel)
+{
+ GP_CHECK_CONTEXT(context);
+
+ int coords[6] = { x0, y0, x1, y1, x2, y2 };
+ GP_FillPolygon(context, 3, &coords, pixel);
+}
+
+void GP_TFillTriangle(GP_Context* context, int x0, int y0, int x1, int y1,
+ int x2, int y2, GP_Pixel pixel)
+{
+ GP_CHECK_CONTEXT(context);
+
+ GP_TRANSFORM_POINT(context, x0, y0);
+ GP_TRANSFORM_POINT(context, x1, y1);
+ GP_TRANSFORM_POINT(context, x2, y2);
+
+ int coords[6] = { x0, y0, x1, y1, x2, y2 };
+ GP_FillPolygon(context, 3, &coords, pixel);
+}
diff --git a/core/GP_Triangle.h b/core/GP_Triangle.h
index 3684b11..4bc5523 100644
--- a/core/GP_Triangle.h
+++ b/core/GP_Triangle.h
@@ -34,4 +34,10 @@ void GP_Triangle(GP_Context *context, int x0, int y0, int x1, int y1,
void GP_TTriangle(GP_Context *context, int x0, int y0, int x1, int y1,
int x2, int y2, GP_Pixel pixel);
+void GP_FillTriangle(GP_Context *context, int x0, int y0, int x1, int y1,
+ int x2, int y2, GP_Pixel pixel);
+
+void GP_TFillTriangle(GP_Context *context, int x0, int y0, int x1, int y1,
+ int x2, int y2, GP_Pixel pixel);
+
#endif /* GP_TRIANGLE_H */
http://repo.or.cz/w/gfxprim.git/commit/e72092bb7d6f87d5d739cc1697da79cd69c6…
commit e72092bb7d6f87d5d739cc1697da79cd69c6a2a7
Author: BlueBear <jiri.bluebear.dluhos(a)gmail.com>
Date: Sat May 7 19:33:59 2011 +0200
Multicolored sierpinsky to aid visual analysis.
diff --git a/targets/sdl/tests/sierpinsky.c b/targets/sdl/tests/sierpinsky.c
index d9411ee..99fc99a 100644
--- a/targets/sdl/tests/sierpinsky.c
+++ b/targets/sdl/tests/sierpinsky.c
@@ -47,14 +47,19 @@ SDL_TimerID timer;
int iter, l, way = 1;
-GP_Pixel black, blue, gray;
+GP_Pixel black, blue, gray, red;
-static void sierpinsky(SDL_Surface *surf, GP_Pixel pixel, float x1, float y1, float x4, float y4, int iter)
+int draw_edge = 1;
+
+static void sierpinsky(SDL_Surface *surf, double x1, double y1, double x4, double y4, int iter)
{
- float x2, y2, x3, y3, x5, y5;
+ double x2, y2, x3, y3, x5, y5;
+ GP_Pixel pixel;
+ GP_RGBToPixel(&context, 0, 0, 255-16*iter, &pixel);
if (iter <= 0) {
- GP_Line(&context, x1, y1, x4, y4, black);
+ if (draw_edge)
+ GP_Line(&context, x1, y1, x4, y4, black);
return;
}
@@ -69,15 +74,19 @@ static void sierpinsky(SDL_Surface *surf, GP_Pixel pixel, float x1, float y1, fl
GP_FillTriangle(&context, x2, y2, x3, y3, x5, y5, pixel);
- sierpinsky(surf, pixel, x1, y1, x2, y2, iter - 1);
- sierpinsky(surf, pixel, x2, y2, x5, y5, iter - 1);
- sierpinsky(surf, pixel, x5, y5, x3, y3, iter - 1);
- sierpinsky(surf, pixel, x3, y3, x4, y4, iter - 1);
+ GP_PutPixel(&context, x2, y2, red);
+ GP_PutPixel(&context, x3, y3, red);
+ GP_PutPixel(&context, x5, y5, red);
+
+ sierpinsky(surf, x1, y1, x2, y2, iter - 1);
+ sierpinsky(surf, x2, y2, x5, y5, iter - 1);
+ sierpinsky(surf, x5, y5, x3, y3, iter - 1);
+ sierpinsky(surf, x3, y3, x4, y4, iter - 1);
}
static void draw(SDL_Surface *surf, int x, int y, int l, int iter)
{
- float x1, y1, x2, y2, x3, y3;
+ double x1, y1, x2, y2, x3, y3;
int w = surf->w;
int h = surf->h;
@@ -96,9 +105,9 @@ static void draw(SDL_Surface *surf, int x, int y, int l, int iter)
GP_FillTriangle(&context, x1, y1, x2, y2, x3, y3, blue);
- sierpinsky(surf, blue, x1, y1, x2, y2, iter/60%6);
- sierpinsky(surf, blue, x2, y2, x3, y3, iter/60%6);
- sierpinsky(surf, blue, x3, y3, x1, y1, iter/60%6);
+ sierpinsky(surf, x1, y1, x2, y2, iter/60%6);
+ sierpinsky(surf, x2, y2, x3, y3, iter/60%6);
+ sierpinsky(surf, x3, y3, x1, y1, iter/60%6);
SDL_UpdateRect(surf, 0, 0, surf->w, surf->h);
}
@@ -142,6 +151,7 @@ int main(void)
GP_ColorNameToPixel(&context, GP_COL_BLACK, &black);
GP_ColorNameToPixel(&context, GP_COL_BLUE, &blue);
GP_ColorNameToPixel(&context, GP_COL_GRAY_LIGHT, &gray);
+ GP_ColorNameToPixel(&context, GP_COL_RED, &red);
iter = 0;
draw(display, display->w/2, display->h/2, l, iter);
@@ -160,6 +170,9 @@ int main(void)
case SDLK_p:
paused = !paused;
break;
+ case SDLK_e:
+ draw_edge = !draw_edge;
+ break;
case SDLK_ESCAPE:
SDL_Quit();
return 0;
-----------------------------------------------------------------------
Summary of changes:
core/GP.h | 1 -
core/GP_FillTriangle.c | 60 ----------------------------------------
core/GP_FillTriangle.h | 38 -------------------------
core/GP_Triangle.c | 22 ++++++++++++++
core/GP_Triangle.h | 6 ++++
targets/sdl/tests/sierpinsky.c | 37 ++++++++++++++++--------
6 files changed, 53 insertions(+), 111 deletions(-)
delete mode 100644 core/GP_FillTriangle.c
delete mode 100644 core/GP_FillTriangle.h
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
Good news everyone,
I've played with the gfxprim pages again and I'm kind of pleased with the
outcome. See for yourself: http://gfxprim.ucw.cz/
Any comments are welcome (some minor changes may happen but the overall desing
should be done now).
--
metan