Gfxprim
Threads by month
- ----- 2026 -----
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- 929 discussions
[repo.or.cz] gfxprim.git branch generate updated: f4f99af5bd7efbf8214eaf84a95dab162f763179
by metan 17 Jul '11
by metan 17 Jul '11
17 Jul '11
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, generate has been updated
via f4f99af5bd7efbf8214eaf84a95dab162f763179 (commit)
from 80e05d567a9526b7bfb21cd458572c364502e4a0 (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/f4f99af5bd7efbf8214eaf84a95dab162f76…
commit f4f99af5bd7efbf8214eaf84a95dab162f763179
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jul 17 14:41:01 2011 +0200
Fixed Filters to work with generated code.
diff --git a/include/core/GP_DefFnPerBpp.h b/include/core/GP_DefFnPerBpp.h
index 6da6754..534a451 100644
--- a/include/core/GP_DefFnPerBpp.h
+++ b/include/core/GP_DefFnPerBpp.h
@@ -51,4 +51,25 @@
GP_DEF_FN_FOR_BPP(fname, MACRO_NAME, fdraw, 24BPP) GP_DEF_FN_FOR_BPP(fname, MACRO_NAME, fdraw, 32BPP)
+/*
+ * Dtto for filters.
+ *
+ * Filter is functions that works on Context per pixel.
+ */
+#define GP_DEF_FFN_FOR_BPP(fname, MACRO_NAME, bpp) + MACRO_NAME(fname##_##bpp, GP_Context *, GP_Pixel, + GP_PutPixel_Raw_##bpp, GP_GetPixel_Raw_##bpp)
+
+#define GP_DEF_FFN_PER_BPP(fname, MACRO_NAME) + GP_DEF_FFN_FOR_BPP(fname, MACRO_NAME, 1BPP_LE) + GP_DEF_FFN_FOR_BPP(fname, MACRO_NAME, 1BPP_BE) + GP_DEF_FFN_FOR_BPP(fname, MACRO_NAME, 2BPP_LE) + GP_DEF_FFN_FOR_BPP(fname, MACRO_NAME, 2BPP_BE) + GP_DEF_FFN_FOR_BPP(fname, MACRO_NAME, 4BPP_LE) + GP_DEF_FFN_FOR_BPP(fname, MACRO_NAME, 4BPP_BE) + GP_DEF_FFN_FOR_BPP(fname, MACRO_NAME, 8BPP) + GP_DEF_FFN_FOR_BPP(fname, MACRO_NAME, 16BPP) + GP_DEF_FFN_FOR_BPP(fname, MACRO_NAME, 24BPP) + GP_DEF_FFN_FOR_BPP(fname, MACRO_NAME, 32BPP) +
#endif /* GP_DEF_FN_PER_BPP_H */
diff --git a/libs/filters/GP_Rotate.c b/libs/filters/GP_Rotate.c
index e73c106..adb0ce2 100644
--- a/libs/filters/GP_Rotate.c
+++ b/libs/filters/GP_Rotate.c
@@ -25,14 +25,14 @@
#include "core/GP_Core.h"
#include "core/GP_FnPerBpp.h"
+#include "core/GP_DefFnPerBpp.h"
#include "GP_Rotate.h"
-#include "algo/GP_MirrorV.algo.h"
-#include "algo/GP_Rotate.algo.h"
-
#include <string.h>
+#include "algo/GP_MirrorV.algo.h"
+
GP_RetCode GP_MirrorH(GP_Context *context)
{
uint32_t bpr = context->bytes_per_row;
@@ -56,63 +56,43 @@ GP_RetCode GP_MirrorH(GP_Context *context)
return GP_ESUCCESS;
}
-DEF_MIRRORV_FN(GP_MirrorV1bpp, GP_Context *, GP_Pixel,
- GP_PUTPIXEL_1BPP, GP_GETPIXEL_1BPP)
-DEF_MIRRORV_FN(GP_MirrorV2bpp, GP_Context *, GP_Pixel,
- GP_PUTPIXEL_2BPP, GP_GETPIXEL_2BPP)
-DEF_MIRRORV_FN(GP_MirrorV4bpp, GP_Context *, GP_Pixel,
- GP_PUTPIXEL_4BPP, GP_GETPIXEL_4BPP)
-DEF_MIRRORV_FN(GP_MirrorV8bpp, GP_Context *, GP_Pixel,
- GP_PUTPIXEL_8BPP, GP_GETPIXEL_8BPP)
-DEF_MIRRORV_FN(GP_MirrorV16bpp, GP_Context *, GP_Pixel,
- GP_PUTPIXEL_16BPP, GP_GETPIXEL_16BPP)
-DEF_MIRRORV_FN(GP_MirrorV24bpp, GP_Context *, GP_Pixel,
- GP_PUTPIXEL_24BPP, GP_GETPIXEL_24BPP)
-DEF_MIRRORV_FN(GP_MirrorV32bpp, GP_Context *, GP_Pixel,
- GP_PUTPIXEL_32BPP, GP_GETPIXEL_32BPP)
+/* Generate mirror functions per BPP */
+GP_DEF_FFN_PER_BPP(GP_MirrorV, DEF_MIRRORV_FN)
GP_RetCode GP_MirrorV(GP_Context *context)
{
if (context == NULL)
return GP_ENULLPTR;
- GP_FN_PER_BPP(GP_MirrorV, context->bpp, context);
+ GP_FN_PER_BPP_CONTEXT(GP_MirrorV, context, context);
return GP_ESUCCESS;
}
-DEF_ROTATECW_FN(GP_RotateCW1bpp, GP_Context *, GP_PUTPIXEL_1BPP, GP_GETPIXEL_1BPP)
-DEF_ROTATECW_FN(GP_RotateCW2bpp, GP_Context *, GP_PUTPIXEL_2BPP, GP_GETPIXEL_2BPP)
-DEF_ROTATECW_FN(GP_RotateCW4bpp, GP_Context *, GP_PUTPIXEL_4BPP, GP_GETPIXEL_4BPP)
-DEF_ROTATECW_FN(GP_RotateCW8bpp, GP_Context *, GP_PUTPIXEL_8BPP, GP_GETPIXEL_8BPP)
-DEF_ROTATECW_FN(GP_RotateCW16bpp, GP_Context *, GP_PUTPIXEL_16BPP, GP_GETPIXEL_16BPP)
-DEF_ROTATECW_FN(GP_RotateCW24bpp, GP_Context *, GP_PUTPIXEL_24BPP, GP_GETPIXEL_24BPP)
-DEF_ROTATECW_FN(GP_RotateCW32bpp, GP_Context *, GP_PUTPIXEL_32BPP, GP_GETPIXEL_32BPP)
+#include "algo/GP_Rotate.algo.h"
+
+/* Generate Rotate functions per BPP */
+GP_DEF_FFN_PER_BPP(GP_RotateCW, DEF_ROTATECW_FN)
GP_RetCode GP_RotateCW(GP_Context *context)
{
if (context == NULL)
return GP_ENULLPTR;
- GP_FN_RET_PER_BPP(GP_RotateCW, context->bpp, context);
+ GP_FN_RET_PER_BPP_CONTEXT(GP_RotateCW, context, context);
return GP_ENOIMPL;
}
-DEF_ROTATECCW_FN(GP_RotateCCW1bpp, GP_Context *, GP_PUTPIXEL_1BPP, GP_GETPIXEL_1BPP)
-DEF_ROTATECCW_FN(GP_RotateCCW2bpp, GP_Context *, GP_PUTPIXEL_2BPP, GP_GETPIXEL_2BPP)
-DEF_ROTATECCW_FN(GP_RotateCCW4bpp, GP_Context *, GP_PUTPIXEL_4BPP, GP_GETPIXEL_4BPP)
-DEF_ROTATECCW_FN(GP_RotateCCW8bpp, GP_Context *, GP_PUTPIXEL_8BPP, GP_GETPIXEL_8BPP)
-DEF_ROTATECCW_FN(GP_RotateCCW16bpp, GP_Context *, GP_PUTPIXEL_16BPP, GP_GETPIXEL_16BPP)
-DEF_ROTATECCW_FN(GP_RotateCCW24bpp, GP_Context *, GP_PUTPIXEL_24BPP, GP_GETPIXEL_24BPP)
-DEF_ROTATECCW_FN(GP_RotateCCW32bpp, GP_Context *, GP_PUTPIXEL_32BPP, GP_GETPIXEL_32BPP)
+/* Generate Rotate functions per BPP */
+GP_DEF_FFN_PER_BPP(GP_RotateCCW, DEF_ROTATECCW_FN)
GP_RetCode GP_RotateCCW(GP_Context *context)
{
if (context == NULL)
return GP_ENULLPTR;
- GP_FN_RET_PER_BPP(GP_RotateCCW, context->bpp, context);
+ GP_FN_RET_PER_BPP_CONTEXT(GP_RotateCCW, context, context);
return GP_ENOIMPL;
}
diff --git a/libs/filters/algo/GP_Rotate.algo.h b/libs/filters/algo/GP_Rotate.algo.h
index 2d5cf28..e6ea14d 100644
--- a/libs/filters/algo/GP_Rotate.algo.h
+++ b/libs/filters/algo/GP_Rotate.algo.h
@@ -27,7 +27,7 @@
#include "core/GP_Common.h"
#include "core/GP_Context.h"
-#define DEF_ROTATECW_FN(FN_NAME, CONTEXT_T, PUTPIXEL, GETPIXEL) +#define DEF_ROTATECW_FN(FN_NAME, CONTEXT_T, PIXEL_T, PUTPIXEL, GETPIXEL) GP_RetCode FN_NAME(CONTEXT_T context) { uint32_t x, y; @@ -58,7 +58,7 @@ GP_RetCode FN_NAME(CONTEXT_T context) return GP_ESUCCESS; }
-#define DEF_ROTATECCW_FN(FN_NAME, CONTEXT_T, PUTPIXEL, GETPIXEL) +#define DEF_ROTATECCW_FN(FN_NAME, CONTEXT_T, PIXEL_T, PUTPIXEL, GETPIXEL) GP_RetCode FN_NAME(CONTEXT_T context) { uint32_t x, y; diff --git a/tests/Makefile b/tests/Makefile
index 71029bb..83de916 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,3 +1,3 @@
TOPDIR=..
-SUBDIRS=loaders filters core SDL
+SUBDIRS=filters core SDL #loaders
include $(TOPDIR)/include.mk
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_DefFnPerBpp.h | 21 +++++++++++++++
libs/filters/GP_Rotate.c | 48 ++++++++++-------------------------
libs/filters/algo/GP_Rotate.algo.h | 4 +-
tests/Makefile | 2 +-
4 files changed, 38 insertions(+), 37 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.")
1
0
[repo.or.cz] gfxprim.git branch generate updated: 80e05d567a9526b7bfb21cd458572c364502e4a0
by metan 17 Jul '11
by metan 17 Jul '11
17 Jul '11
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, generate has been updated
via 80e05d567a9526b7bfb21cd458572c364502e4a0 (commit)
from cfc6c022b5368c44e60c7f494865c651066fb117 (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/80e05d567a9526b7bfb21cd458572c364502…
commit 80e05d567a9526b7bfb21cd458572c364502e4a0
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jul 17 14:21:10 2011 +0200
Fixed Text library compilation.
diff --git a/libs/text/GP_Text.c b/libs/text/GP_Text.c
index af11a48..4ffae23 100644
--- a/libs/text/GP_Text.c
+++ b/libs/text/GP_Text.c
@@ -19,25 +19,21 @@
* Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
* <jiri.bluebear.dluhos(a)gmail.com> *
* *
- * Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
+ * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
#include "algo/Text.algo.h"
#include "gfx/GP_Gfx.h"
#include "core/GP_FnPerBpp.h"
+#include "core/GP_DefFnPerBpp.h"
#include "GP_Text.h"
static GP_TextStyle DefaultStyle = GP_DEFAULT_TEXT_STYLE;
/* Generate drawing functions for various bit depths. */
-DEF_TEXT_FN(GP_Text1bpp, GP_Context *, GP_Pixel, GP_HLine1bpp)
-DEF_TEXT_FN(GP_Text2bpp, GP_Context *, GP_Pixel, GP_HLine2bpp)
-DEF_TEXT_FN(GP_Text4bpp, GP_Context *, GP_Pixel, GP_HLine4bpp)
-DEF_TEXT_FN(GP_Text8bpp, GP_Context *, GP_Pixel, GP_HLine8bpp)
-DEF_TEXT_FN(GP_Text16bpp, GP_Context *, GP_Pixel, GP_HLine16bpp)
-DEF_TEXT_FN(GP_Text24bpp, GP_Context *, GP_Pixel, GP_HLine24bpp)
-DEF_TEXT_FN(GP_Text32bpp, GP_Context *, GP_Pixel, GP_HLine32bpp)
+GP_DEF_FILL_FN_PER_BPP(GP_Text, DEF_TEXT_FN)
+
DEF_TEXT_FN(GP_TText_internal, GP_Context *, GP_Pixel, GP_THLine)
GP_RetCode GP_Text(GP_Context *context, const GP_TextStyle *style,
@@ -87,7 +83,7 @@ GP_RetCode GP_Text(GP_Context *context, const GP_TextStyle *style,
return GP_EINVAL;
}
- GP_FN_PER_BPP(GP_Text, context->bpp, context,
+ GP_FN_PER_BPP_CONTEXT(GP_Text, context, context,
style, topleft_x, topleft_y, str, pixel);
return GP_ESUCCESS;
-----------------------------------------------------------------------
Summary of changes:
libs/text/GP_Text.c | 14 +++++---------
1 files changed, 5 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.")
1
0
[repo.or.cz] gfxprim.git branch generate updated: cfc6c022b5368c44e60c7f494865c651066fb117
by metan 17 Jul '11
by metan 17 Jul '11
17 Jul '11
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, generate has been updated
via cfc6c022b5368c44e60c7f494865c651066fb117 (commit)
from ecca5686f36c35b12f2bd72dd5ef16165da1ec8c (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/cfc6c022b5368c44e60c7f494865c651066f…
commit cfc6c022b5368c44e60c7f494865c651066fb117
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Jul 17 14:13:32 2011 +0200
Made the gfx library work with the generated code.
diff --git a/include/core/GP_Context.h b/include/core/GP_Context.h
index ce85f65..35b8ae7 100644
--- a/include/core/GP_Context.h
+++ b/include/core/GP_Context.h
@@ -30,13 +30,9 @@
#include <unistd.h>
#include "GP_Common.h"
+#include "GP_Types.h"
#include "GP_Pixel.h"
-/* Integer type for coordinates: x, y, width, height, ...
- * Should be signed to hold negative values as well. */
-typedef int GP_Coord;
-typedef unsigned int GP_Size;
-
/* This structure holds all information needed for drawing into an image. */
typedef struct GP_Context {
uint8_t *pixels; /* pointer to image pixels */
diff --git a/include/gfx/GP_Gfx.h b/include/core/GP_DefFnPerBpp.h
similarity index 54%
copy from include/gfx/GP_Gfx.h
copy to include/core/GP_DefFnPerBpp.h
index aa578b4..6da6754 100644
--- a/include/gfx/GP_Gfx.h
+++ b/include/core/GP_DefFnPerBpp.h
@@ -16,41 +16,39 @@
* 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> *
+ * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
/*
-
- This is a main header for gfx part.
-
+ * Macros that gets MACRO template for drawing function and generates drawing
+ * functions for each BPP.
+ *
+ * This functions are later used by GP_FN_PER_BPP_CONTEXT() to generate one
+ * drawing function for all BPP Yay!
*/
+#ifndef GP_DEF_FN_PER_BPP_H
+#define GP_DEF_FN_PER_BPP_H
+
+#define GP_DEF_DRAW_FN_PER_BPP(fname, MACRO_NAME) + GP_DEF_FN_PER_BPP(fname, MACRO_NAME, GP_PutPixel_Raw_)
-#ifndef GP_GFX_H
-#define GP_GFX_H
+#define GP_DEF_FILL_FN_PER_BPP(fname, MACRO_NAME) + GP_DEF_FN_PER_BPP(fname, MACRO_NAME, GP_HLine_)
-/* basic definitions and structures */
-#include "core/GP_Common.h"
-#include "core/GP_Transform.h"
-#include "core/GP_Context.h"
-#include "core/GP_WritePixel.h"
-#include "core/GP_GetPutPixel.h"
-#include "core/GP_Color.h"
+#define GP_DEF_FN_FOR_BPP(fname, MACRO_NAME, fdraw, bpp) + MACRO_NAME(fname##_##bpp, GP_Context *, GP_Pixel, fdraw##bpp)
-/* public drawing API */
-#include "GP_Fill.h"
-#include "GP_HLine.h"
-#include "GP_VLine.h"
-#include "GP_Line.h"
-#include "GP_Rect.h"
-#include "GP_Triangle.h"
-#include "GP_Tetragon.h"
-#include "GP_Circle.h"
-#include "GP_Ellipse.h"
-#include "GP_Polygon.h"
-#include "GP_Symbol.h"
+#define GP_DEF_FN_PER_BPP(fname, MACRO_NAME, fdraw) + GP_DEF_FN_FOR_BPP(fname, MACRO_NAME, fdraw, 1BPP_LE) + GP_DEF_FN_FOR_BPP(fname, MACRO_NAME, fdraw, 1BPP_BE) + GP_DEF_FN_FOR_BPP(fname, MACRO_NAME, fdraw, 2BPP_LE) + GP_DEF_FN_FOR_BPP(fname, MACRO_NAME, fdraw, 2BPP_BE) + GP_DEF_FN_FOR_BPP(fname, MACRO_NAME, fdraw, 4BPP_LE) + GP_DEF_FN_FOR_BPP(fname, MACRO_NAME, fdraw, 4BPP_BE) + GP_DEF_FN_FOR_BPP(fname, MACRO_NAME, fdraw, 8BPP) + GP_DEF_FN_FOR_BPP(fname, MACRO_NAME, fdraw, 16BPP) + GP_DEF_FN_FOR_BPP(fname, MACRO_NAME, fdraw, 24BPP) + GP_DEF_FN_FOR_BPP(fname, MACRO_NAME, fdraw, 32BPP)
-#endif /* GP_GFX_H */
+#endif /* GP_DEF_FN_PER_BPP_H */
diff --git a/include/gfx/GP_Polygon.h b/include/core/GP_Types.h
similarity index 75%
copy from include/gfx/GP_Polygon.h
copy to include/core/GP_Types.h
index dc4a6e1..e3d0f55 100644
--- a/include/gfx/GP_Polygon.h
+++ b/include/core/GP_Types.h
@@ -16,19 +16,20 @@
* 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> *
+ * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
-#ifndef GP_FILL_POLYGON_H
-#define GP_FILL_POLYGON_H
+#ifndef GP_TYPES_H
+#define GP_TYPES_H
-#include "core/GP_Context.h"
+#include <stdint.h>
-void GP_FillPolygon(GP_Context *context, int vertex_count, const int *xy,
- GP_Pixel pixel);
+/*
+ * Integer type for coordinates: x, y, width, height, ...
+ * Should be signed to hold negative values as well.
+ */
+typedef int GP_Coord;
+typedef unsigned int GP_Size;
-#endif /* GP_FILL_POLYGON_H */
+#endif /* GP_TYPES_H */
diff --git a/include/gfx/GP_Circle.h b/include/gfx/GP_Circle.h
index 6360e72..aaab27a 100644
--- a/include/gfx/GP_Circle.h
+++ b/include/gfx/GP_Circle.h
@@ -28,16 +28,16 @@
#include "core/GP_Context.h"
-void GP_Circle(GP_Context *context, int xcenter, int ycenter,
- unsigned int r, GP_Pixel pixel);
+void GP_Circle(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size r, GP_Pixel pixel);
-void GP_TCircle(GP_Context *context, int xcenter, int ycenter,
- unsigned int r, GP_Pixel pixel);
+void GP_TCircle(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size r, GP_Pixel pixel);
-void GP_FillCircle(GP_Context *context, int xcenter, int ycenter,
- unsigned int r, GP_Pixel pixel);
+void GP_FillCircle(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size r, GP_Pixel pixel);
-void GP_TFillCircle(GP_Context *context, int xcenter, int ycenter,
- unsigned int r, GP_Pixel pixel);
+void GP_TFillCircle(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size r, GP_Pixel pixel);
#endif /* GP_CIRCLE_H */
diff --git a/include/gfx/GP_Ellipse.h b/include/gfx/GP_Ellipse.h
index eeb6d5a..ef10808 100644
--- a/include/gfx/GP_Ellipse.h
+++ b/include/gfx/GP_Ellipse.h
@@ -28,17 +28,17 @@
#include "core/GP_Context.h"
-void GP_Ellipse(GP_Context *context, int xcenter, int ycenter,
- unsigned int a, unsigned int b, GP_Pixel pixel);
+void GP_Ellipse(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size a, GP_Size b, GP_Pixel pixel);
-void GP_TEllipse(GP_Context *context, int xcenter, int ycenter,
- unsigned int a, unsigned int b, GP_Pixel pixel);
+void GP_TEllipse(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size a, GP_Size b, GP_Pixel pixel);
-void GP_FillEllipse(GP_Context *context, int xcenter, int ycenter,
- unsigned int a, unsigned int b, GP_Pixel pixel);
+void GP_FillEllipse(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size a, GP_Size b, GP_Pixel pixel);
-void GP_TFillEllipse(GP_Context *context, int xcenter, int ycenter,
- unsigned int a, unsigned int b, GP_Pixel pixel);
+void GP_TFillEllipse(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size a, GP_Size b, GP_Pixel pixel);
#endif /* GP_ELLIPSE_H */
diff --git a/include/gfx/GP_Gfx.h b/include/gfx/GP_Gfx.h
index aa578b4..4639b1f 100644
--- a/include/gfx/GP_Gfx.h
+++ b/include/gfx/GP_Gfx.h
@@ -34,6 +34,7 @@
/* basic definitions and structures */
#include "core/GP_Common.h"
+#include "core/GP_Types.h"
#include "core/GP_Transform.h"
#include "core/GP_Context.h"
#include "core/GP_WritePixel.h"
diff --git a/include/gfx/GP_HLine.h b/include/gfx/GP_HLine.h
index ee3c674..66e2b79 100644
--- a/include/gfx/GP_HLine.h
+++ b/include/gfx/GP_HLine.h
@@ -28,26 +28,59 @@
#include "core/GP_Context.h"
-void GP_HLine1bpp(GP_Context *context, int x0, int x1, int y, GP_Pixel pixel);
-void GP_HLine2bpp(GP_Context *context, int x0, int x1, int y, GP_Pixel pixel);
-void GP_HLine8bpp(GP_Context *context, int x0, int x1, int y, GP_Pixel pixel);
-void GP_HLine4bpp(GP_Context *context, int x0, int x1, int y, GP_Pixel pixel);
-void GP_HLine16bpp(GP_Context *context, int x0, int x1, int y, GP_Pixel pixel);
-void GP_HLine24bpp(GP_Context *context, int x0, int x1, int y, GP_Pixel pixel);
-void GP_HLine32bpp(GP_Context *context, int x0, int x1, int y, GP_Pixel pixel);
+void GP_HLine_1BPP_LE(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
-void GP_HLineXXY(GP_Context *context, int x0, int x1, int y, GP_Pixel pixel);
+void GP_HLine_1BPP_BE(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
-void GP_HLineXYW(GP_Context *context, int x, int y, unsigned int w,
+void GP_HLine_2BPP_LE(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_HLine_2BPP_BE(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_HLine_4BPP_LE(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_HLine_4BPP_BE(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_HLine_8BPP(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_HLine_16BPP(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_HLine_24BPP(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_HLine_32BPP(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_HLineXXY(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
+
+void GP_HLineXYW(GP_Context *context, GP_Coord x, GP_Coord y, GP_Size w,
GP_Pixel pixel);
-void GP_THLineXXY(GP_Context *context, int x0, int x1, int y, GP_Pixel pixel);
+void GP_THLineXXY(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel);
-void GP_THLineXYW(GP_Context *context, int x, int y, unsigned int w,
+void GP_THLineXYW(GP_Context *context, GP_Coord x, GP_Coord y, GP_Size w,
GP_Pixel pixel);
/* default argument set is XXY */
-#define GP_HLine GP_HLineXXY
-#define GP_THLine GP_THLineXXY
+static inline void GP_HLine(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel p)
+{
+ GP_HLineXXY(context, x0, x1, y, p);
+}
+
+static inline void GP_THLine(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel p)
+{
+ GP_THLineXXY(context, x0, x1, y, p);
+}
#endif /* GP_HLINE_H */
diff --git a/include/gfx/GP_Line.h b/include/gfx/GP_Line.h
index b5587bd..be0b67f 100644
--- a/include/gfx/GP_Line.h
+++ b/include/gfx/GP_Line.h
@@ -28,19 +28,22 @@
#include "core/GP_Context.h"
-void GP_Line8bpp(GP_Context *context, int x0, int y0, int x1, int y1,
- GP_Pixel pixel);
-void GP_Line16bpp(GP_Context *context, int x0, int y0, int x1, int y1,
- GP_Pixel pixel);
-void GP_Line24bpp(GP_Context *context, int x0, int y0, int x1, int y1,
- GP_Pixel pixel);
-void GP_Line32bpp(GP_Context *context, int x0, int y0, int x1, int y1,
- GP_Pixel pixel);
-
-void GP_Line(GP_Context *context, int x0, int y0, int x1, int y1,
- GP_Pixel pixel);
-
-void GP_TLine(GP_Context *context, int x0, int y0, int x1, int y1,
- GP_Pixel pixel);
+void GP_Line8bpp(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel);
+
+void GP_Line16bpp(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel);
+
+void GP_Line24bpp(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel);
+
+void GP_Line32bpp(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel);
+
+void GP_Line(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel);
+
+void GP_TLine(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel);
#endif /* GP_LINE_H */
diff --git a/include/gfx/GP_Polygon.h b/include/gfx/GP_Polygon.h
index dc4a6e1..eee3bcc 100644
--- a/include/gfx/GP_Polygon.h
+++ b/include/gfx/GP_Polygon.h
@@ -23,12 +23,12 @@
* *
*****************************************************************************/
-#ifndef GP_FILL_POLYGON_H
-#define GP_FILL_POLYGON_H
+#ifndef GP_POLYGON_H
+#define GP_POLYGON_H
#include "core/GP_Context.h"
-void GP_FillPolygon(GP_Context *context, int vertex_count, const int *xy,
- GP_Pixel pixel);
+void GP_FillPolygon(GP_Context *context, int vertex_count, const GP_Coord *xy,
+ GP_Pixel pixel);
-#endif /* GP_FILL_POLYGON_H */
+#endif /* GP_POLYGON_H */
diff --git a/include/gfx/GP_Rect.h b/include/gfx/GP_Rect.h
index a0085e8..984e0ee 100644
--- a/include/gfx/GP_Rect.h
+++ b/include/gfx/GP_Rect.h
@@ -28,33 +28,33 @@
#include "core/GP_Context.h"
-void GP_RectXYXY(GP_Context *context, int x0, int y0, int x1, int y1,
- GP_Pixel pixel);
+void GP_RectXYXY(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel);
-void GP_RectXYWH(GP_Context *context, int x, int y,
- unsigned int w, unsigned int h, GP_Pixel pixel);
+void GP_RectXYWH(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Size w, GP_Size h, GP_Pixel pixel);
-void GP_TRectXYXY(GP_Context *context, int x0, int y0, int x1, int y1,
- GP_Pixel pixel);
+void GP_TRectXYXY(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel);
-void GP_TRectXYWH(GP_Context *context, int x, int y,
- unsigned int w, unsigned int h, GP_Pixel pixel);
+void GP_TRectXYWH(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Size w, GP_Size h, GP_Pixel pixel);
/* The XYXY argument set is the default */
#define GP_Rect GP_RectXYXY
#define GP_TRect GP_TRectXYXY
-void GP_FillRectXYXY(GP_Context *context, int x0, int y0, int x1, int y1,
- GP_Pixel pixel);
+void GP_FillRectXYXY(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel);
-void GP_FillRectXYWH(GP_Context *context, int x, int y,
- unsigned int w, unsigned int h, GP_Pixel pixel);
+void GP_FillRectXYWH(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Size w, GP_Size h, GP_Pixel pixel);
-void GP_TFillRectXYXY(GP_Context *context, int x0, int y0, int x1, int y1,
- GP_Pixel pixel);
+void GP_TFillRectXYXY(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel);
-void GP_TFillRectXYWH(GP_Context *context, int x, int y,
- unsigned int w, unsigned int h, GP_Pixel pixel);
+void GP_TFillRectXYWH(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Size w, GP_Size h, GP_Pixel pixel);
#define GP_FillRect GP_FillRectXYXY
#define GP_TFillRect GP_TFillRectXYXY
diff --git a/include/gfx/GP_Symbol.h b/include/gfx/GP_Symbol.h
index 5aa3f2c..648a11e 100644
--- a/include/gfx/GP_Symbol.h
+++ b/include/gfx/GP_Symbol.h
@@ -30,7 +30,7 @@
#ifndef GP_SYMBOL_H
#define GP_SYMBOL_H
-#include "core/GP_Context.h"
+#include "core/GP_Types.h"
typedef enum GP_SymbolType {
GP_SYM_TRIANGLE_UP,
@@ -41,15 +41,19 @@ typedef enum GP_SymbolType {
} GP_SymbolType;
void GP_Symbol(GP_Context *context, GP_SymbolType sym,
- int x, int y, int w, int h, GP_Pixel pixel);
+ GP_Coord x, GP_Coord y,
+ GP_Size w, GP_Size h, GP_Pixel pixel);
void GP_TSymbol(GP_Context *context, GP_SymbolType sym,
- int x, int y, int w, int h, GP_Pixel pixel);
+ GP_Coord x, GP_Coord y,
+ GP_Size w, GP_Size h, GP_Pixel pixel);
void GP_FillSymbol(GP_Context *context, GP_SymbolType sym,
- int x, int y, int w, int h, GP_Pixel pixel);
+ GP_Coord x, GP_Coord y,
+ GP_Size w, GP_Size h, GP_Pixel pixel);
void GP_TFillSymbol(GP_Context *context, GP_SymbolType sym,
- int x, int y, int w, int h, GP_Pixel pixel);
+ GP_Coord x, GP_Coord y,
+ GP_Size w, GP_Size h, GP_Pixel pixel);
#endif /* GP_SYMBOL_H */
diff --git a/include/gfx/GP_Tetragon.h b/include/gfx/GP_Tetragon.h
index 3f9d027..687ed7e 100644
--- a/include/gfx/GP_Tetragon.h
+++ b/include/gfx/GP_Tetragon.h
@@ -28,16 +28,20 @@
#include "core/GP_Context.h"
-void GP_Tetragon(GP_Context *context, int x0, int y0, int x1, int y1,
- int x2, int y2, int x3, int y3, GP_Pixel pixel);
+void GP_Tetragon(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Coord x2, GP_Coord y2,
+ GP_Coord x3, GP_Coord y3, GP_Pixel pixel);
-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_TTetragon(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Coord x2, GP_Coord y2,
+ GP_Coord x3, GP_Coord 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_FillTetragon(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Coord x2, GP_Coord y2,
+ GP_Coord x3, GP_Coord 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);
+void GP_TFillTetragon(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Coord x2, GP_Coord y2,
+ GP_Coord x3, GP_Coord y3, GP_Pixel pixel);
#endif /* GP_TETRAGON_H */
diff --git a/include/gfx/GP_Triangle.h b/include/gfx/GP_Triangle.h
index 128a721..7703a5f 100644
--- a/include/gfx/GP_Triangle.h
+++ b/include/gfx/GP_Triangle.h
@@ -28,16 +28,20 @@
#include "core/GP_Context.h"
-void GP_Triangle(GP_Context *context, int x0, int y0, int x1, int y1,
- int x2, int y2, GP_Pixel pixel);
+void GP_Triangle(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1,
+ GP_Coord x2, GP_Coord y2, GP_Pixel pixel);
-void GP_TTriangle(GP_Context *context, int x0, int y0, int x1, int y1,
- int x2, int y2, GP_Pixel pixel);
+void GP_TTriangle(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1,
+ GP_Coord x2, GP_Coord 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_FillTriangle(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1,
+ GP_Coord x2, GP_Coord 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);
+void GP_TFillTriangle(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1,
+ GP_Coord x2, GP_Coord y2, GP_Pixel pixel);
#endif /* GP_TRIANGLE_H */
diff --git a/include/gfx/GP_VLine.h b/include/gfx/GP_VLine.h
index 9e857b4..3cf6085 100644
--- a/include/gfx/GP_VLine.h
+++ b/include/gfx/GP_VLine.h
@@ -28,15 +28,17 @@
#include "core/GP_Context.h"
-void GP_VLineXYY(GP_Context *context, int x, int y0, int y1, GP_Pixel pixel);
+void GP_VLineXYY(GP_Context *context, GP_Coord x, GP_Coord y0,
+ GP_Coord y1, GP_Pixel pixel);
-void GP_VLineXYH(GP_Context *context, int x, int y,
- unsigned int height, GP_Pixel pixel);
+void GP_VLineXYH(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Size height, GP_Pixel pixel);
-void GP_TVLineXYY(GP_Context *context, int x, int y0, int y1, GP_Pixel pixel);
+void GP_TVLineXYY(GP_Context *context, GP_Coord x, GP_Coord y0,
+ GP_Coord y1, GP_Pixel pixel);
-void GP_TVLineXYH(GP_Context *context, int x, int y,
- unsigned int height, GP_Pixel pixel);
+void GP_TVLineXYH(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Size height, GP_Pixel pixel);
/* default argument set is XYY */
#define GP_VLine GP_VLineXYY
diff --git a/libs/gfx/GP_Circle.c b/libs/gfx/GP_Circle.c
index 4e92243..e92d8cc 100644
--- a/libs/gfx/GP_Circle.c
+++ b/libs/gfx/GP_Circle.c
@@ -24,32 +24,28 @@
*****************************************************************************/
#include "GP_Gfx.h"
-#include "algo/Circle.algo.h"
#include "core/GP_FnPerBpp.h"
+#include "core/GP_DefFnPerBpp.h"
+
+#include "algo/Circle.algo.h"
/* Generate drawing functions for various bit depths. */
-DEF_CIRCLE_FN(GP_Circle1bpp, GP_Context *, GP_Pixel, GP_PutPixel1bpp)
-DEF_CIRCLE_FN(GP_Circle2bpp, GP_Context *, GP_Pixel, GP_PutPixel2bpp)
-DEF_CIRCLE_FN(GP_Circle4bpp, GP_Context *, GP_Pixel, GP_PutPixel4bpp)
-DEF_CIRCLE_FN(GP_Circle8bpp, GP_Context *, GP_Pixel, GP_PutPixel8bpp)
-DEF_CIRCLE_FN(GP_Circle16bpp, GP_Context *, GP_Pixel, GP_PutPixel16bpp)
-DEF_CIRCLE_FN(GP_Circle24bpp, GP_Context *, GP_Pixel, GP_PutPixel24bpp)
-DEF_CIRCLE_FN(GP_Circle32bpp, GP_Context *, GP_Pixel, GP_PutPixel32bpp)
+GP_DEF_DRAW_FN_PER_BPP(GP_Circle, DEF_CIRCLE_FN)
-void GP_Circle(GP_Context *context, int xcenter, int ycenter,
- unsigned int r, GP_Pixel pixel)
+void GP_Circle(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size r, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
- GP_FN_PER_BPP(GP_Circle, context->bpp, context,
- xcenter, ycenter, r, pixel);
+ GP_FN_PER_BPP_CONTEXT(GP_Circle, context, context,
+ xcenter, ycenter, r, pixel);
}
-void GP_TCircle(GP_Context *context, int xcenter, int ycenter,
- unsigned int r, GP_Pixel pixel)
+void GP_TCircle(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size r, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
-
+
GP_TRANSFORM_POINT(context, xcenter, ycenter);
GP_Circle(context, xcenter, ycenter, r, pixel);
@@ -58,25 +54,19 @@ void GP_TCircle(GP_Context *context, int xcenter, int ycenter,
#include "algo/FillCircle.algo.h"
/* Generate drawing functions for various bit depths. */
-DEF_FILLCIRCLE_FN(GP_FillCircle1bpp, GP_Context *, GP_Pixel, GP_HLine1bpp)
-DEF_FILLCIRCLE_FN(GP_FillCircle2bpp, GP_Context *, GP_Pixel, GP_HLine2bpp)
-DEF_FILLCIRCLE_FN(GP_FillCircle4bpp, GP_Context *, GP_Pixel, GP_HLine4bpp)
-DEF_FILLCIRCLE_FN(GP_FillCircle8bpp, GP_Context *, GP_Pixel, GP_HLine8bpp)
-DEF_FILLCIRCLE_FN(GP_FillCircle16bpp, GP_Context *, GP_Pixel, GP_HLine16bpp)
-DEF_FILLCIRCLE_FN(GP_FillCircle24bpp, GP_Context *, GP_Pixel, GP_HLine24bpp)
-DEF_FILLCIRCLE_FN(GP_FillCircle32bpp, GP_Context *, GP_Pixel, GP_HLine32bpp)
+GP_DEF_FILL_FN_PER_BPP(GP_FillCircle, DEF_FILLCIRCLE_FN)
-void GP_FillCircle(GP_Context *context, int xcenter, int ycenter,
- unsigned int r, GP_Pixel pixel)
+void GP_FillCircle(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size r, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
- GP_FN_PER_BPP(GP_FillCircle, context->bpp, context,
- xcenter, ycenter, r, pixel);
+ GP_FN_PER_BPP_CONTEXT(GP_FillCircle, context, context,
+ xcenter, ycenter, r, pixel);
}
-void GP_TFillCircle(GP_Context *context, int xcenter, int ycenter,
- unsigned int r, GP_Pixel pixel)
+void GP_TFillCircle(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size r, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
diff --git a/libs/gfx/GP_Ellipse.c b/libs/gfx/GP_Ellipse.c
index 701f9bb..bbd3bdf 100644
--- a/libs/gfx/GP_Ellipse.c
+++ b/libs/gfx/GP_Ellipse.c
@@ -24,33 +24,29 @@
*****************************************************************************/
#include "GP_Gfx.h"
-#include "algo/Ellipse.algo.h"
#include "core/GP_FnPerBpp.h"
+#include "core/GP_DefFnPerBpp.h"
+
+#include "algo/Ellipse.algo.h"
/* Generate drawing functions for various bit depths. */
-DEF_ELLIPSE_FN(GP_Ellipse1bpp, GP_Context *, GP_Pixel, GP_PutPixel1bpp);
-DEF_ELLIPSE_FN(GP_Ellipse2bpp, GP_Context *, GP_Pixel, GP_PutPixel2bpp);
-DEF_ELLIPSE_FN(GP_Ellipse4bpp, GP_Context *, GP_Pixel, GP_PutPixel4bpp);
-DEF_ELLIPSE_FN(GP_Ellipse8bpp, GP_Context *, GP_Pixel, GP_PutPixel8bpp);
-DEF_ELLIPSE_FN(GP_Ellipse16bpp, GP_Context *, GP_Pixel, GP_PutPixel16bpp);
-DEF_ELLIPSE_FN(GP_Ellipse24bpp, GP_Context *, GP_Pixel, GP_PutPixel24bpp);
-DEF_ELLIPSE_FN(GP_Ellipse32bpp, GP_Context *, GP_Pixel, GP_PutPixel32bpp);
+GP_DEF_DRAW_FN_PER_BPP(GP_Ellipse, DEF_ELLIPSE_FN)
-void GP_Ellipse(GP_Context *context, int xcenter, int ycenter,
- unsigned int a, unsigned int b, GP_Pixel pixel)
+void GP_Ellipse(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size a, GP_Size b, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
- GP_FN_PER_BPP(GP_Ellipse, context->bpp, context,
- xcenter, ycenter, a, b, pixel);
+ GP_FN_PER_BPP_CONTEXT(GP_Ellipse, context, context,
+ xcenter, ycenter, a, b, pixel);
}
-void GP_TEllipse(GP_Context *context, int xcenter, int ycenter,
- unsigned int a, unsigned int b, GP_Pixel pixel)
+void GP_TEllipse(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size a, GP_Size b, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
- /* recalculate center point and swap a and b when axes are swapped */
+ /* recalculate center poGP_Coord and swap a and b when axes are swapped */
GP_TRANSFORM_POINT(context, xcenter, ycenter);
GP_TRANSFORM_SWAP(context, a, b);
@@ -60,25 +56,19 @@ void GP_TEllipse(GP_Context *context, int xcenter, int ycenter,
#include "algo/FillEllipse.algo.h"
/* Generate drawing functions for various bit depths. */
-DEF_FILLELLIPSE_FN(GP_FillEllipse1bpp, GP_Context *, GP_Pixel, GP_HLine1bpp)
-DEF_FILLELLIPSE_FN(GP_FillEllipse2bpp, GP_Context *, GP_Pixel, GP_HLine2bpp)
-DEF_FILLELLIPSE_FN(GP_FillEllipse4bpp, GP_Context *, GP_Pixel, GP_HLine4bpp)
-DEF_FILLELLIPSE_FN(GP_FillEllipse8bpp, GP_Context *, GP_Pixel, GP_HLine8bpp)
-DEF_FILLELLIPSE_FN(GP_FillEllipse16bpp, GP_Context *, GP_Pixel, GP_HLine16bpp)
-DEF_FILLELLIPSE_FN(GP_FillEllipse24bpp, GP_Context *, GP_Pixel, GP_HLine24bpp)
-DEF_FILLELLIPSE_FN(GP_FillEllipse32bpp, GP_Context *, GP_Pixel, GP_HLine32bpp)
+GP_DEF_FILL_FN_PER_BPP(GP_FillEllipse, DEF_FILLELLIPSE_FN)
-void GP_FillEllipse(GP_Context *context, int xcenter, int ycenter,
- unsigned int a, unsigned int b, GP_Pixel pixel)
+void GP_FillEllipse(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size a, GP_Size b, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
- GP_FN_PER_BPP(GP_FillEllipse, context->bpp, context,
- xcenter, ycenter, a, b, pixel);
+ GP_FN_PER_BPP_CONTEXT(GP_FillEllipse, context, context,
+ xcenter, ycenter, a, b, pixel);
}
-void GP_TFillEllipse(GP_Context *context, int xcenter, int ycenter,
- unsigned int a, unsigned int b, GP_Pixel pixel)
+void GP_TFillEllipse(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
+ GP_Size a, GP_Size b, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
diff --git a/libs/gfx/GP_HLine.c b/libs/gfx/GP_HLine.c
index ede37ef..3d51cc4 100644
--- a/libs/gfx/GP_HLine.c
+++ b/libs/gfx/GP_HLine.c
@@ -28,22 +28,29 @@
#include "core/GP_FnPerBpp.h"
/* Generate drawing functions for various bit depths. */
-DEF_HLINE_BU_FN(GP_HLine1bpp, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels1bpp)
-DEF_HLINE_BU_FN(GP_HLine2bpp, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels2bpp)
-DEF_HLINE_BU_FN(GP_HLine4bpp, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels4bpp)
-DEF_HLINE_FN(GP_HLine8bpp, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels8bpp)
-DEF_HLINE_FN(GP_HLine16bpp, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels16bpp)
-DEF_HLINE_FN(GP_HLine24bpp, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels24bpp)
-DEF_HLINE_FN(GP_HLine32bpp, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels32bpp)
-void GP_HLineXXY(GP_Context *context, int x0, int x1, int y, GP_Pixel pixel)
+//TODO: BIT ENDIANESS
+DEF_HLINE_BU_FN(GP_HLine_1BPP_LE, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels1bpp)
+DEF_HLINE_BU_FN(GP_HLine_1BPP_BE, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels1bpp)
+DEF_HLINE_BU_FN(GP_HLine_2BPP_LE, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels2bpp)
+DEF_HLINE_BU_FN(GP_HLine_2BPP_BE, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels2bpp)
+DEF_HLINE_BU_FN(GP_HLine_4BPP_LE, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels2bpp)
+DEF_HLINE_BU_FN(GP_HLine_4BPP_BE, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels2bpp)
+
+DEF_HLINE_FN(GP_HLine_8BPP, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels8bpp)
+DEF_HLINE_FN(GP_HLine_16BPP, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels16bpp)
+DEF_HLINE_FN(GP_HLine_24BPP, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels24bpp)
+DEF_HLINE_FN(GP_HLine_32BPP, GP_Context *, GP_Pixel, GP_PIXEL_ADDR, GP_WritePixels32bpp)
+
+void GP_HLineXXY(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
- GP_FN_PER_BPP(GP_HLine, context->bpp, context, x0, x1, y, pixel);
+ GP_FN_PER_BPP_CONTEXT(GP_HLine, context, context, x0, x1, y, pixel);
}
-void GP_HLineXYW(GP_Context *context, int x, int y, unsigned int w,
+void GP_HLineXYW(GP_Context *context, GP_Coord x, GP_Coord y, GP_Size w,
GP_Pixel pixel)
{
/* zero width: do not draw anything */
@@ -53,7 +60,8 @@ void GP_HLineXYW(GP_Context *context, int x, int y, unsigned int w,
GP_HLineXXY(context, x, x + w - 1, y, pixel);
}
-void GP_THLineXXY(GP_Context *context, int x0, int x1, int y, GP_Pixel pixel)
+void GP_THLineXXY(GP_Context *context, GP_Coord x0, GP_Coord x1,
+ GP_Coord y, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
@@ -70,7 +78,7 @@ void GP_THLineXXY(GP_Context *context, int x0, int x1, int y, GP_Pixel pixel)
}
}
-void GP_THLineXYW(GP_Context *context, int x, int y, unsigned int w,
+void GP_THLineXYW(GP_Context *context, GP_Coord x, GP_Coord y, GP_Size w,
GP_Pixel pixel)
{
/* zero width: do not draw anything */
diff --git a/libs/gfx/GP_Line.c b/libs/gfx/GP_Line.c
index 21066b1..d5dda97 100644
--- a/libs/gfx/GP_Line.c
+++ b/libs/gfx/GP_Line.c
@@ -24,31 +24,24 @@
*****************************************************************************/
#include "GP_Gfx.h"
-#include "algo/Line.algo.h"
#include "core/GP_FnPerBpp.h"
+#include "core/GP_DefFnPerBpp.h"
+
+#include "algo/Line.algo.h"
/* Generate drawing functions for various bit depths. */
-DEF_LINE_FN(GP_Line1bpp_LE, GP_Context *, GP_Pixel, GP_PutPixel1bpp_LE)
-DEF_LINE_FN(GP_Line2bpp_LE, GP_Context *, GP_Pixel, GP_PutPixel2bpp_LE)
-DEF_LINE_FN(GP_Line4bpp_LE, GP_Context *, GP_Pixel, GP_PutPixel4bpp_LE)
-DEF_LINE_FN(GP_Line1bpp_BE, GP_Context *, GP_Pixel, GP_PutPixel1bpp_BE)
-DEF_LINE_FN(GP_Line2bpp_BE, GP_Context *, GP_Pixel, GP_PutPixel2bpp_BE)
-DEF_LINE_FN(GP_Line4bpp_BE, GP_Context *, GP_Pixel, GP_PutPixel4bpp_BE)
-DEF_LINE_FN(GP_Line8bpp, GP_Context *, GP_Pixel, GP_PutPixel8bpp)
-DEF_LINE_FN(GP_Line16bpp, GP_Context *, GP_Pixel, GP_PutPixel16bpp)
-DEF_LINE_FN(GP_Line24bpp, GP_Context *, GP_Pixel, GP_PutPixel24bpp)
-DEF_LINE_FN(GP_Line32bpp, GP_Context *, GP_Pixel, GP_PutPixel32bpp)
+GP_DEF_DRAW_FN_PER_BPP(GP_Line, DEF_LINE_FN)
-void GP_Line(GP_Context *context, int x0, int y0, int x1, int y1,
- GP_Pixel pixel)
+void GP_Line(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
- GP_FN_PER_BPP(GP_Line, context->bpp, context, x0, y0, x1, y1, pixel);
+ GP_FN_PER_BPP_CONTEXT(GP_Line, context, context, x0, y0, x1, y1, pixel);
}
-void GP_TLine(GP_Context *context, int x0, int y0, int x1, int y1,
- GP_Pixel pixel)
+void GP_TLine(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
diff --git a/libs/gfx/GP_Polygon.c b/libs/gfx/GP_Polygon.c
index bf47baf..1bf5dc7 100644
--- a/libs/gfx/GP_Polygon.c
+++ b/libs/gfx/GP_Polygon.c
@@ -29,15 +29,15 @@
#include <stdlib.h>
struct GP_PolygonEdge {
- int startx, starty;
- int endx, endy;
- int dx, dy;
+ GP_Coord startx, starty;
+ GP_Coord endx, endy;
+ GP_Coord dx, dy;
};
struct GP_Polygon {
struct GP_PolygonEdge *edges;
- int edge_count;
- int ymin, ymax;
+ GP_Coord edge_count;
+ GP_Coord ymin, ymax;
};
#define GP_POLYGON_INITIALIZER { @@ -48,7 +48,7 @@ struct GP_Polygon {
}
static void GP_InitEdge(struct GP_PolygonEdge *edge,
- int x1, int y1, int x2, int y2)
+ GP_Coord x1, GP_Coord y1, GP_Coord x2, GP_Coord y2)
{
if (y1 < y2) { /* coords are top-down, correct */
edge->startx = x1;
@@ -66,7 +66,8 @@ static void GP_InitEdge(struct GP_PolygonEdge *edge,
edge->dy = edge->endy - edge->starty;
}
-static void GP_AddEdge(struct GP_Polygon *poly, int x1, int y1, int x2, int y2)
+static void GP_AddEdge(struct GP_Polygon *poly, GP_Coord x1, GP_Coord y1,
+ GP_Coord x2, GP_Coord y2)
{
struct GP_PolygonEdge *edge = poly->edges + poly->edge_count;
@@ -78,7 +79,7 @@ static void GP_AddEdge(struct GP_Polygon *poly, int x1, int y1, int x2, int y2)
poly->ymax = GP_MAX(poly->ymax, edge->endy);
}
-static int GP_CompareEdges(const void *edge1, const void *edge2)
+static GP_Coord GP_CompareEdges(const void *edge1, const void *edge2)
{
struct GP_PolygonEdge *e1 = (struct GP_PolygonEdge *) edge1;
struct GP_PolygonEdge *e2 = (struct GP_PolygonEdge *) edge2;
@@ -96,15 +97,15 @@ static int GP_CompareEdges(const void *edge1, const void *edge2)
return 0;
}
-static void GP_LoadPolygon(struct GP_Polygon *poly, int vertex_count,
- const int *xy)
+static void GP_LoadPolygon(struct GP_Polygon *poly, GP_Coord vertex_count,
+ const GP_Coord *xy)
{
poly->edge_count = 0;
poly->edges = calloc(sizeof(struct GP_PolygonEdge),
vertex_count);
- int i;
- int coord_count = 2*vertex_count - 2;
+ GP_Coord i;
+ GP_Coord coord_count = 2*vertex_count - 2;
for (i = 0; i < coord_count; i+=2) {
/* add the edge, unless it is horizontal */
@@ -133,13 +134,13 @@ static void GP_ResetPolygon(struct GP_Polygon *poly)
}
/*
- * Finds an X coordinate of an intersection of the edge
+ * Finds an X coordinate of an GP_Coordersection of the edge
* with the given Y line.
*/
-static inline int GP_FindIntersection(int y, const struct GP_PolygonEdge *edge)
+static inline GP_Coord GP_FindIntersection(GP_Coord y, const struct GP_PolygonEdge *edge)
{
- int edge_y = y - edge->starty; /* Y relative to the edge */
- int x = edge->startx;
+ GP_Coord edge_y = y - edge->starty; /* Y relative to the edge */
+ GP_Coord x = edge->startx;
if (edge->dx > 0) {
while (edge->startx*edge->dy + edge_y*edge->dx > x*edge->dy)
@@ -152,37 +153,37 @@ static inline int GP_FindIntersection(int y, const struct GP_PolygonEdge *edge)
return x;
}
-void GP_FillPolygon(GP_Context *context, int vertex_count, const int *xy,
+void GP_FillPolygon(GP_Context *context, GP_Coord vertex_count, const GP_Coord *xy,
GP_Pixel pixel)
{
struct GP_Polygon poly = GP_POLYGON_INITIALIZER;
GP_LoadPolygon(&poly, vertex_count, xy);
- int y, startx, endx;
- int startx_prev = -INT_MAX;
- int endx_prev = INT_MAX;
+ GP_Coord y, startx, endx;
+ GP_Coord startx_prev = -INT_MAX;
+ GP_Coord endx_prev = INT_MAX;
for (y = poly.ymin; y <= poly.ymax; y++) {
startx = INT_MAX;
endx = 0;
- int i;
+ GP_Coord i;
for (i = 0; i < poly.edge_count; i++) {
struct GP_PolygonEdge *edge = poly.edges + i;
if (y < edge->starty || y > edge->endy)
continue;
- int inter = GP_FindIntersection(y, edge);
+ GP_Coord GP_Coorder = GP_FindIntersection(y, edge);
- startx = GP_MIN(startx, inter);
- endx = GP_MAX(endx, inter);
+ startx = GP_MIN(startx, GP_Coorder);
+ endx = GP_MAX(endx, GP_Coorder);
if (y != edge->endy) {
- inter = GP_FindIntersection(y + 1, edge);
- startx = GP_MIN(startx, inter);
- endx = GP_MAX(endx, inter);
+ GP_Coorder = GP_FindIntersection(y + 1, edge);
+ startx = GP_MIN(startx, GP_Coorder);
+ endx = GP_MAX(endx, GP_Coorder);
}
}
diff --git a/libs/gfx/GP_Rect.c b/libs/gfx/GP_Rect.c
index 52e3a36..9f1fabe 100644
--- a/libs/gfx/GP_Rect.c
+++ b/libs/gfx/GP_Rect.c
@@ -25,8 +25,8 @@
#include "GP_Gfx.h"
-void GP_RectXYXY(GP_Context *context, int x0, int y0, int x1, int y1,
- GP_Pixel pixel)
+void GP_RectXYXY(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
@@ -36,8 +36,8 @@ void GP_RectXYXY(GP_Context *context, int x0, int y0, int x1, int y1,
GP_VLine(context, x1, y0, y1, pixel);
}
-void GP_RectXYWH(GP_Context *context, int x, int y,
- unsigned int w, unsigned int h, GP_Pixel pixel)
+void GP_RectXYWH(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Size w, GP_Size h, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
@@ -47,8 +47,8 @@ void GP_RectXYWH(GP_Context *context, int x, int y,
GP_VLine(context, x + w, y, y + h, pixel);
}
-void GP_TRectXYXY(GP_Context *context, int x0, int y0, int x1, int y1,
- GP_Pixel pixel)
+void GP_TRectXYXY(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
@@ -58,27 +58,27 @@ void GP_TRectXYXY(GP_Context *context, int x0, int y0, int x1, int y1,
GP_RectXYXY(context, x0, y0, x1, y1, pixel);
}
-void GP_TRectXYWH(GP_Context *context, int x, int y,
- unsigned int w, unsigned int h, GP_Pixel pixel)
+void GP_TRectXYWH(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Size w, GP_Size h, GP_Pixel pixel)
{
GP_TRectXYXY(context, x, y, x + w, y + h, pixel);
}
-void GP_FillRectXYXY(GP_Context *context, int x0, int y0, int x1, int y1,
- GP_Pixel pixel)
+void GP_FillRectXYXY(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
if (y0 > y1)
GP_SWAP(y0, y1);
- int y;
+ GP_Coord y;
for (y = y0; y <= y1; y++)
GP_HLine(context, x0, x1, y, pixel);
}
-void GP_FillRectXYWH(GP_Context *context, int x, int y,
- unsigned int w, unsigned int h, GP_Pixel pixel)
+void GP_FillRectXYWH(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Size w, GP_Size h, GP_Pixel pixel)
{
/* zero width/height: draw nothing */
if (w == 0 || h == 0)
@@ -87,8 +87,8 @@ void GP_FillRectXYWH(GP_Context *context, int x, int y,
return GP_FillRectXYXY(context, x, y, x + w - 1, y + h - 1, pixel);
}
-void GP_TFillRectXYXY(GP_Context *context, int x0, int y0,
- int x1, int y1, GP_Pixel pixel)
+void GP_TFillRectXYXY(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
@@ -98,8 +98,8 @@ void GP_TFillRectXYXY(GP_Context *context, int x0, int y0,
GP_FillRect(context, x0, y0, x1, y1, pixel);
}
-void GP_TFillRectXYWH(GP_Context *context, int x, int y,
- unsigned int w, unsigned int h, GP_Pixel pixel)
+void GP_TFillRectXYWH(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Size w, GP_Size h, GP_Pixel pixel)
{
/* zero width/height: draw nothing */
if (w == 0 || h == 0)
diff --git a/libs/gfx/GP_Symbol.c b/libs/gfx/GP_Symbol.c
index 1103673..7a7b44e 100644
--- a/libs/gfx/GP_Symbol.c
+++ b/libs/gfx/GP_Symbol.c
@@ -69,7 +69,7 @@
} while (0)
void GP_Symbol(GP_Context *context, GP_SymbolType sym,
- int x, int y, int w, int h, GP_Pixel pixel)
+ GP_Coord x, GP_Coord y, GP_Size w, GP_Size h, GP_Pixel pixel)
{
DO_DECREMENT(w);
DO_DECREMENT(h);
@@ -97,7 +97,7 @@ void GP_Symbol(GP_Context *context, GP_SymbolType sym,
}
void GP_FillSymbol(GP_Context *context, GP_SymbolType sym,
- int x, int y, int w, int h, GP_Pixel pixel)
+ GP_Coord x, GP_Coord y, GP_Size w, GP_Size h, GP_Pixel pixel)
{
DO_DECREMENT(w);
DO_DECREMENT(h);
@@ -125,7 +125,7 @@ void GP_FillSymbol(GP_Context *context, GP_SymbolType sym,
}
void GP_TSymbol(GP_Context *context, GP_SymbolType sym,
- int x, int y, int w, int h, GP_Pixel pixel)
+ GP_Coord x, GP_Coord y, GP_Size w, GP_Size h, GP_Pixel pixel)
{
DO_DECREMENT(w);
DO_DECREMENT(h);
@@ -153,7 +153,8 @@ void GP_TSymbol(GP_Context *context, GP_SymbolType sym,
}
void GP_TFillSymbol(GP_Context *context, GP_SymbolType sym,
- int x, int y, int w, int h, GP_Pixel pixel)
+ GP_Coord x, GP_Coord y,
+ GP_Size w, GP_Size h, GP_Pixel pixel)
{
DO_DECREMENT(w);
DO_DECREMENT(h);
diff --git a/libs/gfx/GP_Tetragon.c b/libs/gfx/GP_Tetragon.c
index ff9100e..f5f924a 100644
--- a/libs/gfx/GP_Tetragon.c
+++ b/libs/gfx/GP_Tetragon.c
@@ -25,8 +25,9 @@
#include "GP_Gfx.h"
-void GP_Tetragon(GP_Context *context, int x0, int y0, int x1, int y1,
- int x2, int y2, int x3, int y3, GP_Pixel pixel)
+void GP_Tetragon(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Coord x2, GP_Coord y2,
+ GP_Coord x3, GP_Coord y3, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
@@ -36,8 +37,9 @@ void GP_Tetragon(GP_Context *context, int x0, int y0, int x1, int y1,
GP_Line(context, x3, y3, x0, y0, pixel);
}
-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_TTetragon(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Coord x2, GP_Coord y2,
+ GP_Coord x3, GP_Coord y3, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
@@ -49,17 +51,19 @@ 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)
+void GP_FillTetragon(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Coord x2, GP_Coord y2,
+ GP_Coord x3, GP_Coord 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);
+ const GP_Coord xy[8] = { x0, y0, x1, y1, x2, y2, x3, y3 };
+ GP_FillPolygon(context, 4, 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)
+void GP_TFillTetragon(GP_Context* context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1, GP_Coord x2, GP_Coord y2,
+ GP_Coord x3, GP_Coord y3, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
@@ -68,6 +72,6 @@ void GP_TFillTetragon(GP_Context* context, int x0, int y0, int x1, int 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);
+ const GP_Coord xy[8] = { x0, y0, x1, y1, x2, y2, x3, y3 };
+ GP_FillPolygon(context, 4, xy, pixel);
}
diff --git a/libs/gfx/GP_Triangle.c b/libs/gfx/GP_Triangle.c
index 46f6939..10725ec 100644
--- a/libs/gfx/GP_Triangle.c
+++ b/libs/gfx/GP_Triangle.c
@@ -25,8 +25,9 @@
#include "GP_Gfx.h"
-void GP_Triangle(GP_Context *context, int x0, int y0, int x1, int y1,
- int x2, int y2, GP_Pixel pixel)
+void GP_Triangle(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1,
+ GP_Coord x2, GP_Coord y2, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
@@ -35,8 +36,9 @@ void GP_Triangle(GP_Context *context, int x0, int y0, int x1, int y1,
GP_Line(context, x1, y1, x2, y2, pixel);
}
-void GP_TTriangle(GP_Context *context, int x0, int y0, int x1, int y1,
- int x2, int y2, GP_Pixel pixel)
+void GP_TTriangle(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1,
+ GP_Coord x2, GP_Coord y2, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
@@ -47,17 +49,19 @@ 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)
+void GP_FillTriangle(GP_Context *context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1,
+ GP_Coord x2, GP_Coord y2, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
- int coords[6] = { x0, y0, x1, y1, x2, y2 };
+ const GP_Coord 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)
+void GP_TFillTriangle(GP_Context* context, GP_Coord x0, GP_Coord y0,
+ GP_Coord x1, GP_Coord y1,
+ GP_Coord x2, GP_Coord y2, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
@@ -65,6 +69,6 @@ void GP_TFillTriangle(GP_Context* context, int x0, int y0, int x1, int y1,
GP_TRANSFORM_POINT(context, x1, y1);
GP_TRANSFORM_POINT(context, x2, y2);
- int coords[6] = { x0, y0, x1, y1, x2, y2 };
+ const GP_Coord coords[6] = { x0, y0, x1, y1, x2, y2 };
GP_FillPolygon(context, 3, coords, pixel);
}
diff --git a/libs/gfx/GP_VLine.c b/libs/gfx/GP_VLine.c
index 7a27768..91d26da 100644
--- a/libs/gfx/GP_VLine.c
+++ b/libs/gfx/GP_VLine.c
@@ -24,27 +24,24 @@
*****************************************************************************/
#include "GP_Gfx.h"
-#include "algo/VLine.algo.h"
#include "core/GP_FnPerBpp.h"
+#include "core/GP_DefFnPerBpp.h"
+
+#include "algo/VLine.algo.h"
/* Generate drawing functions for various bit depths. */
-DEF_VLINE_FN(GP_VLine1bpp, GP_Context *, GP_Pixel, GP_PutPixel1bpp)
-DEF_VLINE_FN(GP_VLine2bpp, GP_Context *, GP_Pixel, GP_PutPixel2bpp)
-DEF_VLINE_FN(GP_VLine4bpp, GP_Context *, GP_Pixel, GP_PutPixel4bpp)
-DEF_VLINE_FN(GP_VLine8bpp, GP_Context *, GP_Pixel, GP_PutPixel8bpp)
-DEF_VLINE_FN(GP_VLine16bpp, GP_Context *, GP_Pixel, GP_PutPixel16bpp)
-DEF_VLINE_FN(GP_VLine24bpp, GP_Context *, GP_Pixel, GP_PutPixel24bpp)
-DEF_VLINE_FN(GP_VLine32bpp, GP_Context *, GP_Pixel, GP_PutPixel32bpp)
+GP_DEF_DRAW_FN_PER_BPP(GP_VLine, DEF_VLINE_FN)
-void GP_VLineXYY(GP_Context *context, int x, int y0, int y1, GP_Pixel pixel)
+void GP_VLineXYY(GP_Context *context, GP_Coord x, GP_Coord y0,
+ GP_Coord y1, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
- GP_FN_PER_BPP(GP_VLine, context->bpp, context, x, y0, y1, pixel);
+ GP_FN_PER_BPP_CONTEXT(GP_VLine, context, context, x, y0, y1, pixel);
}
-void GP_VLineXYH(GP_Context *context, int x, int y, unsigned int height,
- GP_Pixel pixel)
+void GP_VLineXYH(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Size height, GP_Pixel pixel)
{
/* zero height: do not draw anything */
if (height == 0)
@@ -53,7 +50,8 @@ void GP_VLineXYH(GP_Context *context, int x, int y, unsigned int height,
GP_VLineXYY(context, x, y, y + height - 1, pixel);
}
-void GP_TVLineXYY(GP_Context *context, int x, int y0, int y1, GP_Pixel pixel)
+void GP_TVLineXYY(GP_Context *context, GP_Coord x, GP_Coord y0,
+ GP_Coord y1, GP_Pixel pixel)
{
GP_CHECK_CONTEXT(context);
@@ -70,8 +68,8 @@ void GP_TVLineXYY(GP_Context *context, int x, int y0, int y1, GP_Pixel pixel)
}
}
-void GP_TVLineXYH(GP_Context *context, int x, int y, unsigned int height,
- GP_Pixel pixel)
+void GP_TVLineXYH(GP_Context *context, GP_Coord x, GP_Coord y,
+ GP_Size height, GP_Pixel pixel)
{
/* zero height: do not draw anything */
if (height == 0)
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_Context.h | 6 +--
.../core/GP_DefFnPerBpp.h | 62 ++++++++++----------
LICENSE => include/core/GP_Types.h | 19 +++++-
include/gfx/GP_Circle.h | 16 +++---
include/gfx/GP_Ellipse.h | 16 +++---
include/gfx/GP_Gfx.h | 1 +
include/gfx/GP_HLine.h | 59 +++++++++++++++----
include/gfx/GP_Line.h | 31 +++++-----
include/gfx/GP_Polygon.h | 10 ++--
include/gfx/GP_Rect.h | 32 +++++-----
include/gfx/GP_Symbol.h | 14 +++--
include/gfx/GP_Tetragon.h | 20 ++++---
include/gfx/GP_Triangle.h | 20 ++++---
include/gfx/GP_VLine.h | 14 +++--
libs/gfx/GP_Circle.c | 46 ++++++---------
libs/gfx/GP_Ellipse.c | 46 ++++++---------
libs/gfx/GP_HLine.c | 32 ++++++----
libs/gfx/GP_Line.c | 25 +++-----
libs/gfx/GP_Polygon.c | 55 +++++++++---------
libs/gfx/GP_Rect.c | 34 +++++-----
libs/gfx/GP_Symbol.c | 9 ++-
libs/gfx/GP_Tetragon.c | 28 +++++----
libs/gfx/GP_Triangle.c | 24 +++++---
libs/gfx/GP_VLine.c | 28 ++++-----
24 files changed, 346 insertions(+), 301 deletions(-)
copy libs/loaders/GP_PXMCommon.h => include/core/GP_DefFnPerBpp.h (55%)
copy LICENSE => include/core/GP_Types.h (83%)
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.")
1
0
[repo.or.cz] gfxprim.git branch generate updated: ecca5686f36c35b12f2bd72dd5ef16165da1ec8c
by metan 13 Jul '11
by metan 13 Jul '11
13 Jul '11
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, generate has been updated
via ecca5686f36c35b12f2bd72dd5ef16165da1ec8c (commit)
from 7d798834242fb298acd49b2c444843eaad852a93 (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/ecca5686f36c35b12f2bd72dd5ef16165da1…
commit ecca5686f36c35b12f2bd72dd5ef16165da1ec8c
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Wed Jul 13 21:40:12 2011 +0200
Fix some typos and warnings.
diff --git a/include/core/GP_GetPutPixel.h b/include/core/GP_GetPutPixel.h
index 7151a36..4f7a146 100644
--- a/include/core/GP_GetPutPixel.h
+++ b/include/core/GP_GetPutPixel.h
@@ -17,6 +17,7 @@
* Boston, MA 02110-1301 USA *
* *
* Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
+ * Copyright (C) 2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
@@ -41,10 +42,12 @@ GP_Pixel GP_GetPixel(const GP_Context *context, int x, int y);
/*
* Version of GetPixel without transformations nor border checking.
*/
-static inline GP_Pixel GP_GetPixel_Raw(GP_Context *context, int x, int y)
+static inline GP_Pixel GP_GetPixel_Raw(const GP_Context *context, int x, int y)
{
GP_FN_RET_PER_BPP(GP_GetPixel_Raw, context->bpp, context->bit_endian,
context, x, y);
+
+ GP_ABORT("Invalid context pixel type");
}
/*
@@ -56,7 +59,8 @@ void GP_PutPixel(GP_Context *context, int x, int y, GP_Pixel p);
/*
* Version of PutPixel without transformations nor border checking.
*/
-static inline void GP_PutPixel_Raw(GP_Context *context, int x, int y, GP_Pixel p)
+static inline void GP_PutPixel_Raw(GP_Context *context, int x, int y,
+ GP_Pixel p)
{
GP_FN_PER_BPP(GP_PutPixel_Raw, context->bpp, context->bit_endian,
context, x, y, p);
diff --git a/libs/core/GP_Blit.c b/libs/core/GP_Blit.c
index 251272d..a43c16f 100644
--- a/libs/core/GP_Blit.c
+++ b/libs/core/GP_Blit.c
@@ -57,8 +57,6 @@ void GP_Blit_Naive(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP
{
GP_CHECK(x1 >= 0);
GP_CHECK(y1 >= 0);
- GP_CHECK(w >= 0);
- GP_CHECK(h >= 0);
GP_CHECK(x1 + w <= GP_ContextW(c1));
GP_CHECK(y1 + h <= GP_ContextH(c1));
GP_CHECK(x2 >= 0);
@@ -66,8 +64,8 @@ void GP_Blit_Naive(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP
GP_CHECK(x2 + w <= GP_ContextW(c2));
GP_CHECK(y2 + h <= GP_ContextH(c2));
- for (int i = 0; i < w; i++)
- for (int j = 0; j < h; j++) {
+ for (GP_Size i = 0; i < w; i++)
+ for (GP_Size j = 0; j < h; j++) {
GP_Pixel p = GP_GetPixel(c1, x1 + i, y1 + j);
if (c1->pixel_type != c2->pixel_type)
p = GP_ConvertContextPixel(p, c1, c2);
diff --git a/libs/core/GP_WritePixel.c b/libs/core/GP_WritePixel.c
index 534094e..182a42e 100644
--- a/libs/core/GP_WritePixel.c
+++ b/libs/core/GP_WritePixel.c
@@ -23,6 +23,8 @@
* *
*****************************************************************************/
+#include <string.h>
+
#include "GP_Core.h"
#include "GP_WritePixel.h"
diff --git a/pylib/gfxprim/generators/core/gen_getputpixel.py b/pylib/gfxprim/generators/core/gen_getputpixel.py
index 6b96fc3..f360ec0 100644
--- a/pylib/gfxprim/generators/core/gen_getputpixel.py
+++ b/pylib/gfxprim/generators/core/gen_getputpixel.py
@@ -1,5 +1,6 @@
# Module generating C source and headers for get/putpixel
# 2011 - Tomas Gavenciak <gavento(a)ucw.cz>
+# 2011 - Cyril Hrubis <metan(a)ucw.cz>
from gfxprim.generators.utils import *
@@ -32,9 +33,9 @@ def gen_getpixel_bpp(size, size_suffix, header):
"of form 8BPP, 2BPP_LE and the like."
header.rbody(
"n/*** GP_GetPixel for {{ size_suffix }} ***/n"
- "static inline GP_Pixel GP_GetPixel_Raw_{{ size_suffix }}(GP_Context *c, int x, int y)n"
+ "static inline GP_Pixel GP_GetPixel_Raw_{{ size_suffix }}(const GP_Context *c, int x, int y)n"
"{n"
- " return GP_GET_BITS(GP_PIXEL_ADDR_OFFSET_{{ size_suffix }}(x) , {{ size }},n"
+ " return GP_GET_BITS(GP_PIXEL_ADDR_OFFSET_{{ size_suffix }}(x), {{ size }},n"
" *(GP_PIXEL_ADDR_{{ size_suffix}}(c, x, y)));n"
"}nn", size=size, size_suffix=size_suffix)
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_GetPutPixel.h | 8 ++++++--
libs/core/GP_Blit.c | 6 ++----
libs/core/GP_WritePixel.c | 2 ++
pylib/gfxprim/generators/core/gen_getputpixel.py | 5 +++--
4 files changed, 13 insertions(+), 8 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.")
1
0
[repo.or.cz] gfxprim.git branch generate updated: 7d798834242fb298acd49b2c444843eaad852a93
by metan 09 Jul '11
by metan 09 Jul '11
09 Jul '11
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, generate has been updated
via 7d798834242fb298acd49b2c444843eaad852a93 (commit)
from b7f10b82d579dfb7878335336b0d016f5343f793 (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/7d798834242fb298acd49b2c444843eaad85…
commit 7d798834242fb298acd49b2c444843eaad852a93
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Jul 9 22:44:00 2011 +0200
Started to fix surrounding library code.
Started to fix the library code to play well with
generated code. BEWARE UNTESTED.
diff --git a/include/core/GP_Pixel.h b/include/core/GP_Pixel.h
index 7250179..6282bf1 100644
--- a/include/core/GP_Pixel.h
+++ b/include/core/GP_Pixel.h
@@ -41,7 +41,7 @@ struct GP_Context;
/*
* GP_PixelType is typedef enum of PixelTypes,
*
- * each named GP_PIXEL_<TYPENAME>, such as GP_PIXEL_GRB888
+ * each named GP_PIXEL_<TYPENAME>, such as GP_PIXEL_RGB888
* see the beginning of GP_Pixel.gen.h for a complete list
*
* The type always contains GP_PIXEL_UNKNOWN = 0 and
@@ -52,8 +52,8 @@ struct GP_Context;
/*
* GP_Pixel is just uint32_t
*/
-
typedef uint32_t GP_Pixel;
+#define GP_PIXEL_BITS 32
/* Generated header */
#include "GP_Pixel.gen.h"
@@ -123,8 +123,8 @@ extern const GP_PixelTypeDescription const GP_PixelTypes[];
static inline const char *GP_PixelTypeName(GP_PixelType type)
{
- GP_CHECK(type < GP_PIXEL_MAX);
- return GP_PixelTypes[type].name;
+ GP_CHECK(type < GP_PIXEL_MAX);
+ return GP_PixelTypes[type].name;
}
/*
@@ -133,15 +133,16 @@ static inline const char *GP_PixelTypeName(GP_PixelType type)
static inline uint32_t GP_PixelSize(GP_PixelType type)
{
- GP_CHECK(type < GP_PIXEL_MAX);
- return GP_PixelTypes[type].size;
+ GP_CHECK(type < GP_PIXEL_MAX);
+ return GP_PixelTypes[type].size;
}
/*
* Print a human-readable representation of a pixel value to a string.
* Arguments as for snprintf().
*/
-static inline void GP_PixelSNPrint(char *buf, size_t len, GP_Pixel pixel, GP_PixelType type)
+static inline void GP_PixelSNPrint(char *buf, size_t len, GP_Pixel pixel,
+ GP_PixelType type)
{
GP_FN_PER_PIXELTYPE(GP_PixelSNPrint, type, buf, len, pixel);
}
@@ -156,4 +157,13 @@ static inline void GP_PixelPrint(GP_Pixel pixel, GP_PixelType type)
printf("%s", buf);
}
+/*
+ * Match pixel type to known pixel types.
+ *
+ * Returns either valid PixelType or GP_PIXEL_UNKNOWN
+ */
+GP_PixelType GP_PixelRGBMatch(GP_Pixel rmask, GP_Pixel gmask,
+ GP_Pixel bmask, GP_Pixel amask);
+
+
#endif /* GP_PIXEL_H */
diff --git a/libs/SDL/GP_SDL_Context.c b/libs/SDL/GP_SDL_Context.c
index 487476b..021b6e6 100644
--- a/libs/SDL/GP_SDL_Context.c
+++ b/libs/SDL/GP_SDL_Context.c
@@ -26,91 +26,22 @@
#include "GP.h"
#include "GP_SDL.h"
-/* Checks whether pixel color component masks in the given surface are equal
- * to specified. Returns nonzero if they match, zero otherwise.
- */
-static int check_pixel_masks(SDL_Surface *surf, unsigned int rmask,
- unsigned int gmask, unsigned int bmask, unsigned int amask)
-{
- return (surf->format->Rmask == rmask
- && surf->format->Gmask == gmask
- && surf->format->Bmask == bmask
- && surf->format->Ashift == amask);
-}
-
-/* Detects the pixel type of the SDL surface.
- * Returns the pixel type, or GP_PIXEL_UNKNOWN if the type was not recognized.
- */
-static enum GP_PixelType find_surface_pixel_type(SDL_Surface *surf)
-{
- switch (surf->format->BytesPerPixel) {
- case 1:
- if (check_pixel_masks(surf, 0, 0, 0, 0)) {
- return GP_PIXEL_PAL8;
- }
- break;
- case 2:
- if (check_pixel_masks(surf, 0x7c00, 0x03e0, 0x001f, 0)) {
- return GP_PIXEL_RGB555;
- }
- if (check_pixel_masks(surf, 0xf800, 0x07e0, 0x001f, 0)) {
- return GP_PIXEL_RGB565;
- }
- break;
- case 3:
- if (check_pixel_masks(surf, 0xff0000, 0xff00, 0xff, 0)) {
- return GP_PIXEL_RGB888;
- }
- if (check_pixel_masks(surf, 0xff, 0xff00, 0xff0000, 0)) {
- return GP_PIXEL_BGR888;
- }
- break;
- case 4:
- if (check_pixel_masks(surf, 0xff0000, 0xff00, 0xff, 0)) {
- return GP_PIXEL_XRGB8888;
- }
- if (check_pixel_masks(surf, 0xff, 0xff00, 0xff0000, 0)) {
- return GP_PIXEL_XBGR8888;
- }
- if (check_pixel_masks(surf, 0xff000000, 0xff0000, 0xff00, 0)) {
- return GP_PIXEL_RGBX8888;
- }
- if (check_pixel_masks(surf, 0xff00, 0xff0000, 0xff000000, 0)) {
- return GP_PIXEL_BGRX8888;
- }
- if (check_pixel_masks(surf, 0xff0000, 0xff00, 0xff, 0xff000000)) {
- return GP_PIXEL_ARGB8888;
- }
- if (check_pixel_masks(surf, 0xff, 0xff00, 0xff0000, 0xff000000)) {
- return GP_PIXEL_ABGR8888;
- }
- if (check_pixel_masks(surf, 0xff000000, 0xff0000, 0xff00, 0xff)) {
- return GP_PIXEL_RGBA8888;
- }
- if (check_pixel_masks(surf, 0xff00, 0xff0000, 0xff000000, 0xff)) {
- return GP_PIXEL_BGRA8888;
- }
- break;
-
- }
- return GP_PIXEL_UNKNOWN;
-
-}
-
GP_RetCode GP_SDL_ContextFromSurface(GP_Context *context, SDL_Surface *surf)
{
- if (surf == NULL || surf->pixels == NULL || context == NULL) {
+ if (surf == NULL || surf->pixels == NULL || context == NULL)
return GP_ENULLPTR;
- }
/* sanity checks on the SDL surface */
- if (surf->format->BytesPerPixel == 0 || surf->format->BytesPerPixel > 4) {
+ if (surf->format->BytesPerPixel == 0 || surf->format->BytesPerPixel > 4)
return GP_ENOIMPL;
- }
- enum GP_PixelType pixeltype = find_surface_pixel_type(surf);
- if (pixeltype == GP_PIXEL_UNKNOWN) {
+
+ enum GP_PixelType pixeltype = GP_PixelRGBMatch(surf->format->Rmask,
+ surf->format->Gmask,
+ surf->format->Bmask,
+ surf->format->Ashift);
+
+ if (pixeltype == GP_PIXEL_UNKNOWN)
return GP_ENOIMPL;
- }
/* basic structure and size */
context->pixels = surf->pixels;
diff --git a/libs/backends/GP_Backend_SDL.c b/libs/backends/GP_Backend_SDL.c
index 2cf4fe4..aac4a32 100644
--- a/libs/backends/GP_Backend_SDL.c
+++ b/libs/backends/GP_Backend_SDL.c
@@ -45,78 +45,6 @@ static int (*dyn_SDL_WaitEvent)(SDL_Event *);
/* User callbacks. */
static void (*GP_SDL_update_video_callback)(void) = NULL;
-/*
- * Checks whether pixel color component masks in the given surface are equal
- * to specified. Returns nonzero if they match, zero otherwise.
- */
-static int GP_SDL_CheckPixelMasks(SDL_Surface *surf, unsigned int rmask,
- unsigned int gmask, unsigned int bmask, unsigned int amask)
-{
- return (surf->format->Rmask == rmask
- && surf->format->Gmask == gmask
- && surf->format->Bmask == bmask
- && surf->format->Ashift == amask);
-}
-
-/*
- * Detects the pixel type of the SDL surface.
- * Returns the pixel type, or GP_PIXEL_UNKNOWN if the type was not recognized.
- */
-static enum GP_PixelType GP_SDL_FindSurfacePixelType(SDL_Surface *surf)
-{
- switch (surf->format->BytesPerPixel) {
- case 1:
- if (GP_SDL_CheckPixelMasks(surf, 0, 0, 0, 0)) {
- return GP_PIXEL_PAL8;
- }
- break;
- case 2:
- if (GP_SDL_CheckPixelMasks(surf, 0x7c00, 0x03e0, 0x001f, 0)) {
- return GP_PIXEL_RGB555;
- }
- if (GP_SDL_CheckPixelMasks(surf, 0xf800, 0x07e0, 0x001f, 0)) {
- return GP_PIXEL_RGB565;
- }
- break;
- case 3:
- if (GP_SDL_CheckPixelMasks(surf, 0xff0000, 0xff00, 0xff, 0)) {
- return GP_PIXEL_RGB888;
- }
- if (GP_SDL_CheckPixelMasks(surf, 0xff, 0xff00, 0xff0000, 0)) {
- return GP_PIXEL_BGR888;
- }
- break;
- case 4:
- if (GP_SDL_CheckPixelMasks(surf, 0xff0000, 0xff00, 0xff, 0)) {
- return GP_PIXEL_XRGB8888;
- }
- if (GP_SDL_CheckPixelMasks(surf, 0xff, 0xff00, 0xff0000, 0)) {
- return GP_PIXEL_XBGR8888;
- }
- if (GP_SDL_CheckPixelMasks(surf, 0xff000000, 0xff0000, 0xff00, 0)) {
- return GP_PIXEL_RGBX8888;
- }
- if (GP_SDL_CheckPixelMasks(surf, 0xff00, 0xff0000, 0xff000000, 0)) {
- return GP_PIXEL_BGRX8888;
- }
- if (GP_SDL_CheckPixelMasks(surf, 0xff0000, 0xff00, 0xff, 0xff000000)) {
- return GP_PIXEL_ARGB8888;
- }
- if (GP_SDL_CheckPixelMasks(surf, 0xff, 0xff00, 0xff0000, 0xff000000)) {
- return GP_PIXEL_ABGR8888;
- }
- if (GP_SDL_CheckPixelMasks(surf, 0xff000000, 0xff0000, 0xff00, 0xff)) {
- return GP_PIXEL_RGBA8888;
- }
- if (GP_SDL_CheckPixelMasks(surf, 0xff00, 0xff0000, 0xff000000, 0xff)) {
- return GP_PIXEL_BGRA8888;
- }
- break;
-
- }
- return GP_PIXEL_UNKNOWN;
-}
-
inline GP_RetCode GP_SDL_ContextFromSurface(
GP_Context *context, SDL_Surface *surf)
{
@@ -124,13 +52,16 @@ inline GP_RetCode GP_SDL_ContextFromSurface(
GP_CHECK(surf, "surface is NULL");
/* sanity checks on the SDL surface */
- if (surf->format->BytesPerPixel == 0 || surf->format->BytesPerPixel > 4) {
+ if (surf->format->BytesPerPixel == 0 || surf->format->BytesPerPixel > 4)
return GP_ENOIMPL;
- }
- enum GP_PixelType pixeltype = GP_SDL_FindSurfacePixelType(surf);
- if (pixeltype == GP_PIXEL_UNKNOWN) {
+
+ enum GP_PixelType pixeltype = GP_PixelRGBMatch(surf->format->Rmask,
+ surf->format->Gmask,
+ surf->format->Bmask,
+ surf->format->Ashift);
+
+ if (pixeltype == GP_PIXEL_UNKNOWN)
return GP_ENOIMPL;
- }
/* basic structure and size */
context->pixels = surf->pixels;
diff --git a/libs/core/GP_Pixel.c b/libs/core/GP_Pixel.c
new file mode 100644
index 0000000..d6553b1
--- /dev/null
+++ b/libs/core/GP_Pixel.c
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * 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 <string.h>
+
+#include "GP_Pixel.h"
+
+static const GP_PixelTypeChannel *get_channel(const GP_PixelTypeDescription *desc,
+ const char *name)
+{
+ unsigned int i;
+
+ for (i = 0; i < desc->numchannels; i++)
+ if (!strcmp(desc->channels[i].name, name))
+ return &desc->channels[i];
+
+ return NULL;
+}
+
+static int match(const GP_PixelTypeChannel *channel, GP_Pixel mask)
+{
+ if (channel == NULL)
+ return !mask;
+
+ GP_Pixel chmask = ~0;
+
+ chmask >>= (GP_PIXEL_BITS - channel->size);
+ chmask <<= channel->offset;
+
+ return (chmask == mask);
+}
+
+GP_PixelType GP_PixelRGBMatch(GP_Pixel rmask, GP_Pixel gmask,
+ GP_Pixel bmask, GP_Pixel amask)
+{
+ unsigned int i;
+
+ for (i = 0; i < GP_PIXEL_MAX; i++) {
+ int res;
+
+ const GP_PixelTypeChannel *r, *g, *b, *a;
+
+ r = get_channel(&GP_PixelTypes[i], "R");
+ g = get_channel(&GP_PixelTypes[i], "G");
+ b = get_channel(&GP_PixelTypes[i], "B");
+ a = get_channel(&GP_PixelTypes[i], "A");
+
+ res = match(r, rmask) && match(g, gmask) &&
+ match(b, bmask) && match(a, amask);
+
+ if (res)
+ return GP_PixelTypes[i].type;
+ }
+
+ return GP_PIXEL_UNKNOWN;
+}
diff --git a/libs/loaders/Makefile b/libs/loaders/Makefile
index 1e88e78..e753f5c 100644
--- a/libs/loaders/Makefile
+++ b/libs/loaders/Makefile
@@ -1,5 +1,5 @@
TOPDIR=../..
-CSOURCES=$(shell ls *.c)
+#CSOURCES=$(shell ls *.c)
LIBNAME=loaders
include $(TOPDIR)/include.mk
include $(TOPDIR)/lib.mk
diff --git a/pylib/gfxprim/generators/core/make_GP_Convert.py b/pylib/gfxprim/generators/core/make_GP_Convert.py
index dfd23dd..03b682c 100644
--- a/pylib/gfxprim/generators/core/make_GP_Convert.py
+++ b/pylib/gfxprim/generators/core/make_GP_Convert.py
@@ -20,7 +20,7 @@ def core_GP_Pixel_Scale_gen(h):
h.rhead(
"/* helper macros to transfer s1-bit value to s2-bit valuen"
" * NOTE: efficient and accurate for both up- and downscaling,n"
- " * WARNING: GP_SCALE_VAL requires constants numebrs as first two parametersn"
+ " * WARNING: GP_SCALE_VAL requires constants numbers as first two parametersn"
" */n"
"#define GP_SCALE_VAL(s1, s2, val) ( GP_SCALE_VAL_##s1##_##s2(val) )nn"
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_Pixel.h | 24 ++++--
libs/SDL/GP_SDL_Context.c | 87 ++-------------------
libs/backends/GP_Backend_SDL.c | 85 ++-------------------
libs/{backends/GP_Backend.c => core/GP_Pixel.c} | 79 +++++++++-----------
libs/loaders/Makefile | 2 +-
pylib/gfxprim/generators/core/make_GP_Convert.py | 2 +-
6 files changed, 71 insertions(+), 208 deletions(-)
copy libs/{backends/GP_Backend.c => core/GP_Pixel.c} (64%)
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.")
1
0
[repo.or.cz] gfxprim.git branch generate updated: b7f10b82d579dfb7878335336b0d016f5343f793
by gavento 13 Jun '11
by gavento 13 Jun '11
13 Jun '11
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, generate has been updated
via b7f10b82d579dfb7878335336b0d016f5343f793 (commit)
via 132422504ff084746df93675292ee937a946d105 (commit)
via 617420b08642f72170638b2f543022c61600e96c (commit)
via efa0c0660b9db3601452b32864d0ef114a72e0ce (commit)
via b5426313d22d110cc0d9f26d273c5e19c5632687 (commit)
via abbcc7e4e20f3d131b2c7fe46895089d2980dc94 (commit)
via 092a846fd82550f4435b5396a7e48e789afdd0bc (commit)
via 402eaabcf521cf1e6e0643b2d140e4b9dcf3f10a (commit)
via d1f7f07b180f153f0eb40e54230537e8495871e9 (commit)
via e22c5773aab5f5b5681f9f2d606ebd9eeb4fea7b (commit)
via 70a840f2dde4591281025f8acb0374004d8d0e44 (commit)
via fe2f2b950ec689827669756925914f61a9f584ab (commit)
via 85a6fffce341ae7b993b80fefecb97c1619636e4 (commit)
via ebd807bf4a3a9c1f916dff933c16536c4ef2261c (commit)
via d01f20fa8ffaa7959891751f12ef3195a7cfbde7 (commit)
via 2139339c8854d942378361854f6e1f7c5781b9b1 (commit)
via 777062b642ebcecb14a3a8944ff4afd25d145eb7 (commit)
via 6d267ad031a775ffb3e7e73a5357a7600e7b96f0 (commit)
via 50e68bdcafa2e379597a3c454343c4f3b2c7db73 (commit)
via e8872dfaab48d1f16b749fbd0ea698a6b7ce86ae (commit)
via d7551ce7958fc44a3a9e070258d3c8a45a23f755 (commit)
via 413daca73ab16f53c9fd81410c261bc7628d2e11 (commit)
from abf38d0ef10e4cd84391950b1595cfc60dcf3181 (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/b7f10b82d579dfb7878335336b0d016f5343…
commit b7f10b82d579dfb7878335336b0d016f5343f793
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Mon Jun 13 01:01:58 2011 +0200
Add test OBJs to CLEAN in tests.mk
diff --git a/tests.mk b/tests.mk
index 846e4f9..e4cf3bb 100644
--- a/tests.mk
+++ b/tests.mk
@@ -26,7 +26,7 @@ ${TESTSUITE_GEN}: $(filter-out ${TESTSUITE_GEN},${GENSOURCES}) ${GENHEADERS}
TESTSUITE_SRCS=$(wildcard *.test.c) ${GENSOURCES} ${GENHEADERS} ${GP_TESTLIB_SRCS}
INCLUDE+=../tests/common
TESTSUITE_OBJS=$(patsubst %.c,%.o,$(TESTSUITE_SRCS))
-CLEAN+=${TESTSUITE}
+CLEAN+=${TESTSUITE} ${TESTSUITE_OBJS}
TESTS+=${TESTSUITE}
${TESTSUITE}: ${TESTSUITE_OBJS}
http://repo.or.cz/w/gfxprim.git/commit/132422504ff084746df93675292ee937a946…
commit 132422504ff084746df93675292ee937a946d105
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Mon Jun 13 00:58:10 2011 +0200
Fix naive blit typo
diff --git a/libs/core/GP_Blit.c b/libs/core/GP_Blit.c
index 76c7a2c..251272d 100644
--- a/libs/core/GP_Blit.c
+++ b/libs/core/GP_Blit.c
@@ -23,6 +23,7 @@
#include "GP_Pixel.h"
#include "GP_GetPutPixel.h"
#include "GP_Context.h"
+#include "GP_Convert.h"
#include "GP_Blit.h"
/*
@@ -69,7 +70,7 @@ void GP_Blit_Naive(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP
for (int j = 0; j < h; j++) {
GP_Pixel p = GP_GetPixel(c1, x1 + i, y1 + j);
if (c1->pixel_type != c2->pixel_type)
- p = GP_GP_ConvertContextPixel(p, c1, c2);
+ p = GP_ConvertContextPixel(p, c1, c2);
GP_PutPixel(c2, x2 + i, y2 + j, p);
}
}
http://repo.or.cz/w/gfxprim.git/commit/617420b08642f72170638b2f543022c61600…
commit 617420b08642f72170638b2f543022c61600e96c
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Mon Jun 13 00:57:24 2011 +0200
Improve and extend GP_Convert gen. tests
diff --git a/pylib/gfxprim/generators/core/make_GP_Convert.py b/pylib/gfxprim/generators/core/make_GP_Convert.py
index 41637ca..dfd23dd 100644
--- a/pylib/gfxprim/generators/core/make_GP_Convert.py
+++ b/pylib/gfxprim/generators/core/make_GP_Convert.py
@@ -76,8 +76,26 @@ def core_GP_Convert_gen_h(c):
'{n'
' GP_Pixel p1 = GP_RandomColor(GP_PIXEL_{{ t.name }});n'
' GP_Pixel p2 = GP_ConvertPixel(p1, GP_PIXEL_{{ t.name }}, GP_PIXEL_RGBA8888);n'
- ' GP_Pixel p3 = GP_ConvertPixel(p1, GP_PIXEL_RGBA8888, GP_PIXEL_{{ t.name }});n'
- ' fail_unless(GP_EqualColors(p1, GP_PIXEL_{{ t.name }}, p3, GP_PIXEL_{{ t.name }}));n'
- ' fail_unless(GP_EqualColors(p1, GP_PIXEL_{{ t.name }}, p2, GP_PIXEL_{{ t.name }}));n'
- '}nn'
- 'GP_ENDTESTn', t=t)
+ ' GP_Pixel p3 = GP_ConvertPixel(p2, GP_PIXEL_RGBA8888, GP_PIXEL_{{ t.name }});n'
+ ' GP_CHECK_EqualColors(p1, GP_PIXEL_{{ t.name }}, p3, GP_PIXEL_{{ t.name }});n'
+ ' GP_CHECK_EqualColors(p1, GP_PIXEL_{{ t.name }}, p2, GP_PIXEL_RGBA8888);n'
+ '}n'
+ 'GP_ENDTESTnn', t=t)
+ c.rbody(
+ 'GP_TEST(WhiteStaysWhite_via_{{ t.name }}, "loop_start=0, loop_end=4")n'
+ '{n'
+ ' GP_Pixel p1 = GP_RGBToPixel(255, 255, 255, GP_PIXEL_RGB888);n'
+ ' GP_Pixel p2 = GP_RGB888ToPixel(p1, GP_PIXEL_{{ t.name }});n'
+ ' GP_Pixel p3 = GP_PixelToRGB888(p2, GP_PIXEL_{{ t.name }});n'
+ ' GP_CHECK_EqualColors(p1, GP_PIXEL_RGB888, p3, GP_PIXEL_RGB888);n'
+ '}n'
+ 'GP_ENDTESTnn', t=t)
+ c.rbody(
+ 'GP_TEST(BlackStaysBlack_via_{{ t.name }}, "loop_start=0, loop_end=4")n'
+ '{n'
+ ' GP_Pixel p1 = GP_RGBToPixel(0, 0, 0, GP_PIXEL_RGB888);n'
+ ' GP_Pixel p2 = GP_RGB888ToPixel(p1, GP_PIXEL_{{ t.name }});n'
+ ' GP_Pixel p3 = GP_PixelToRGB888(p2, GP_PIXEL_{{ t.name }});n'
+ ' GP_CHECK_EqualColors(p1, GP_PIXEL_RGB888, p3, GP_PIXEL_RGB888);n'
+ '}n'
+ 'GP_ENDTESTnn', t=t)
http://repo.or.cz/w/gfxprim.git/commit/efa0c0660b9db3601452b32864d0ef114a72…
commit efa0c0660b9db3601452b32864d0ef114a72e0ce
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Mon Jun 13 00:56:55 2011 +0200
Bix fix in pixel value scaling
DUH
diff --git a/pylib/gfxprim/generators/core/make_GP_Convert.py b/pylib/gfxprim/generators/core/make_GP_Convert.py
index 249763d..41637ca 100644
--- a/pylib/gfxprim/generators/core/make_GP_Convert.py
+++ b/pylib/gfxprim/generators/core/make_GP_Convert.py
@@ -26,11 +26,11 @@ def core_GP_Pixel_Scale_gen(h):
"{% for s1 in range(1,9) %}{% for s2 in range(1,9) %}"
"{% if s2>s1 %}"
- "#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) ((val) * {{ multcoef(s1, s2) }})n"
+ "#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) (((val) * {{ multcoef(s1, s2) }}) >> {{ (-s2) % s1 }})n"
"{% else %}"
"#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) ((val) >> {{ s1 - s2 }})n"
"{% endif %}"
- "{% endfor %}{% endfor %}", multcoef = lambda s1,s2: hex(sum([1<<i*s1 for i in range(s2/s1)]))
+ "{% endfor %}{% endfor %}", multcoef = lambda s1,s2: hex(sum([1<<(i*s1) for i in range((s2+s1-1)/s1)]))
)
http://repo.or.cz/w/gfxprim.git/commit/b5426313d22d110cc0d9f26d273c5e19c563…
commit b5426313d22d110cc0d9f26d273c5e19c5632687
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Mon Jun 13 00:56:17 2011 +0200
Minor header inclusion
diff --git a/include/core/GP_Convert.h b/include/core/GP_Convert.h
index aeb5acf..6dd9d61 100644
--- a/include/core/GP_Convert.h
+++ b/include/core/GP_Convert.h
@@ -25,6 +25,7 @@
#include "GP_Common.h"
#include "GP_Context.h"
+#include "GP_Pixel.h"
/* Generated headers */
#include "GP_Convert.gen.h"
http://repo.or.cz/w/gfxprim.git/commit/abbcc7e4e20f3d131b2c7fe46895089d2980…
commit abbcc7e4e20f3d131b2c7fe46895089d2980dc94
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Mon Jun 13 00:55:33 2011 +0200
Added hand-made smoke tests for GP_Convert
diff --git a/tests/core/GP_Convert.test.c b/tests/core/GP_Convert.test.c
new file mode 100644
index 0000000..3f80a3a
--- /dev/null
+++ b/tests/core/GP_Convert.test.c
@@ -0,0 +1,27 @@
+/*
+ * 2011 - Tomas Gavenciak <gavento(a)ucw.cz>
+ */
+
+#include "GP_Tests.h"
+#include "GP_Convert.h"
+#include "GP_TestingCore.h"
+
+GP_SUITE(GP_Convert)
+
+GP_TEST(BasicPixelConversions)
+{
+ GP_Pixel p1, p2;
+ p1 = GP_RGBAToPixel(255, 255, 255, 255, GP_PIXEL_RGBA8888);
+ fail_unless(p1 == 0xffffffff);
+ p1 = GP_RGBAToPixel(0, 0, 0, 0, GP_PIXEL_RGBA8888);
+ fail_unless(p1 == 0x0);
+ p1 = GP_RGBToPixel(0x12, 0x34, 0x56, GP_PIXEL_RGB888);
+ fail_unless(p1 == 0x563412);
+ GP_CHECK_EqualColors(p1, GP_PIXEL_RGB888, p1, GP_PIXEL_RGB888);
+
+ p1 = GP_RGB888ToPixel(GP_RGBToPixel(0x12, 0x34, 0x56, GP_PIXEL_RGB888), GP_PIXEL_V4);
+ p2 = GP_RGBAToPixel(0x12, 0x34, 0x56, 0x78, GP_PIXEL_V2);
+ GP_CHECK_EqualColors(p1, GP_PIXEL_V4, p2, GP_PIXEL_V2);
+}
+GP_ENDTEST
+
http://repo.or.cz/w/gfxprim.git/commit/092a846fd82550f4435b5396a7e48e789afd…
commit 092a846fd82550f4435b5396a7e48e789afdd0bc
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Mon Jun 13 00:54:19 2011 +0200
Extended pixel equality in tests, fixed GP_CHECK_EqualColors
but still TODO find better definition of color equality
diff --git a/tests/common/GP_TestingCore.c b/tests/common/GP_TestingCore.c
index afa2754..501a66a 100644
--- a/tests/common/GP_TestingCore.c
+++ b/tests/common/GP_TestingCore.c
@@ -43,11 +43,27 @@ void GP_RandomizeRect(GP_Context *context, GP_Coord x, GP_Coord y, GP_Size w, GP
GP_PutPixel(context, i + x, j + y, GP_RandomColor(context->pixel_type));
}
+/* TODO: Proper equality definition (currently almost ad-hoc */
int GP_EqualColors(GP_Pixel p1, GP_PixelType t1, GP_Pixel p2, GP_PixelType t2)
{
- GP_Pixel col1 = GP_PixelToRGBA8888(p1, t1);
- GP_Pixel col2 = GP_PixelToRGBA8888(p2, t2);
- return (col1 & 0xffffffff) == (col2 & 0xffffffff);
+ int size1 = GP_PixelTypes[t1].size;
+ int size2 = GP_PixelTypes[t2].size;
+
+ // Same type
+ if (t1 == t2)
+ return GP_GET_BITS(0, size1, p1) == GP_GET_BITS(0, size1, p2);
+
+ // t1 -> RGBA8888 -> t2
+ GP_Pixel conv1 = GP_RGBA8888ToPixel(GP_PixelToRGBA8888(p1, t1), t2);
+ if (GP_GET_BITS(0, size2, conv1) == GP_GET_BITS(0, size2, p2))
+ return 1;
+
+ // t2 -> RGBA8888 -> t1
+ GP_Pixel conv2 = GP_RGBA8888ToPixel(GP_PixelToRGBA8888(p2, t2), t1);
+ if (GP_GET_BITS(0, size1, conv2) == GP_GET_BITS(0, size1, p1))
+ return 1;
+
+ return 0;
}
int GP_EqualRects(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h,
diff --git a/tests/common/GP_TestingCore.h b/tests/common/GP_TestingCore.h
index 0e4b726..31d2d1f 100644
--- a/tests/common/GP_TestingCore.h
+++ b/tests/common/GP_TestingCore.h
@@ -52,8 +52,8 @@ int GP_EqualColors(GP_Pixel p1, GP_PixelType t1, GP_Pixel p2, GP_PixelType t2);
char b1[256], b2[256]; GP_PixelSNPrint(b1, 256, p1, t1); GP_PixelSNPrint(b2, 256, p2, t2); - GP_CHECK("Pixel colors %s and %s are not the same color.", b1, b2); - } while (0);
+ GP_ABORT("Pixels %s and %s are not the same color.", b1, b2); + } } while (0);
/*
* Compare two rectangles in two contexts. Return 1 on equal.
http://repo.or.cz/w/gfxprim.git/commit/402eaabcf521cf1e6e0643b2d140e4b9dcf3…
commit 402eaabcf521cf1e6e0643b2d140e4b9dcf3f10a
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Mon Jun 13 00:52:01 2011 +0200
Added GP_PixelSNPrint (similar to snprintf())
diff --git a/include/core/GP_Pixel.h b/include/core/GP_Pixel.h
index ec78c04..7250179 100644
--- a/include/core/GP_Pixel.h
+++ b/include/core/GP_Pixel.h
@@ -34,6 +34,7 @@
#include "GP_Color.h"
#include "GP_Common.h"
#include "GP_RetCode.h"
+#include "GP_FnPerBpp.h"
struct GP_Context;
@@ -136,4 +137,23 @@ static inline uint32_t GP_PixelSize(GP_PixelType type)
return GP_PixelTypes[type].size;
}
+/*
+ * Print a human-readable representation of a pixel value to a string.
+ * Arguments as for snprintf().
+ */
+static inline void GP_PixelSNPrint(char *buf, size_t len, GP_Pixel pixel, GP_PixelType type)
+{
+ GP_FN_PER_PIXELTYPE(GP_PixelSNPrint, type, buf, len, pixel);
+}
+
+/*
+ * "printf" out a human-readable representation of pixel value.
+ */
+static inline void GP_PixelPrint(GP_Pixel pixel, GP_PixelType type)
+{
+ char buf[256];
+ GP_PixelSNPrint(buf, 256, pixel, type);
+ printf("%s", buf);
+}
+
#endif /* GP_PIXEL_H */
diff --git a/pylib/gfxprim/generators/core/gen_pixeltype.py b/pylib/gfxprim/generators/core/gen_pixeltype.py
index f6aa886..680a476 100644
--- a/pylib/gfxprim/generators/core/gen_pixeltype.py
+++ b/pylib/gfxprim/generators/core/gen_pixeltype.py
@@ -63,15 +63,15 @@ def gen_GP_PixelTypes(header, code):
'};n', sorted_pts=sorted_pts, len=len)
def gen_print(ptype, header, code):
- "Generate a GP_Pixel_Print_<TYPE> function (source and header)"
+ "Generate a GP_PixelSNPrint_<TYPE> function (source and header)"
header.rbody(
- "/* print formatted value of pixel type {{ f.name }} */n"
- "void GP_PixelPrint_{{ f.name }}(GP_Pixel p);n", f=ptype)
+ "/* snprintf a human readable value of pixel type {{ f.name }} */n"
+ "void GP_PixelSNPrint_{{ f.name }}(char *buf, size_t len, GP_Pixel p);n", f=ptype)
code.rbody(
- "/* print formatted value of pixel type {{f.name}} */n"
- "void GP_PixelPrint_{{ f.name }}(GP_Pixel p)n"
+ "/* snprintf a human readable value of pixel type {{f.name}} */n"
+ "void GP_PixelSNPrint_{{ f.name }}(char *buf, size_t len, GP_Pixel p)n"
"{n"
- ' printf("<{{ f.name }} %0{{ (f.size+3)//4 }}x{% for c in f.chanslist %} {{ c[0] }}=%d{% endfor %}>",n'
+ ' snprintf(buf, len, "<{{ f.name }} 0x%0{{ (f.size+3)//4 }}x{% for c in f.chanslist %} {{ c[0] }}=%d{% endfor %}>",n'
" GP_GET_BITS(0, {{ f.size }}, p)"
"{% for c in f.chanslist %}"
",n GP_GET_BITS({{ c[1] }}, {{ c[2] }}, p)"
http://repo.or.cz/w/gfxprim.git/commit/d1f7f07b180f153f0eb40e54230537e84958…
commit d1f7f07b180f153f0eb40e54230537e8495871e9
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Mon Jun 13 00:26:58 2011 +0200
Added debugging macros GP_GET_BITS_DBG and GP_SET_BITS_DBG
diff --git a/include/core/GP_Common.h b/include/core/GP_Common.h
index 48a1167..cda1967 100644
--- a/include/core/GP_Common.h
+++ b/include/core/GP_Common.h
@@ -141,6 +141,12 @@
#define GP_GET_BITS(offset, count, val) ( ( (val)>>(offset) ) & ( ((((typeof(val))1)<<(count)) - 1) ) )
/*
+ * Debugging version, evaluates args twice.
+ */
+#define GP_GET_BITS_DBG(offset, count, val) ( printf("GET_BITS(%d, %d, 0x%x)=%d", offset, count, val, + GP_GET_BITS(offset, count, val)), GP_GET_BITS(offset, count, val))
+
+/*
* Set count bits of dest at ofset to val (shifted by offset)
*
* Does not check val for overflow
@@ -160,6 +166,14 @@
GP_SET_BITS_OR(offset, dest, val); } while (0)
+/*
+ * Debugging version, evaluates args twice.
+ */
+#define GP_SET_BITS_DBG(offset, count, dest, val) do { + GP_SET_BITS(offset, count, dest, val); + printf("SET_BITS(%d, %d, p, %d)n", offset, count, val); + } while (0)
+
/* Determines the sign of the integer value; it is +1 if value is positive,
* -1 if negative, and 0 if it is zero.
http://repo.or.cz/w/gfxprim.git/commit/e22c5773aab5f5b5681f9f2d606ebd9eeb4f…
commit e22c5773aab5f5b5681f9f2d606ebd9eeb4fea7b
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Mon Jun 13 00:25:50 2011 +0200
Added GP_CHECK_EqualColors macro
diff --git a/tests/common/GP_TestingCore.h b/tests/common/GP_TestingCore.h
index 23ea12a..0e4b726 100644
--- a/tests/common/GP_TestingCore.h
+++ b/tests/common/GP_TestingCore.h
@@ -45,6 +45,17 @@ void GP_RandomizeRect(GP_Context *context, GP_Coord x, GP_Coord y, GP_Size w, GP
int GP_EqualColors(GP_Pixel p1, GP_PixelType t1, GP_Pixel p2, GP_PixelType t2);
/*
+ * Macro version with GP_CHECK
+ */
+#define GP_CHECK_EqualColors(p1, t1, p2, t2) do { + if (!GP_EqualColors(p1, t1, p2, t2)) { + char b1[256], b2[256]; + GP_PixelSNPrint(b1, 256, p1, t1); + GP_PixelSNPrint(b2, 256, p2, t2); + GP_CHECK("Pixel colors %s and %s are not the same color.", b1, b2); + } while (0);
+
+/*
* Compare two rectangles in two contexts. Return 1 on equal.
* The colors are cmpared by first converting them to RGBA8888.
* Somewhat inefficient.
http://repo.or.cz/w/gfxprim.git/commit/70a840f2dde4591281025f8acb0374004d8d…
commit 70a840f2dde4591281025f8acb0374004d8d0e44
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 22:46:52 2011 +0200
Added GP_FN_(RET_)PER_PIXELTYPE switch-branching generation
diff --git a/pylib/gfxprim/generators/core/make_GP_Pixel.py b/pylib/gfxprim/generators/core/make_GP_Pixel.py
index 05cc28e..fd5b16c 100644
--- a/pylib/gfxprim/generators/core/make_GP_Pixel.py
+++ b/pylib/gfxprim/generators/core/make_GP_Pixel.py
@@ -41,6 +41,19 @@ def core_GP_Pixel_gen(h, c):
gen_get_pixel_addr(t, h, c)
gen_create(t, h, c)
+ ## FnPerPixelType and FnRetPerPixelType
+ for r in ['', 'return ']:
+ h.rbody(
+ 'n/* Macro for branching on PixelType (similar to GP_FnPerBpp macros) */n'
+ '#define GP_FN_{% if r %}RET_{% endif %}PER_PIXELTYPE(FN_NAME, type, ...)
'
+ ' switch (type) {
'
+ '{% for t in types %}{% if t.number != 0 %}'
+ ' case GP_PIXEL_{{ t.name }}:
'
+ ' {{ r }}FN_NAME##_{{ t.name }}(__VA_ARGS__);
'
+ ' break;
'
+ '{% endif %}{% endfor %}'
+ ' default: GP_ABORT("Invalid PixelType %d", type);
'
+ ' }nn', types=pixeltypes.values(), r=r)
@generator(CHeaderGenerator(name = 'GP_GetPutPixel.gen.h'),
descr = 'Access pixel bytes, Get and PutPixelnDo not include directly, use GP_Pixel.h',
http://repo.or.cz/w/gfxprim.git/commit/fe2f2b950ec689827669756925914f61a9f5…
commit fe2f2b950ec689827669756925914f61a9f584ab
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 22:37:10 2011 +0200
Rename some helpers in FnPerBpp (colision with planned code)
diff --git a/include/core/GP_FnPerBpp.h b/include/core/GP_FnPerBpp.h
index bc76178..79361b0 100644
--- a/include/core/GP_FnPerBpp.h
+++ b/include/core/GP_FnPerBpp.h
@@ -44,13 +44,13 @@
/*
* Branch on GP_Context argument.
*/
-#define GP_FN_PER_CONTEXT(FN_NAME, context, ...) +#define GP_FN_PER_BPP_CONTEXT(FN_NAME, context, ...) GP_FN_PER_BPP(FN_NAME, (context)->bpp, (context)->bit_endian, __VA_ARGS__)
/*
* Branch on GP_PixelType argument.
*/
-#define GP_FN_PER_PIXELTYPE(FN_NAME, type, ...) +#define GP_FN_PER_BPP_PIXELTYPE(FN_NAME, type, ...) GP_FN_PER_BPP(FN_NAME, GP_PixelTypes[type].size, GP_PixelTypes[type].bit_endian, __VA_ARGS__)
/*
@@ -102,13 +102,13 @@
/*
* Branch on GP_Context argument.
*/
-#define GP_FN_RET_PER_CONTEXT(FN_NAME, context, ...) +#define GP_FN_RET_PER_BPP_CONTEXT(FN_NAME, context, ...) GP_FN_RET_PER_BPP(FN_NAME, (context)->bpp, (context)->bit_endian, __VA_ARGS__)
/*
* Branch on GP_PixelType argument.
*/
-#define GP_FN_RET_PER_PIXELTYPE(FN_NAME, type, ...) +#define GP_FN_RET_PER_BPP_PIXELTYPE(FN_NAME, type, ...) GP_FN_RET_PER_BPP(FN_NAME, GP_PixelTypes[type].size, GP_PixelTypes[type].bit_endian, __VA_ARGS__)
/*
http://repo.or.cz/w/gfxprim.git/commit/85a6fffce341ae7b993b80fefecb97c16196…
commit 85a6fffce341ae7b993b80fefecb97c1619636e4
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 22:31:39 2011 +0200
Rename GP_Pixel_Print_* to GP_PixelPrint_*
diff --git a/pylib/gfxprim/generators/core/gen_pixeltype.py b/pylib/gfxprim/generators/core/gen_pixeltype.py
index ba25a20..f6aa886 100644
--- a/pylib/gfxprim/generators/core/gen_pixeltype.py
+++ b/pylib/gfxprim/generators/core/gen_pixeltype.py
@@ -66,10 +66,10 @@ def gen_print(ptype, header, code):
"Generate a GP_Pixel_Print_<TYPE> function (source and header)"
header.rbody(
"/* print formatted value of pixel type {{ f.name }} */n"
- "void GP_Pixel_Print_{{ f.name }}(GP_Pixel p);n", f=ptype)
+ "void GP_PixelPrint_{{ f.name }}(GP_Pixel p);n", f=ptype)
code.rbody(
"/* print formatted value of pixel type {{f.name}} */n"
- "void GP_Pixel_Print_{{ f.name }}(GP_Pixel p)n"
+ "void GP_PixelPrint_{{ f.name }}(GP_Pixel p)n"
"{n"
' printf("<{{ f.name }} %0{{ (f.size+3)//4 }}x{% for c in f.chanslist %} {{ c[0] }}=%d{% endfor %}>",n'
" GP_GET_BITS(0, {{ f.size }}, p)"
http://repo.or.cz/w/gfxprim.git/commit/ebd807bf4a3a9c1f916dff933c16536c4ef2…
commit ebd807bf4a3a9c1f916dff933c16536c4ef2261c
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 22:30:41 2011 +0200
Added helpers and documentation to FnPerBpp
diff --git a/include/core/GP_FnPerBpp.h b/include/core/GP_FnPerBpp.h
index ed2356d..bc76178 100644
--- a/include/core/GP_FnPerBpp.h
+++ b/include/core/GP_FnPerBpp.h
@@ -24,17 +24,44 @@
*****************************************************************************/
/*
- * Macro that generates a switch-case block that calls various variants
- * of the specified function depending on the bit depth of the context.
+ * Macros that generate a switch-case block that calls various variants
+ * of the specified function depending on the bit depth (bpp).
+ *
+ * For function name y and x bpp, the function called will be
+ * y_xBPP, resp y_xBPP_LE (or _BE; the bit-endian) for x<8.
+ *
+ * The functions branch either on bpp and bit_endian, type of given
+ * GP_Context or given GP_PixelType.
+ *
* Extra arguments are arguments to be passed to the function.
- * Returns GP_ENOIMPL if the bit depth is unknown.
+ * Note that if the function takes the context/type/bpp as an argument,
+ * you still need to provide it in __VA_ARGS__
+ *
+ * The GP_FN_PER_* variants ignore the return value of the called function.
+ * The GP_FN_RET_PER_* variants "return"s the value returned by the function.
+ */
+
+/*
+ * Branch on GP_Context argument.
+ */
+#define GP_FN_PER_CONTEXT(FN_NAME, context, ...) + GP_FN_PER_BPP(FN_NAME, (context)->bpp, (context)->bit_endian, __VA_ARGS__)
+
+/*
+ * Branch on GP_PixelType argument.
+ */
+#define GP_FN_PER_PIXELTYPE(FN_NAME, type, ...) + GP_FN_PER_BPP(FN_NAME, GP_PixelTypes[type].size, GP_PixelTypes[type].bit_endian, __VA_ARGS__)
+
+/*
+ * Branch on bpp and bit_endian.
*/
#define GP_FN_PER_BPP(FN_NAME, bpp, bit_endian, ...) switch (bpp) { case 1: {- if (bit_endian==GP_BIT_ENDIAN_LE)+ if (bit_endian == GP_BIT_ENDIAN_LE) FN_NAME##_1BPP_LE(__VA_ARGS__); else FN_NAME##_1BPP_BE(__VA_ARGS__);@@ -42,7 +69,7 @@
break; case 2: {- if (bit_endian==GP_BIT_ENDIAN_LE)+ if (bit_endian == GP_BIT_ENDIAN_LE) FN_NAME##_2BPP_LE(__VA_ARGS__); else FN_NAME##_2BPP_BE(__VA_ARGS__);@@ -50,7 +77,7 @@
break; case 4: {- if (bit_endian==GP_BIT_ENDIAN_LE)+ if (bit_endian == GP_BIT_ENDIAN_LE) FN_NAME##_4BPP_LE(__VA_ARGS__); else FN_NAME##_4BPP_BE(__VA_ARGS__);@@ -72,26 +99,41 @@
break; }
+/*
+ * Branch on GP_Context argument.
+ */
+#define GP_FN_RET_PER_CONTEXT(FN_NAME, context, ...) + GP_FN_RET_PER_BPP(FN_NAME, (context)->bpp, (context)->bit_endian, __VA_ARGS__)
+
+/*
+ * Branch on GP_PixelType argument.
+ */
+#define GP_FN_RET_PER_PIXELTYPE(FN_NAME, type, ...) + GP_FN_RET_PER_BPP(FN_NAME, GP_PixelTypes[type].size, GP_PixelTypes[type].bit_endian, __VA_ARGS__)
+
+/*
+ * Branch on bpp and bit_endian.
+ */
#define GP_FN_RET_PER_BPP(FN_NAME, bpp, bit_endian, ...) switch (bpp) { case 1: {- if (bit_endian==GP_BIT_ENDIAN_LE)+ if (bit_endian == GP_BIT_ENDIAN_LE) return FN_NAME##_1BPP_LE(__VA_ARGS__); else return FN_NAME##_1BPP_BE(__VA_ARGS__); } case 2: {- if (bit_endian==GP_BIT_ENDIAN_LE)+ if (bit_endian == GP_BIT_ENDIAN_LE) return FN_NAME##_2BPP_LE(__VA_ARGS__); else return FN_NAME##_2BPP_BE(__VA_ARGS__); } case 4: {- if (bit_endian==GP_BIT_ENDIAN_LE)+ if (bit_endian == GP_BIT_ENDIAN_LE) return FN_NAME##_4BPP_LE(__VA_ARGS__); else return FN_NAME##_4BPP_BE(__VA_ARGS__);
http://repo.or.cz/w/gfxprim.git/commit/d01f20fa8ffaa7959891751f12ef3195a7cf…
commit d01f20fa8ffaa7959891751f12ef3195a7cfbde7
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 22:00:52 2011 +0200
Added generated test for GP_Convert
Failing so far
diff --git a/pylib/gfxprim/generators/core/make_GP_Convert.py b/pylib/gfxprim/generators/core/make_GP_Convert.py
index 633f6cc..249763d 100644
--- a/pylib/gfxprim/generators/core/make_GP_Convert.py
+++ b/pylib/gfxprim/generators/core/make_GP_Convert.py
@@ -12,6 +12,7 @@ from gfxprim.generators.generator import *
from gfxprim.generators.pixeltype import *
from gfxprim.generators.core.gen_convert import *
+
@generator(CHeaderGenerator(name = 'GP_Convert_Scale.gen.h'),
descr = 'Fast value scaling macros',
authors = ["2011 - Tomas Gavenciak <gavento(a)ucw.cz>"])
@@ -32,6 +33,7 @@ def core_GP_Pixel_Scale_gen(h):
"{% endfor %}{% endfor %}", multcoef = lambda s1,s2: hex(sum([1<<i*s1 for i in range(s2/s1)]))
)
+
@generator(CHeaderGenerator(name = 'GP_Convert.gen.h'),
CSourceGenerator(name = 'GP_Convert.gen.c'),
descr = 'Convert PixelType values macros and functions',
@@ -58,11 +60,24 @@ def core_GP_Convert_gen_h(h, c):
gen_convert_to(pixeltypes['RGBA8888'], pixeltypes['V2'], h, c)
gen_convert_to(pixeltypes['VA12'], pixeltypes['RGBA8888'], h, c)
+
@generator(CSourceGenerator(name = 'GP_Convert.test.gen.c'),
descr = 'GP_Convert tests',
authors = ["2011 - Tomas Gavenciak <gavento(a)ucw.cz>"])
def core_GP_Convert_gen_h(c):
c.rhead('#include "GP_Tests.h"n')
- c.rhead('#include "GP_Convert.h"nn')
+ c.rhead('#include "GP_Convert.h"n')
+ c.rhead('#include "GP_TestingCore.h"nn')
c.rhead('GP_SUITE(GP_Convert)nn')
- c.rbody('GP_TEST(triv)n{}nGP_ENDTESTn')
+ for t in pixeltypes.values():
+ if not t.is_palette() and t.number != 0:
+ c.rbody(
+ 'GP_TEST(GP_ConvertPixel_for_{{ t.name }}, "loop_start=0, loop_end=4")n'
+ '{n'
+ ' GP_Pixel p1 = GP_RandomColor(GP_PIXEL_{{ t.name }});n'
+ ' GP_Pixel p2 = GP_ConvertPixel(p1, GP_PIXEL_{{ t.name }}, GP_PIXEL_RGBA8888);n'
+ ' GP_Pixel p3 = GP_ConvertPixel(p1, GP_PIXEL_RGBA8888, GP_PIXEL_{{ t.name }});n'
+ ' fail_unless(GP_EqualColors(p1, GP_PIXEL_{{ t.name }}, p3, GP_PIXEL_{{ t.name }}));n'
+ ' fail_unless(GP_EqualColors(p1, GP_PIXEL_{{ t.name }}, p2, GP_PIXEL_{{ t.name }}));n'
+ '}nn'
+ 'GP_ENDTESTn', t=t)
http://repo.or.cz/w/gfxprim.git/commit/2139339c8854d942378361854f6e1f7c5781…
commit 2139339c8854d942378361854f6e1f7c5781b9b1
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 21:57:08 2011 +0200
Fix a bug (arg. order)
diff --git a/include/core/GP_Convert.h b/include/core/GP_Convert.h
index dff93e6..aeb5acf 100644
--- a/include/core/GP_Convert.h
+++ b/include/core/GP_Convert.h
@@ -96,7 +96,7 @@ static inline GP_Pixel GP_RGBAToContextPixel(uint8_t r, uint8_t g, uint8_t b, ui
*/
static inline GP_Pixel GP_ConvertPixel(GP_Pixel pixel, GP_PixelType from, GP_PixelType to)
{
- return GP_RGBA8888ToPixel(GP_PixelToRGBA8888(from, pixel), to);
+ return GP_RGBA8888ToPixel(GP_PixelToRGBA8888(pixel, from), to);
}
/*
http://repo.or.cz/w/gfxprim.git/commit/777062b642ebcecb14a3a8944ff4afd25d14…
commit 777062b642ebcecb14a3a8944ff4afd25d145eb7
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 21:54:24 2011 +0200
Add random gen initialization to testing, move testing files
diff --git a/tests.mk b/tests.mk
index 2dc8df3..846e4f9 100644
--- a/tests.mk
+++ b/tests.mk
@@ -14,7 +14,7 @@ endif
ifdef TESTSUITE
# a bit crude way to link with test minilibrary
-GP_TESTLIB_SRCS=${TOPDIR}/tests/common/GP_Tests.c
+GP_TESTLIB_SRCS=$(wildcard ${TOPDIR}/tests/common/*.c)
CSOURCES+=${GP_TESTLIB_SRCS}
# generated suite creation code
diff --git a/libs/core/GP_TestingCore.c b/tests/common/GP_TestingCore.c
similarity index 100%
rename from libs/core/GP_TestingCore.c
rename to tests/common/GP_TestingCore.c
diff --git a/include/core/GP_TestingCore.h b/tests/common/GP_TestingCore.h
similarity index 100%
rename from include/core/GP_TestingCore.h
rename to tests/common/GP_TestingCore.h
diff --git a/libs/core/GP_TestingRandom.c b/tests/common/GP_TestingRandom.c
similarity index 100%
rename from libs/core/GP_TestingRandom.c
rename to tests/common/GP_TestingRandom.c
diff --git a/include/core/GP_TestingRandom.h b/tests/common/GP_TestingRandom.h
similarity index 95%
rename from include/core/GP_TestingRandom.h
rename to tests/common/GP_TestingRandom.h
index 9f897f8..9f267fb 100644
--- a/include/core/GP_TestingRandom.h
+++ b/tests/common/GP_TestingRandom.h
@@ -28,8 +28,10 @@
* on random() called in the tested routines or other tests.
*/
-#ifndef CORE_GP_TESTING_RANDOM_H
-#define CORE_GP_TESTING_RANDOM_H
+#ifndef GP_TESTING_RANDOM_H
+#define GP_TESTING_RANDOM_H
+
+#include <stdint.h>
/*
* Return next random value from the testing random generator
@@ -44,4 +46,4 @@ long int GP_TestingRandom(void);
*/
void GP_InitTestingRandom(const char *text, uint64_t seed);
-#endif /* CORE_GP_TESTING_RANDOM_H */
+#endif /* GP_TESTING_RANDOM_H */
diff --git a/tests/common/GP_Tests.h b/tests/common/GP_Tests.h
index d24b5f6..72c83bb 100644
--- a/tests/common/GP_Tests.h
+++ b/tests/common/GP_Tests.h
@@ -41,6 +41,7 @@
*/
#include <check.h>
+#include "GP_TestingRandom.h"
/*
* Helper macro to allow auto-generation of test-cases and suites.
@@ -62,9 +63,9 @@
* Parameters name, fname, line are used internally, do not use them
*/
-#define GP_TEST(name, ...) static void name(int);- void GP_TEST_##name(int i) {name(i);} - START_TEST(name)
+#define GP_TEST(name, ...) static void name(int); void GP_TEST_##name(int i) {+ GP_InitTestingRandom( #name, i); name(i); } + START_TEST(name)
#define GP_ENDTEST END_TEST
http://repo.or.cz/w/gfxprim.git/commit/6d267ad031a775ffb3e7e73a5357a7600e7b…
commit 6d267ad031a775ffb3e7e73a5357a7600e7b96f0
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 20:57:50 2011 +0200
Fixed "make clean" in tests/core
diff --git a/tests/core/Makefile b/tests/core/Makefile
index 2d11c70..c03633a 100644
--- a/tests/core/Makefile
+++ b/tests/core/Makefile
@@ -5,7 +5,6 @@ TESTSUITE=core_suite
LDLIBS+=-lGP -L$(TOPDIR)/build/ -lcheck
GENSOURCES+=GP_Convert.test.gen.c
-include $(TOPDIR)/include.mk
include $(TOPDIR)/tests.mk
-
+include $(TOPDIR)/include.mk
http://repo.or.cz/w/gfxprim.git/commit/50e68bdcafa2e379597a3c454343c4f3b2c7…
commit 50e68bdcafa2e379597a3c454343c4f3b2c7db73
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 20:56:32 2011 +0200
Support for generating tests source files + demo
Added support to tests.mk and make_collected_tests.py
Demo in make_GP_Convert.py
diff --git a/pylib/gfxprim/generators/core/make_GP_Convert.py b/pylib/gfxprim/generators/core/make_GP_Convert.py
index 291b383..633f6cc 100644
--- a/pylib/gfxprim/generators/core/make_GP_Convert.py
+++ b/pylib/gfxprim/generators/core/make_GP_Convert.py
@@ -57,3 +57,12 @@ def core_GP_Convert_gen_h(h, c):
gen_convert_to(pixeltypes['RGB565'], pixeltypes['RGBA8888'], h, c)
gen_convert_to(pixeltypes['RGBA8888'], pixeltypes['V2'], h, c)
gen_convert_to(pixeltypes['VA12'], pixeltypes['RGBA8888'], h, c)
+
+@generator(CSourceGenerator(name = 'GP_Convert.test.gen.c'),
+ descr = 'GP_Convert tests',
+ authors = ["2011 - Tomas Gavenciak <gavento(a)ucw.cz>"])
+def core_GP_Convert_gen_h(c):
+ c.rhead('#include "GP_Tests.h"n')
+ c.rhead('#include "GP_Convert.h"nn')
+ c.rhead('GP_SUITE(GP_Convert)nn')
+ c.rbody('GP_TEST(triv)n{}nGP_ENDTESTn')
diff --git a/pylib/gfxprim/generators/make_collected_tests.py b/pylib/gfxprim/generators/make_collected_tests.py
index ca117ec..d690dac 100644
--- a/pylib/gfxprim/generators/make_collected_tests.py
+++ b/pylib/gfxprim/generators/make_collected_tests.py
@@ -27,7 +27,7 @@ def msg(prefix, msg_s, fname=None, line=None):
s += '] '
sys.stderr.write(s + msg_s + 'n')
-testfile_pattern = '*.test.c'
+testfile_patterns = ['*.test.c', '*.test.gen.c']
suites = {} # {"suitename":["testname":{test_parameters}]}
@@ -39,8 +39,9 @@ test_re = re.compile("A\s*GP_TEST\((.*)\)\s*Z")
'from .test.c files',
authors = ["2011 - Tomas Gavenciak <gavento(a)ucw.cz>"])
def tests_collected_tests(c):
- fnames = glob.fnmatch.filter(os.listdir(c.fdir or '.'), testfile_pattern)
- print fnames
+ fnames = []
+ for pat in testfile_patterns:
+ fnames += glob.fnmatch.filter(os.listdir(c.fdir or '.'), pat)
for fn in fnames:
dirfn = os.path.join(c.fdir, fn)
with open(dirfn, 'rt') as f:
diff --git a/tests.mk b/tests.mk
index 5dbcc80..2dc8df3 100644
--- a/tests.mk
+++ b/tests.mk
@@ -21,7 +21,9 @@ CSOURCES+=${GP_TESTLIB_SRCS}
TESTSUITE_GEN=collected_tests.gen.c # also fixed in the code generator
GENSOURCES+=${TESTSUITE_GEN}
-TESTSUITE_SRCS=$(wildcard *.test.c) ${TESTSUITE_GEN} ${GP_TESTLIB_SRCS}
+${TESTSUITE_GEN}: $(filter-out ${TESTSUITE_GEN},${GENSOURCES}) ${GENHEADERS}
+
+TESTSUITE_SRCS=$(wildcard *.test.c) ${GENSOURCES} ${GENHEADERS} ${GP_TESTLIB_SRCS}
INCLUDE+=../tests/common
TESTSUITE_OBJS=$(patsubst %.c,%.o,$(TESTSUITE_SRCS))
CLEAN+=${TESTSUITE}
diff --git a/tests/core/Makefile b/tests/core/Makefile
index 929a30c..2d11c70 100644
--- a/tests/core/Makefile
+++ b/tests/core/Makefile
@@ -1,8 +1,9 @@
TOPDIR=../..
LIBNAME=core
-TESTSUITE=core
+TESTSUITE=core_suite
LDLIBS+=-lGP -L$(TOPDIR)/build/ -lcheck
+GENSOURCES+=GP_Convert.test.gen.c
include $(TOPDIR)/include.mk
include $(TOPDIR)/tests.mk
http://repo.or.cz/w/gfxprim.git/commit/e8872dfaab48d1f16b749fbd0ea698a6b7ce…
commit e8872dfaab48d1f16b749fbd0ea698a6b7ce86ae
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 20:43:41 2011 +0200
Added helper routines for testing parts of core
* Color (pixel) randomization and comparation
* Context randomization and comparation
diff --git a/include/core/GP_TestingCore.h b/include/core/GP_TestingCore.h
new file mode 100644
index 0000000..23ea12a
--- /dev/null
+++ b/include/core/GP_TestingCore.h
@@ -0,0 +1,55 @@
+/*****************************************************************************
+ * 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) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#ifndef CORE_GP_TESTINGCORE_H
+#define CORE_GP_TESTINGCORE_H
+
+#include "GP_Context.h"
+#include "GP_Pixel.h"
+
+/*
+ * Return pixel value of random color of given type.
+ * Uses GP_TestingRandom and is not really efficient.
+ */
+GP_Pixel GP_RandomColor(GP_PixelType type);
+
+/*
+ * Set color of pixels in given bitap rectangle to random values.
+ * Uses GP_TestingRandom and is not really efficient.
+ */
+void GP_RandomizeRect(GP_Context *context, GP_Coord x, GP_Coord y, GP_Size w, GP_Size h);
+
+/*
+ * Return true if the two colors are equal after conversion to RGBA8888.
+ * Not very efficient.
+ */
+int GP_EqualColors(GP_Pixel p1, GP_PixelType t1, GP_Pixel p2, GP_PixelType t2);
+
+/*
+ * Compare two rectangles in two contexts. Return 1 on equal.
+ * The colors are cmpared by first converting them to RGBA8888.
+ * Somewhat inefficient.
+ */
+int GP_EqualRects(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h,
+ const GP_Context *c2, GP_Coord x2, GP_Coord y2);
+
+#endif /* CORE_GP_TESTINGCORE_H */
diff --git a/libs/core/GP_TestingCore.c b/libs/core/GP_TestingCore.c
new file mode 100644
index 0000000..afa2754
--- /dev/null
+++ b/libs/core/GP_TestingCore.c
@@ -0,0 +1,65 @@
+/*****************************************************************************
+ * 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) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include "GP_Common.h"
+#include "GP_Convert.h"
+#include "GP_GetPutPixel.h"
+#include "GP_TestingCore.h"
+#include "GP_TestingRandom.h"
+
+/*
+ * TODO: Use a different version for palette types.
+ */
+GP_Pixel GP_RandomColor(GP_PixelType type)
+{
+ return GP_RGBAToPixel(GP_TestingRandom() % 256, GP_TestingRandom() % 256,
+ GP_TestingRandom() % 256, GP_TestingRandom() % 256, type);
+}
+
+void GP_RandomizeRect(GP_Context *context, GP_Coord x, GP_Coord y, GP_Size w, GP_Size h)
+{
+ GP_CHECK(context);
+ for (GP_Size i = 0; i < w; i++)
+ for (GP_Size j = 0; j < h; j++)
+ GP_PutPixel(context, i + x, j + y, GP_RandomColor(context->pixel_type));
+}
+
+int GP_EqualColors(GP_Pixel p1, GP_PixelType t1, GP_Pixel p2, GP_PixelType t2)
+{
+ GP_Pixel col1 = GP_PixelToRGBA8888(p1, t1);
+ GP_Pixel col2 = GP_PixelToRGBA8888(p2, t2);
+ return (col1 & 0xffffffff) == (col2 & 0xffffffff);
+}
+
+int GP_EqualRects(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h,
+ const GP_Context *c2, GP_Coord x2, GP_Coord y2)
+{
+ GP_CHECK(c1);
+ GP_CHECK(c2);
+ for (GP_Size i = 0; i < w; i++)
+ for (GP_Size j = 0; j < h; j++) {
+ if (!GP_EqualColors(GP_GetPixel(c1, x1 + i, y1 + j), c1->pixel_type,
+ GP_GetPixel(c2, x2 + i, y2 + j), c2->pixel_type))
+ return 0;
+ }
+ return 1;
+}
http://repo.or.cz/w/gfxprim.git/commit/d7551ce7958fc44a3a9e070258d3c8a45a23…
commit d7551ce7958fc44a3a9e070258d3c8a45a23f755
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 20:42:53 2011 +0200
Add separate pseudorandom generator for testing inputs
diff --git a/include/core/GP_TestingRandom.h b/include/core/GP_TestingRandom.h
new file mode 100644
index 0000000..9f897f8
--- /dev/null
+++ b/include/core/GP_TestingRandom.h
@@ -0,0 +1,47 @@
+/*****************************************************************************
+ * 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) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+/*
+ * These routines use a pseudorandom generator with internal state.
+ * Use this only to provide tests with pseudo-random inputs.
+ * The seed is initialized with the test name, so the random numbers
+ * (and therefore inputs) are the same for a test, and do not depend
+ * on random() called in the tested routines or other tests.
+ */
+
+#ifndef CORE_GP_TESTING_RANDOM_H
+#define CORE_GP_TESTING_RANDOM_H
+
+/*
+ * Return next random value from the testing random generator
+ */
+long int GP_TestingRandom(void);
+
+/*
+ * Initialize the random generator to a seed computed from the given string
+ * and the given seed value. Needs to be called at least once.
+ *
+ * The string may be for example the name of the test, the seed the number of test iteration.
+ */
+void GP_InitTestingRandom(const char *text, uint64_t seed);
+
+#endif /* CORE_GP_TESTING_RANDOM_H */
diff --git a/libs/core/GP_TestingRandom.c b/libs/core/GP_TestingRandom.c
new file mode 100644
index 0000000..17281a9
--- /dev/null
+++ b/libs/core/GP_TestingRandom.c
@@ -0,0 +1,58 @@
+/*****************************************************************************
+ * 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) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include <stdlib.h>
+
+#include "GP_Common.h"
+#include "GP_TestingRandom.h"
+
+/*
+ * State array for testing random generator
+ *
+ * The idea is to have a seperate random generator for generating
+ * random inputs for tests in case tested algorithms also use
+ * the random generator. Change in the tested algorithm must not
+ * change the input data generated for this or other part of the test.
+ *
+ * Take care when changing the values - unrelated test might start
+ * exhibiting a bug, some tests may rely on the exact result.
+ */
+#define GP_RandomStateSize 256
+static char GP_RandomTestingState[GP_RandomStateSize];
+static struct random_data GP_RandomTestingData;
+
+long int GP_TestingRandom(void)
+{
+ int32_t r;
+ GP_ASSERT(random_r(&GP_RandomTestingData, &r) == 0);
+ return r;
+}
+
+void GP_InitTestingRandom(const char *text, uint64_t seed)
+{
+ const char *p = text;
+ for (; (p) && (*p); p++)
+ seed = ((seed * 327) + *p) % 0x7B391D50A10A3LL; // TODO replace with large primes
+ GP_ASSERT(initstate_r(seed, GP_RandomTestingState, GP_RandomStateSize,
+ &GP_RandomTestingData) == 0);
+}
+
http://repo.or.cz/w/gfxprim.git/commit/413daca73ab16f53c9fd81410c261bc7628d…
commit 413daca73ab16f53c9fd81410c261bc7628d2e11
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 20:40:02 2011 +0200
Make context arg of GetPixel const
diff --git a/include/core/GP_GetPutPixel.h b/include/core/GP_GetPutPixel.h
index 102bf9a..7151a36 100644
--- a/include/core/GP_GetPutPixel.h
+++ b/include/core/GP_GetPutPixel.h
@@ -36,7 +36,7 @@
* GetPixel with context transformations and clipping.
* Returns 0 for clipped pixels or pixels outside bitmap.
*/
-GP_Pixel GP_GetPixel(GP_Context *context, int x, int y);
+GP_Pixel GP_GetPixel(const GP_Context *context, int x, int y);
/*
* Version of GetPixel without transformations nor border checking.
diff --git a/libs/core/GP_GetPutPixel.c b/libs/core/GP_GetPutPixel.c
index fe37216..9cac910 100644
--- a/libs/core/GP_GetPutPixel.c
+++ b/libs/core/GP_GetPutPixel.c
@@ -23,7 +23,7 @@
#include "GP_GetPutPixel.h"
#include "GP_Transform.h"
-GP_Pixel GP_GetPixel(GP_Context *context, int x, int y)
+GP_Pixel GP_GetPixel(const GP_Context *context, int x, int y)
{
GP_TRANSFORM_POINT(context, x, y);
if (GP_PIXEL_IS_CLIPPED(context, x, y))
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_Common.h | 14 +++
include/core/GP_Convert.h | 3 +-
include/core/GP_FnPerBpp.h | 60 ++++++++++++--
include/core/GP_GetPutPixel.h | 2 +-
include/core/GP_Pixel.h | 20 +++++
libs/core/GP_Blit.c | 3 +-
libs/core/GP_GetPutPixel.c | 2 +-
pylib/gfxprim/generators/core/gen_pixeltype.py | 12 ++--
pylib/gfxprim/generators/core/make_GP_Convert.py | 46 ++++++++++-
pylib/gfxprim/generators/core/make_GP_Pixel.py | 13 +++
pylib/gfxprim/generators/make_collected_tests.py | 7 +-
tests.mk | 8 +-
.../GP_Blit.c => tests/common/GP_TestingCore.c | 86 +++++++++++---------
.../common/GP_TestingCore.h | 53 ++++++------
.../common/GP_TestingRandom.c | 57 ++++++-------
.../GP_Blit.h => tests/common/GP_TestingRandom.h | 41 +++++-----
tests/common/GP_Tests.h | 7 +-
tests/core/GP_Convert.test.c | 27 ++++++
tests/core/Makefile | 6 +-
19 files changed, 316 insertions(+), 151 deletions(-)
copy libs/core/GP_Blit.c => tests/common/GP_TestingCore.c (50%)
copy include/core/GP_GetPutPixel.h => tests/common/GP_TestingCore.h (58%)
copy include/core/GP_GetPutPixel.h => tests/common/GP_TestingRandom.c (60%)
copy include/core/GP_Blit.h => tests/common/GP_TestingRandom.h (66%)
create mode 100644 tests/core/GP_Convert.test.c
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.")
1
0
Problms with git update messages (Your message to Gfxprim awaits moderator approval)
by Tomas Gavenciak 12 Jun '11
by Tomas Gavenciak 12 Jun '11
12 Jun '11
Dear admins of repo.or.cz,
We use your repository to develop our small graphic library,
frequently pushing large refactoring commits, many small commits at
once or bigger chunks of new code.
Getting announces of other peoples' commits is a very useful feature,
but the full patch format is inconvenient for at least two reasons:
* It is very hard to read the commit comment of other than the first
commit in the message
* The patch body is quite frequently too large and/or of little
interest or information itself
I think it would be an improvement to your great service to (have an
option to) send the commit messages instead of the full patch. Anyone
interested in the actual change can see it the repo within the
context. Would you please consider making that change?
An inspiration for additional luxury (not requesting those):
It might make sense to send the patch if very small (<20 lines or so),
but I am not sure how hard/useful would that be.
Including a link directly to the commit page or the project commit log
page on gitweb might be nice for those who would like to see the full
patch without fetching the repo.
Best regards,
Tomas
On Sun, Jun 12, 2011 at 1:29 AM, <gfxprim-bounces(a)ucw.cz> wrote:
> Your mail to 'Gfxprim' with the subject
>
> [repo.or.cz] gfxprim.git branch generate updated:
> abf38d0ef10e4cd84391950b1595cfc60dcf3181
>
> Is being held until the list moderator can review it for approval.
>
> The reason it is being held:
>
> Message body is too big: 94428 bytes with a limit of 40 KB
>
> Either the message will get posted to the list, or you will receive
> notification of the moderator's decision. If you would like to cancel
> this posting, please visit the following URL:
>
> http://www.ucw.cz/mailman/confirm/gfxprim/434baecc73c727fa1e4afc18075d535a0…
>
>
1
0
[repo.or.cz] gfxprim.git branch generate updated: abf38d0ef10e4cd84391950b1595cfc60dcf3181
by gavento 12 Jun '11
by gavento 12 Jun '11
12 Jun '11
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, generate has been updated
via abf38d0ef10e4cd84391950b1595cfc60dcf3181 (commit)
via 80c8f8ccda4b63c85fa784cb2ebfa61181a818a4 (commit)
via 06fa397a908dd96877573db3df61274cd493eed4 (commit)
via 21749e191eb8863acaa33bc32d2959f89cc97d88 (commit)
via 4b24345dd60ebbc38dccca753476ebf32cb72df0 (commit)
via 47c5f5f4b32da3d004ffa2c037857c8323ea1a1f (commit)
via c4ac868f69649ea94eab4a650b49ca25dcd2c490 (commit)
via 51e969cd103ec6546ec91af744157338d352896c (commit)
via f11293be8118c9707b268f55ba49dc6ea8b111ff (commit)
via 6aa9b93dc730b452effb253df5a051bc791692ef (commit)
via 93c34cab6ae326bf2ff21a69c973a3922ca9ece7 (commit)
via 628bf75875173555777a15ce6a7fe7e91cd328b8 (commit)
via cfd3858ce9e6a269b8903bd312e52259c48e318c (commit)
from fb094cd7f8086ddb9e59b91224c5fef9702136fa (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/abf38d0ef10e4cd84391950b1595cfc60dcf…
commit abf38d0ef10e4cd84391950b1595cfc60dcf3181
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 01:27:18 2011 +0200
Add blit color conversion, use GP_Coord and GP_Size in blits
diff --git a/libs/core/GP_Blit.c b/include/core/GP_Blit.h
similarity index 55%
copy from libs/core/GP_Blit.c
copy to include/core/GP_Blit.h
index 29e90e8..fc2c6a7 100644
--- a/libs/core/GP_Blit.c
+++ b/include/core/GP_Blit.h
@@ -20,57 +20,29 @@
* *
*****************************************************************************/
-#include "GP_Pixel.h"
-#include "GP_Pixel_Access.h"
-#include "GP_Context.h"
+#ifndef CORE_GP_BLIT_H
+#define CORE_GP_BLIT_H
-/*
-void GP_Blit(const GP_Context *c1, int x1, int y1, int w, int h,
- GP_Context *c2, int x2, int y2)
-{
- // Ultimate TODO: effective processing
- GP_Blit_Naive(c1, x1, y1, w, h, c2, x2, y2);
-}
-*/
+/* Generated header */
+#include "GP_Blit.gen.h"
-// TODO(gavento, czech) Plan:
-// GP_Blit_Naive - Zadne rotovani a tak, jen Get/PutPixel a konverze A->RGBA8888->B
-// GP_Blit_Simple - S rotovanim, makrovy Get/PutPixel, mozna optimalizace na radky, chytrejsi konverze (ale porad univ.)
-// GP_Blit_Simple_xBPP - S rotovanim, makrovy Get/PutPixel
-// GP_Blit_xBPP - Optimalizovane, muze volat GP_Blit_Simple_xBPP pro divne pripady
-// GP_Blit - Vola GP_Blit_xBPP (stejny typ) nebo GP_Blit_Simple (jine typy), pripadne optimalizovat
-
-/*
-void GP_Blit_Naive(const GP_Context *c1, int x1, int y1, int w, int h,
- GP_Context *c2, int x2, int y2)
-{
- GP_TRANSFORM_BLIT(c1, x1, y1, w, h, c2, x2, y2);
- // TODO: Cipping?
- GP_Blit_Naive_Raw(c1, x1, y1, w, h, c2, x2, y2);
-}
-*/
+void GP_Blit(const GP_Context *c1, int x1, int y1, int w, int h,
+ GP_Context *c2, int x2, int y2);
/*
* Very naive blit, no optimalizations whatsoever - keep it that way.
* Used as a reference for testing and such. Aaand ultimate fallback.
+ * GP_CHECKS for clipping and size (for testing)
*/
-void GP_Blit_Naive(const GP_Context *c1, int x1, int y1, int w, int h,
- GP_Context *c2, int x2, int y2)
-{
- GP_CHECK(x1 >= 0);
- GP_CHECK(y1 >= 0);
- GP_CHECK(w >= 0);
- GP_CHECK(h >= 0);
- GP_CHECK(x1 + w <= GP_ContextW(c1));
- GP_CHECK(y1 + h <= GP_ContextH(c1));
- GP_CHECK(x2 >= 0);
- GP_CHECK(y2 >= 0);
- GP_CHECK(x2 + w <= GP_ContextW(c2));
- GP_CHECK(y2 + h <= GP_ContextH(c2));
+void GP_Blit_Naive(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h,
+ GP_Context *c2, GP_Coord x2, GP_Coord y2);
- for (int i = 0; i < w; i++)
- for (int j = 0; j < h; j++) {
- GP_Pixel p = GP_GetPixel(c1, x1 + i, y1 + j);
- GP_PutPixel(c2, x2 + i, y2 + j, p);
- }
-}
+/*
+ * Similar in purpose to GP_Blit_Naive, but operates on raw coordinates.
+ * Does no range checking.
+ */
+/*
+void GP_Blit_Naive_Raw(const GP_Context *c1, int x1, int y1, int w, int h,
+ GP_Context *c2, int x2, int y2);
+*/
+#endif // CORE_GP_BLIT_H
diff --git a/libs/core/GP_Blit.c b/libs/core/GP_Blit.c
index 29e90e8..76c7a2c 100644
--- a/libs/core/GP_Blit.c
+++ b/libs/core/GP_Blit.c
@@ -21,8 +21,9 @@
*****************************************************************************/
#include "GP_Pixel.h"
-#include "GP_Pixel_Access.h"
+#include "GP_GetPutPixel.h"
#include "GP_Context.h"
+#include "GP_Blit.h"
/*
void GP_Blit(const GP_Context *c1, int x1, int y1, int w, int h,
@@ -50,12 +51,8 @@ void GP_Blit_Naive(const GP_Context *c1, int x1, int y1, int w, int h,
}
*/
-/*
- * Very naive blit, no optimalizations whatsoever - keep it that way.
- * Used as a reference for testing and such. Aaand ultimate fallback.
- */
-void GP_Blit_Naive(const GP_Context *c1, int x1, int y1, int w, int h,
- GP_Context *c2, int x2, int y2)
+void GP_Blit_Naive(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h,
+ GP_Context *c2, GP_Coord x2, GP_Coord y2)
{
GP_CHECK(x1 >= 0);
GP_CHECK(y1 >= 0);
@@ -71,6 +68,8 @@ void GP_Blit_Naive(const GP_Context *c1, int x1, int y1, int w, int h,
for (int i = 0; i < w; i++)
for (int j = 0; j < h; j++) {
GP_Pixel p = GP_GetPixel(c1, x1 + i, y1 + j);
+ if (c1->pixel_type != c2->pixel_type)
+ p = GP_GP_ConvertContextPixel(p, c1, c2);
GP_PutPixel(c2, x2 + i, y2 + j, p);
}
}
diff --git a/pylib/gfxprim/generators/core/gen_blit.py b/pylib/gfxprim/generators/core/gen_blit.py
index 819f29f..78be0f8 100644
--- a/pylib/gfxprim/generators/core/gen_blit.py
+++ b/pylib/gfxprim/generators/core/gen_blit.py
@@ -18,14 +18,14 @@ def gen_blit_same_t(size, size_suffix, header, code):
"n/*** Blit preserving type, variant for {{ size_suffix }} ***n"
" * Assumes the contexts to be of the right types and sizesn"
" * Ignores transformations and clipping */nn"
- "void GP_Blit_{{ size_suffix }}(const GP_Context *c1, int x1, int y1, int w, int h,n"
- " GP_Context *c2, int x2, int y2);n",
+ "void GP_Blit_{{ size_suffix }}(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h,n"
+ " GP_Context *c2, GP_Coord x2, GP_Coord y2);n",
size=size, size_suffix=size_suffix)
code.rbody(
"n/*** Blit preservimg type, variant for {{ size_suffix }} ***/n"
- "void GP_Blit_{{ size_suffix }}(const GP_Context *c1, int x1, int y1, int w, int h,n"
- " GP_Context *c2, int x2, int y2)n"
+ "void GP_Blit_{{ size_suffix }}(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h,n"
+ " GP_Context *c2, GP_Coord x2, GP_Coord y2)n"
"{n"
" if (unlikely(w == 0 || h == 0)) return;nn"
" /* Special case - copy whole line-block with one memcpy() */n"
@@ -38,7 +38,7 @@ def gen_blit_same_t(size, size_suffix, header, code):
" }nn"
"{% if size>=8 %}"
" /* General case - memcpy() each horizontal line */n"
- " for (int i=0; i<h; i++)n"
+ " for (GP_Size i = 0; i < h; i++)n"
" memcpy(GP_PIXEL_ADDR_{{ size_suffix }}(c2, x2, y2 + i), n"
" GP_PIXEL_ADDR_{{ size_suffix }}(c1, x2, y2 + i),n"
" {{ size/8 }} * w);n"
@@ -57,7 +57,7 @@ def gen_blit_same_t(size, size_suffix, header, code):
" uint8_t *p2 = GP_PIXEL_ADDR_{{ size_suffix }}(c2, x2, y2);n"
" uint8_t *end_p1 = GP_PIXEL_ADDR_{{ size_suffix }}(c1, x1 + w - 1, y1);n"
" uint8_t *end_p2 = GP_PIXEL_ADDR_{{ size_suffix }}(c2, x2 + w - 1, y2);n"
- " for (int i = 0; i < h; i++) {n"
+ " for (GP_Size i = 0; i < h; i++) {n"
" if (al1 != 0)n"
" GP_SET_BITS(al1, 8-al1, *p2, GP_GET_BITS(al1, 8-al1, *p1));n"
" memcpy(p2+(al1!=0), p1+(al1!=0), copy_size);n"
@@ -73,19 +73,3 @@ def gen_blit_same_t(size, size_suffix, header, code):
"{% endif %}"
"}n", size=size, size_suffix=size_suffix)
-
-def gen_blit_t(f1, f2, header, code):
- "Generate a macro GP_Blit_T1_T2 blitting a rectangle"
- "Does not (yet) convert between PAL formats and RGBVA"
- allowed_chansets = [ set(list(s)) for s in ['RGB', 'RGBA', 'V', 'VA'] ]
- if f1!=f2:
- assert(set(f1.chans.keys()) in allowed_chansets)
- assert(set(f2.chans.keys()) in allowed_chansets)
-
- header.rbody(
- "n/*** Blit line {{ f1.name }} -> {{ f2.name }} ***n"
- " * Assumes the contexts to be of the right types and sizes */nn"
- "void GP_Blit_{{ f1.name }}_{{ f2.name }}(const GP_Context *c1, int x1, int y2, int w, int h,n"
- " GP_Context *c2, int x2, int y2);n",
- f1=f1, f2=f2)
-
diff --git a/pylib/gfxprim/generators/core/make_GP_Blit.py b/pylib/gfxprim/generators/core/make_GP_Blit.py
index 702d2ba..03057b0 100644
--- a/pylib/gfxprim/generators/core/make_GP_Blit.py
+++ b/pylib/gfxprim/generators/core/make_GP_Blit.py
@@ -21,7 +21,7 @@ def core_GP_Blit_gen(h, c):
'#include "GP_Pixel.h"n'
'#include "GP.h"n'
'#include "GP_Context.h"n'
- '#include "GP_Blit.gen.h"n'
+ '#include "GP_Blit.h"n'
)
for bpp in bitsizes:
http://repo.or.cz/w/gfxprim.git/commit/80c8f8ccda4b63c85fa784cb2ebfa61181a8…
commit 80c8f8ccda4b63c85fa784cb2ebfa61181a818a4
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 01:25:24 2011 +0200
Add GP_Size (unsigned int) type
diff --git a/include/core/GP_Context.h b/include/core/GP_Context.h
index da344f3..ce85f65 100644
--- a/include/core/GP_Context.h
+++ b/include/core/GP_Context.h
@@ -35,6 +35,7 @@
/* Integer type for coordinates: x, y, width, height, ...
* Should be signed to hold negative values as well. */
typedef int GP_Coord;
+typedef unsigned int GP_Size;
/* This structure holds all information needed for drawing into an image. */
typedef struct GP_Context {
http://repo.or.cz/w/gfxprim.git/commit/06fa397a908dd96877573db3df61274cd493…
commit 06fa397a908dd96877573db3df61274cd493eed4
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 01:09:05 2011 +0200
Extend value scaling to all values 1..8
Requred by RGB565 etc.
diff --git a/pylib/gfxprim/generators/core/make_GP_Convert.py b/pylib/gfxprim/generators/core/make_GP_Convert.py
index 8ef43ed..291b383 100644
--- a/pylib/gfxprim/generators/core/make_GP_Convert.py
+++ b/pylib/gfxprim/generators/core/make_GP_Convert.py
@@ -23,7 +23,7 @@ def core_GP_Pixel_Scale_gen(h):
" */n"
"#define GP_SCALE_VAL(s1, s2, val) ( GP_SCALE_VAL_##s1##_##s2(val) )nn"
- "{% for s1 in [1, 2, 4, 8] %}{% for s2 in [1, 2, 4, 8] %}"
+ "{% for s1 in range(1,9) %}{% for s2 in range(1,9) %}"
"{% if s2>s1 %}"
"#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) ((val) * {{ multcoef(s1, s2) }})n"
"{% else %}"
http://repo.or.cz/w/gfxprim.git/commit/21749e191eb8863acaa33bc32d2959f89cc9…
commit 21749e191eb8863acaa33bc32d2959f89cc97d88
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 01:00:16 2011 +0200
Move scaling code generation from Pixel to Convert
diff --git a/include/core/GP_Convert.h b/include/core/GP_Convert.h
index c1c44ef..dff93e6 100644
--- a/include/core/GP_Convert.h
+++ b/include/core/GP_Convert.h
@@ -26,8 +26,9 @@
#include "GP_Common.h"
#include "GP_Context.h"
-/* Generated header */
+/* Generated headers */
#include "GP_Convert.gen.h"
+#include "GP_Convert_Scale.gen.h"
/*
* Generated function to convert RGB888 to any type.
diff --git a/include/core/GP_Pixel.h b/include/core/GP_Pixel.h
index 7ac0fb7..ec78c04 100644
--- a/include/core/GP_Pixel.h
+++ b/include/core/GP_Pixel.h
@@ -54,9 +54,8 @@ struct GP_Context;
typedef uint32_t GP_Pixel;
-/* Generated headers */
+/* Generated header */
#include "GP_Pixel.gen.h"
-#include "GP_Pixel_Scale.gen.h"
/*
* Information about ordering of pixels in byte for 1, 2 and 4 bpp
diff --git a/libs/core/Makefile b/libs/core/Makefile
index bce6f9d..5bcadca 100644
--- a/libs/core/Makefile
+++ b/libs/core/Makefile
@@ -1,6 +1,6 @@
TOPDIR=../..
GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c GP_Convert.gen.c
-GENHEADERS=GP_Pixel_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h GP_GetPutPixel.gen.h GP_Convert.gen.h
+GENHEADERS=GP_Convert_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h GP_GetPutPixel.gen.h GP_Convert.gen.h
CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
LIBNAME=core
CFLAGS+=-Wno-overflow
diff --git a/pylib/gfxprim/generators/core/make_GP_Convert.py b/pylib/gfxprim/generators/core/make_GP_Convert.py
index 1800a2c..8ef43ed 100644
--- a/pylib/gfxprim/generators/core/make_GP_Convert.py
+++ b/pylib/gfxprim/generators/core/make_GP_Convert.py
@@ -3,6 +3,7 @@
# Script generating:
#
# GP_Convert.gen.c, GP_Convert.gen.h
+# GP_Convert_Scale.gen.h
#
# 2011 - Tomas Gavenciak <gavento(a)ucw.cz>
#
@@ -11,11 +12,29 @@ from gfxprim.generators.generator import *
from gfxprim.generators.pixeltype import *
from gfxprim.generators.core.gen_convert import *
+@generator(CHeaderGenerator(name = 'GP_Convert_Scale.gen.h'),
+ descr = 'Fast value scaling macros',
+ authors = ["2011 - Tomas Gavenciak <gavento(a)ucw.cz>"])
+def core_GP_Pixel_Scale_gen(h):
+ h.rhead(
+ "/* helper macros to transfer s1-bit value to s2-bit valuen"
+ " * NOTE: efficient and accurate for both up- and downscaling,n"
+ " * WARNING: GP_SCALE_VAL requires constants numebrs as first two parametersn"
+ " */n"
+ "#define GP_SCALE_VAL(s1, s2, val) ( GP_SCALE_VAL_##s1##_##s2(val) )nn"
+
+ "{% for s1 in [1, 2, 4, 8] %}{% for s2 in [1, 2, 4, 8] %}"
+ "{% if s2>s1 %}"
+ "#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) ((val) * {{ multcoef(s1, s2) }})n"
+ "{% else %}"
+ "#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) ((val) >> {{ s1 - s2 }})n"
+ "{% endif %}"
+ "{% endfor %}{% endfor %}", multcoef = lambda s1,s2: hex(sum([1<<i*s1 for i in range(s2/s1)]))
+ )
@generator(CHeaderGenerator(name = 'GP_Convert.gen.h'),
CSourceGenerator(name = 'GP_Convert.gen.c'),
- descr = 'Convert PixelType values macros and functionsn'
- 'Do not include directly, use GP_Convert.h',
+ descr = 'Convert PixelType values macros and functions',
authors = ["2011 - Tomas Gavenciak <gavento(a)ucw.cz>"])
def core_GP_Convert_gen_h(h, c):
h.rhead('#include "GP_Common.h"n');
diff --git a/pylib/gfxprim/generators/core/make_GP_Pixel.py b/pylib/gfxprim/generators/core/make_GP_Pixel.py
index fc99657..05cc28e 100644
--- a/pylib/gfxprim/generators/core/make_GP_Pixel.py
+++ b/pylib/gfxprim/generators/core/make_GP_Pixel.py
@@ -3,7 +3,6 @@
# Script generating:
#
# GP_Pixel.gen.c, GP_Pixel.gen.h
-# GP_Pixel_Scale.gen.h
# GP_Pixel_Access.gen.h
#
# 2011 - Tomas Gavenciak <gavento(a)ucw.cz>
@@ -14,26 +13,6 @@ from gfxprim.generators.pixeltype import *
from gfxprim.generators.core.gen_pixeltype import *
from gfxprim.generators.core.gen_getputpixel import *
-@generator(CHeaderGenerator(name = 'GP_Pixel_Scale.gen.h'),
- descr = 'Fast value scaling macrosnDo not include directly, use GP_Pixel.h',
- authors = ["2011 - Tomas Gavenciak <gavento(a)ucw.cz>"])
-def core_GP_Pixel_Scale_gen(h):
- h.rhead(
- "/* helper macros to transfer s1-bit value to s2-bit valuen"
- " * NOTE: efficient and accurate for both up- and downscaling,n"
- " * WARNING: GP_SCALE_VAL requires constants numebrs as first two parametersn"
- " */n"
- "#define GP_SCALE_VAL(s1, s2, val) ( GP_SCALE_VAL_##s1##_##s2(val) )nn"
-
- "{% for s1 in [1, 2, 4, 8] %}{% for s2 in [1, 2, 4, 8] %}"
- "{% if s2>s1 %}"
- "#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) ((val) * {{ multcoef(s1, s2) }})n"
- "{% else %}"
- "#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) ((val) >> {{ s1 - s2 }})n"
- "{% endif %}"
- "{% endfor %}{% endfor %}", multcoef = lambda s1,s2: hex(sum([1<<i*s1 for i in range(s2/s1)]))
- )
-
@generator(CHeaderGenerator(name='GP_Pixel.gen.h'),
CSourceGenerator(name='GP_Pixel.gen.c'),
descr = 'Pixel type definitions and functionsnDo not include directly, use GP_Pixel.h',
http://repo.or.cz/w/gfxprim.git/commit/4b24345dd60ebbc38dccca753476ebf32cb7…
commit 4b24345dd60ebbc38dccca753476ebf32cb72df0
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 00:56:36 2011 +0200
Write up more conversion code, almost complete
diff --git a/include/core/GP_Convert.h b/include/core/GP_Convert.h
index bf1580b..c1c44ef 100644
--- a/include/core/GP_Convert.h
+++ b/include/core/GP_Convert.h
@@ -26,13 +26,40 @@
#include "GP_Common.h"
#include "GP_Context.h"
+/* Generated header */
+#include "GP_Convert.gen.h"
+
+/*
+ * Generated function to convert RGB888 to any type.
+ * Does not work with palette types.
+ */
+GP_Pixel GP_RGB888ToPixel(GP_Pixel pixel, GP_PixelType type);
+
+/*
+ * Generated function to convert RGBA8888 to any type.
+ * Does not work with palette types.
+ */
+GP_Pixel GP_RGBA8888ToPixel(GP_Pixel pixel, GP_PixelType type);
+
+/*
+ * Generated function to convert to RGB888 from any type.
+ * Does not work with palette types.
+ */
+GP_Pixel GP_PixelToRGB888(GP_Pixel pixel, GP_PixelType type);
+
+/*
+ * Generated function to convert to RGBA8888 from any type.
+ * Does not work with palette types.
+ */
+GP_Pixel GP_PixelToRGBA8888(GP_Pixel pixel, GP_PixelType type);
+
/*
* Converts a color specified by its R, G, B components to a specified type.
*/
static inline GP_Pixel GP_RGBToPixel(uint8_t r, uint8_t g, uint8_t b, GP_PixelType type)
{
GP_Pixel p = GP_Pixel_CREATE_RGB888(r, g, b);
- return GP_RGB888ToType(p, type);
+ return GP_RGB888ToPixel(p, type);
}
/*
@@ -41,7 +68,7 @@ static inline GP_Pixel GP_RGBToPixel(uint8_t r, uint8_t g, uint8_t b, GP_PixelTy
static inline GP_Pixel GP_RGBAToPixel(uint8_t r, uint8_t g, uint8_t b, uint8_t a, GP_PixelType type)
{
GP_Pixel p = GP_Pixel_CREATE_RGBA8888(r, g, b, a);
- return GP_RGBA8888ToType(p, type);
+ return GP_RGBA8888ToPixel(p, type);
}
/*
@@ -55,27 +82,29 @@ static inline GP_Pixel GP_RGBToContextPixel(uint8_t r, uint8_t g, uint8_t b,
}
/*
- * Generated function to convert RGB888 to any type.
- * Does not work with palette types.
- */
-GP_Pixel GP_RGB888ToPixel(GP_Pixel pixel, GP_PixelType type);
-
-/*
- * Generated function to convert RGBA8888 to any type.
- * Does not work with palette types.
+ * Converts a color specified by its R, G, B, A components to a pixel value
+ * compatible with the specified context.
*/
-GP_Pixel GP_RGBA8888ToPixel(GP_Pixel pixel, GP_PixelType type);
+static inline GP_Pixel GP_RGBAToContextPixel(uint8_t r, uint8_t g, uint8_t b, uint8_t a, const GP_Context *context)
+{
+ return GP_RGBAToPixel(r, g, b, a, context->pixel_type);
+}
/*
- * Generated function to convert to RGB888 from any type.
- * Does not work with palette types.
+ * Convert between any pixel types (excl. palette types) via RGBA8888
*/
-GP_Pixel GP_PixelToRGB888(GP_Pixel pixel, GP_PixelType type);
-
+static inline GP_Pixel GP_ConvertPixel(GP_Pixel pixel, GP_PixelType from, GP_PixelType to)
+{
+ return GP_RGBA8888ToPixel(GP_PixelToRGBA8888(from, pixel), to);
+}
+
/*
- * Generated function to convert to RGBA8888 from any type.
- * Does not work with palette types.
+ * Convert between pixel types of given contexts (excl. palette types) via RGBA8888.
+ *
*/
-GP_Pixel GP_PixelToRGBA8888(GP_Pixel pixel, GP_PixelType type);
+static inline GP_Pixel GP_ConvertContextPixel(GP_Pixel pixel, const GP_Context *from, const GP_Context *to)
+{
+ return GP_RGBA8888ToPixel(GP_PixelToRGBA8888(from->pixel_type, pixel), to->pixel_type);
+}
#endif /* CORE_GP_CONVERT_H */
diff --git a/pylib/gfxprim/generators/core/gen_convert.py b/pylib/gfxprim/generators/core/gen_convert.py
index a136649..84c2b69 100644
--- a/pylib/gfxprim/generators/core/gen_convert.py
+++ b/pylib/gfxprim/generators/core/gen_convert.py
@@ -28,10 +28,10 @@ def gen_fixedtype_to_type(fixedtype, header, code):
"{% endif %}"
"{% endfor %}"
" default:n"
- " GP_ABORT("Unknown PixelType %ld", type);n"
+ " GP_ABORT("Unknown PixelType %ud", type);n"
" }n"
" return p;n"
- "}n", f=fixedtype, types=pixeltypes.values())
+ "}nn", f=fixedtype, types=pixeltypes.values())
def gen_type_to_fixedtype(fixedtype, header, code):
"Generate functions converting to a fixed PixelType from any other"
@@ -57,10 +57,10 @@ def gen_type_to_fixedtype(fixedtype, header, code):
"{% endif %}"
"{% endfor %}"
" default:n"
- " GP_ABORT("Unknown PixelType %ld", type);n"
+ " GP_ABORT("Unknown PixelType %u", type);n"
" }n"
" return p;n"
- "}n", f=fixedtype, types=pixeltypes.values())
+ "}nn", f=fixedtype, types=pixeltypes.values())
def gen_convert_to(f1, f2, header, code):
"Generate a macro converting from f1 to f2"
@@ -80,25 +80,25 @@ def gen_convert_to(f1, f2, header, code):
# case 1: just copy a channel
"{%- if c2[0] in f1.chans.keys() %}{% set c1 = f1.chans[c2[0]] %}"
- " /* {{ c2[0] }}:={{ c1[0] }} */ GP_SET_BITS({{c2[1]}}+o2,
"
- " GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1)), p2);
"
+ " /* {{ c2[0] }}:={{ c1[0] }} */ GP_SET_BITS({{c2[1]}}+o2, {{c2[2]}}, p2,
"
+ " GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1)));
"
# case 2: set A to full opacity (not present in source)
"{% elif c2[0]=='A' %}"
- " /* A:={{ hmask(c2[2]) }} */GP_SET_BITS({{c2[1]}}+o2, {{ hmask(c2[2]) }}, p2);
"
+ " /* A:={{ hmask(c2[2]) }} */GP_SET_BITS({{c2[1]}}+o2, {{c2[2]}}, p2, {{ hmask(c2[2]) }});
"
# case 3: calculate V as average of RGB
"{% elif c2[0]=='V' and set('RGB').issubset(set(f1.chans.keys())) %}"
- " /* V:=RGB_avg */ GP_SET_BITS({{c2[1]}}+o2, (
"
+ " /* V:=RGB_avg */ GP_SET_BITS({{c2[1]}}+o2, {{c2[2]}}, p2, (
"
"{% for c1 in [f1.chans['R'], f1.chans['G'], f1.chans['B']] %}"
- " /* {{c1[0]}} */ GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1), p2) +
"
+ " /* {{c1[0]}} */ GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1)) +
"
"{% endfor %}"
" 0)/3);
"
#- case 4: set each RGB to V
"{% elif c2[0] in 'RGB' and 'V' in f1.chans.keys() %}{% set c1 = f1.chans['V'] %}"
- " /* {{ c2[0] }}:=V */ GP_SET_BITS({{c2[1]}}+o2,
"
- " GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1)), p2);
"
+ " /* {{ c2[0] }}:=V */ GP_SET_BITS({{c2[1]}}+o2, {{c2[2]}}, p2,
"
+ " GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1)));
"
# invalid mapping (there should be none, but who knows ...)
"{% else %} {{ raise(Error('channel conversion' +f1.name+ ' to ' +f2.name+ ' not supported')) }}"
@@ -111,6 +111,6 @@ def gen_convert_to(f1, f2, header, code):
# add version without offsets
"/* a version without offsets */n"
"#define GP_Pixel_{{ f1.name }}_TO_{{ f2.name }}(p1, p2) "
- "(GP_Pixel_{{ f1.name }}_TO_{{ f2.name }}_OFFSET(p1, 0, p2, 0))n",
+ "GP_Pixel_{{ f1.name }}_TO_{{ f2.name }}_OFFSET(p1, 0, p2, 0)n",
f1=f1, f2=f2, hmask=hmask, set=set)
diff --git a/pylib/gfxprim/generators/core/make_GP_Convert.py b/pylib/gfxprim/generators/core/make_GP_Convert.py
index e8c7360..1800a2c 100644
--- a/pylib/gfxprim/generators/core/make_GP_Convert.py
+++ b/pylib/gfxprim/generators/core/make_GP_Convert.py
@@ -22,8 +22,7 @@ def core_GP_Convert_gen_h(h, c):
h.rhead('#include "GP_Context.h"n');
h.rhead('#include "GP_Pixel.h"nn');
- h.rhead('#include "GP_Common.h"n');
- c.rhead('#include "GP_Pixel.h"nn');
+ c.rhead('#include "GP_Convert.h"nn');
## two base types for conversions
for bt in [pixeltypes['RGB888'], pixeltypes['RGBA8888']]:
http://repo.or.cz/w/gfxprim.git/commit/47c5f5f4b32da3d004ffa2c037857c8323ea…
commit 47c5f5f4b32da3d004ffa2c037857c8323ea1a1f
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 00:54:55 2011 +0200
Rename pixel_access -> getputpixel in gener. libs as well
diff --git a/pylib/gfxprim/generators/core/gen_pixel_access.py b/pylib/gfxprim/generators/core/gen_getputpixel.py
similarity index 100%
rename from pylib/gfxprim/generators/core/gen_pixel_access.py
rename to pylib/gfxprim/generators/core/gen_getputpixel.py
diff --git a/pylib/gfxprim/generators/core/make_GP_Pixel.py b/pylib/gfxprim/generators/core/make_GP_Pixel.py
index 0ade754..fc99657 100644
--- a/pylib/gfxprim/generators/core/make_GP_Pixel.py
+++ b/pylib/gfxprim/generators/core/make_GP_Pixel.py
@@ -12,7 +12,7 @@
from gfxprim.generators.generator import *
from gfxprim.generators.pixeltype import *
from gfxprim.generators.core.gen_pixeltype import *
-from gfxprim.generators.core.gen_pixel_access import *
+from gfxprim.generators.core.gen_getputpixel import *
@generator(CHeaderGenerator(name = 'GP_Pixel_Scale.gen.h'),
descr = 'Fast value scaling macrosnDo not include directly, use GP_Pixel.h',
http://repo.or.cz/w/gfxprim.git/commit/c4ac868f69649ea94eab4a650b49ca25dcd2…
commit c4ac868f69649ea94eab4a650b49ca25dcd2c490
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 00:20:00 2011 +0200
Fixed Makefile (gen files), disable overflow warning
diff --git a/libs/core/Makefile b/libs/core/Makefile
index c3692df..bce6f9d 100644
--- a/libs/core/Makefile
+++ b/libs/core/Makefile
@@ -1,8 +1,9 @@
TOPDIR=../..
-GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c GP_Convert.gen.c GP_Convert.gen.h
-GENHEADERS=GP_Pixel_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h GP_GetPutPixel.gen.h
+GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c GP_Convert.gen.c
+GENHEADERS=GP_Pixel_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h GP_GetPutPixel.gen.h GP_Convert.gen.h
CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
LIBNAME=core
+CFLAGS+=-Wno-overflow
include $(TOPDIR)/gen.mk
include $(TOPDIR)/include.mk
http://repo.or.cz/w/gfxprim.git/commit/51e969cd103ec6546ec91af744157338d352…
commit 51e969cd103ec6546ec91af744157338d352896c
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 00:15:09 2011 +0200
Remove annoying readout in pixeltype loading
replaced by warning in case nothing is loaded
diff --git a/pylib/gfxprim/generators/pixeltype.py b/pylib/gfxprim/generators/pixeltype.py
index e43ffce..92586ab 100644
--- a/pylib/gfxprim/generators/pixeltype.py
+++ b/pylib/gfxprim/generators/pixeltype.py
@@ -104,11 +104,7 @@ def load_pixeltypes(defs_file = None):
if not defs_file:
path = os.path.dirname(os.path.abspath(__file__))
defs_file = os.path.join(path, '..', '..', 'pixeltypes.py')
- sys.stderr.write("Opening PixelType defs file '" + defs_file + "'n")
- l1 = len(pixeltypes)
execfile(defs_file)
- l2 = len(pixeltypes)
- sys.stderr.write("Read %d PixelTypes, now %d totaln" % (l2 - l1, l2))
def __init__():
"Initialize PixelType UNKNOWN.n"
@@ -116,6 +112,9 @@ def __init__():
if 0 not in pixeltypes:
PixelType("UNKNOWN", 0, [], bit_endian=bit_endians[0], number=0)
load_pixeltypes()
+ # check if some types were loaded
+ if len(pixeltypes) <= 1:
+ sys.stderr.write("WARNING: no PixelTypes were loaded.")
__init__()
http://repo.or.cz/w/gfxprim.git/commit/f11293be8118c9707b268f55ba49dc6ea8b1…
commit f11293be8118c9707b268f55ba49dc6ea8b111ff
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 12 00:00:41 2011 +0200
Implemented various PixelType conversions
diff --git a/include/core/GP_Convert.h b/include/core/GP_Convert.h
new file mode 100644
index 0000000..bf1580b
--- /dev/null
+++ b/include/core/GP_Convert.h
@@ -0,0 +1,81 @@
+/*****************************************************************************
+ * 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) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#ifndef CORE_GP_CONVERT_H
+#define CORE_GP_CONVERT_H
+
+#include "GP_Common.h"
+#include "GP_Context.h"
+
+/*
+ * Converts a color specified by its R, G, B components to a specified type.
+ */
+static inline GP_Pixel GP_RGBToPixel(uint8_t r, uint8_t g, uint8_t b, GP_PixelType type)
+{
+ GP_Pixel p = GP_Pixel_CREATE_RGB888(r, g, b);
+ return GP_RGB888ToType(p, type);
+}
+
+/*
+ * Converts a color specified by its R, G, B, A components to a specified type.
+ */
+static inline GP_Pixel GP_RGBAToPixel(uint8_t r, uint8_t g, uint8_t b, uint8_t a, GP_PixelType type)
+{
+ GP_Pixel p = GP_Pixel_CREATE_RGBA8888(r, g, b, a);
+ return GP_RGBA8888ToType(p, type);
+}
+
+/*
+ * Converts a color specified by its R, G, B components to a pixel value
+ * compatible with the specified context.
+ */
+static inline GP_Pixel GP_RGBToContextPixel(uint8_t r, uint8_t g, uint8_t b,
+ const GP_Context *context)
+{
+ return GP_RGBToPixel(r, g, b, context->pixel_type);
+}
+
+/*
+ * Generated function to convert RGB888 to any type.
+ * Does not work with palette types.
+ */
+GP_Pixel GP_RGB888ToPixel(GP_Pixel pixel, GP_PixelType type);
+
+/*
+ * Generated function to convert RGBA8888 to any type.
+ * Does not work with palette types.
+ */
+GP_Pixel GP_RGBA8888ToPixel(GP_Pixel pixel, GP_PixelType type);
+
+/*
+ * Generated function to convert to RGB888 from any type.
+ * Does not work with palette types.
+ */
+GP_Pixel GP_PixelToRGB888(GP_Pixel pixel, GP_PixelType type);
+
+/*
+ * Generated function to convert to RGBA8888 from any type.
+ * Does not work with palette types.
+ */
+GP_Pixel GP_PixelToRGBA8888(GP_Pixel pixel, GP_PixelType type);
+
+#endif /* CORE_GP_CONVERT_H */
diff --git a/include/core/GP_Pixel.h b/include/core/GP_Pixel.h
index a1469e8..7ac0fb7 100644
--- a/include/core/GP_Pixel.h
+++ b/include/core/GP_Pixel.h
@@ -21,6 +21,8 @@
* *
* Copyright (C) 2009-2010 Cyril Hrubis <metan(a)ucw.cz> *
* *
+ * Copyright (C) 2011 Tomas Gavenciak <gavento(a)ucw.cz> *
+ * *
*****************************************************************************/
#ifndef GP_PIXEL_H
@@ -135,38 +137,4 @@ static inline uint32_t GP_PixelSize(GP_PixelType type)
return GP_PixelTypes[type].size;
}
-
-/* Below -- TODO sync with new pixel type */
-
-/*
- * Returns GP_PixelType to GP_ColorType mapping.
- */
-//GP_ColorType GP_PixelTypeToColorType(GP_PixelType type);
-
-/*
- * Converts a color to the specified pixel type.
- */
-//GP_RetCode GP_ColorToPixelType(GP_PixelType pixel_type, GP_Color color, GP_Pixel *pixel);
-
-/*
- * Converts a color to a pixel value suitable for the specified context.
- */
-//GP_RetCode GP_ColorToPixel(struct GP_Context *context, GP_Color color, GP_Pixel *pixel);
-
-/*
- *
- */
-//GP_RetCode GP_ColorNameToPixel(struct GP_Context *context, GP_ColorName name, GP_Pixel *pixel);
-
-/*
- * Converts a color name to the specified pixel type.
- */
-//GP_RetCode GP_ColorNameToPixelType(GP_PixelType pixel_type, GP_ColorName name, GP_Pixel *pixel);
-
-/*
- * Converts a color specified by its R, G, B components to a pixel value
- * compatible with the specified context.
- */
-GP_RetCode GP_RGBToPixel(struct GP_Context *context, uint8_t r, uint8_t g, uint8_t b, GP_Pixel *pixel);
-
#endif /* GP_PIXEL_H */
diff --git a/libs/core/Makefile b/libs/core/Makefile
index 9ed6c65..c3692df 100644
--- a/libs/core/Makefile
+++ b/libs/core/Makefile
@@ -1,5 +1,5 @@
TOPDIR=../..
-GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c
+GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c GP_Convert.gen.c GP_Convert.gen.h
GENHEADERS=GP_Pixel_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h GP_GetPutPixel.gen.h
CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
LIBNAME=core
diff --git a/pylib/gfxprim/generators/core/gen_convert.py b/pylib/gfxprim/generators/core/gen_convert.py
new file mode 100644
index 0000000..a136649
--- /dev/null
+++ b/pylib/gfxprim/generators/core/gen_convert.py
@@ -0,0 +1,116 @@
+# Module generating C source and headers for various PixelType conversions
+# 2011 - Tomas Gavenciak <gavento(a)ucw.cz>
+
+from gfxprim.generators.pixeltype import pixeltypes, channels
+from gfxprim.generators.utils import hmask
+
+def gen_fixedtype_to_type(fixedtype, header, code):
+ "Generate functions converting a fixed PixelType to any other"
+ "Does not work on palette types at all (yet)"
+ code.rbody(
+ "GP_Pixel GP_{{ f.name }}ToPixel(GP_Pixel pixel, GP_PixelType type)n"
+ "{n"
+ " GP_Pixel p = 0;n"
+ " switch(type) {n"
+ "{% for tf in types %}"
+ "{% if tf.number == 0 %}"
+ " case GP_PIXEL_UNKNOWN:n"
+ " GP_ABORT("Cannot convert to GP_PIXEL_UNKNOWN");n"
+ " break;n"
+ "{% elif tf.is_palette() %}"
+ " case GP_PIXEL_{{ tf.name }}:n"
+ " GP_ABORT("Cannot convert to palette type {{ tf.name }}");n"
+ " break;n"
+ "{% else %}"
+ " case GP_PIXEL_{{ tf.name }}:n"
+ " GP_Pixel_{{ f.name }}_TO_{{ tf.name }}(pixel, p);n"
+ " break;n"
+ "{% endif %}"
+ "{% endfor %}"
+ " default:n"
+ " GP_ABORT("Unknown PixelType %ld", type);n"
+ " }n"
+ " return p;n"
+ "}n", f=fixedtype, types=pixeltypes.values())
+
+def gen_type_to_fixedtype(fixedtype, header, code):
+ "Generate functions converting to a fixed PixelType from any other"
+ "Does not work on palette types at all (yet)"
+ code.rbody(
+ "GP_Pixel GP_PixelTo{{ f.name }}(GP_Pixel pixel, GP_PixelType type)n"
+ "{n"
+ " GP_Pixel p = 0;n"
+ " switch(type) {n"
+ "{% for sf in types %}"
+ "{% if sf.number == 0 %}"
+ " case GP_PIXEL_UNKNOWN:n"
+ " GP_ABORT("Cannot convert from GP_PIXEL_UNKNOWN");n"
+ " break;n"
+ "{% elif sf.is_palette() %}"
+ " case GP_PIXEL_{{ sf.name }}:n"
+ " GP_ABORT("Cannot convert from palette type {{ sf.name }} (yet)");n"
+ " break;n"
+ "{% else %}"
+ " case GP_PIXEL_{{ sf.name }}:n"
+ " GP_Pixel_{{ sf.name }}_TO_{{ f.name }}(pixel, p);n"
+ " break;n"
+ "{% endif %}"
+ "{% endfor %}"
+ " default:n"
+ " GP_ABORT("Unknown PixelType %ld", type);n"
+ " }n"
+ " return p;n"
+ "}n", f=fixedtype, types=pixeltypes.values())
+
+def gen_convert_to(f1, f2, header, code):
+ "Generate a macro converting from f1 to f2"
+ "This function supports only RGBVA types (no palettes"
+ allowed_chansets = [ set(list(s)) for s in ['RGB', 'RGBA', 'V', 'VA'] ]
+ assert(set(f1.chans.keys()) in allowed_chansets)
+ assert(set(f2.chans.keys()) in allowed_chansets)
+
+ header.rbody(
+ "n/*** {{ f1.name }} -> {{ f2.name }} ***n"
+ " * macro storing p1 ({{ f1.name }} at bit-offset o1) in p2 ({{ f2.name }} at bit-offset o2),n"
+ " * the relevant part of p2 is assumed to be clear (zero) */nn"
+ "#define GP_Pixel_{{ f1.name }}_TO_{{ f2.name }}_OFFSET(p1, o1, p2, o2) do {
"
+
+ ## set each of <TARGET> channels
+ "{% for c2 in f2.chanslist %}"
+
+ # case 1: just copy a channel
+ "{%- if c2[0] in f1.chans.keys() %}{% set c1 = f1.chans[c2[0]] %}"
+ " /* {{ c2[0] }}:={{ c1[0] }} */ GP_SET_BITS({{c2[1]}}+o2,
"
+ " GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1)), p2);
"
+
+ # case 2: set A to full opacity (not present in source)
+ "{% elif c2[0]=='A' %}"
+ " /* A:={{ hmask(c2[2]) }} */GP_SET_BITS({{c2[1]}}+o2, {{ hmask(c2[2]) }}, p2);
"
+
+ # case 3: calculate V as average of RGB
+ "{% elif c2[0]=='V' and set('RGB').issubset(set(f1.chans.keys())) %}"
+ " /* V:=RGB_avg */ GP_SET_BITS({{c2[1]}}+o2, (
"
+ "{% for c1 in [f1.chans['R'], f1.chans['G'], f1.chans['B']] %}"
+ " /* {{c1[0]}} */ GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1), p2) +
"
+ "{% endfor %}"
+ " 0)/3);
"
+
+ #- case 4: set each RGB to V
+ "{% elif c2[0] in 'RGB' and 'V' in f1.chans.keys() %}{% set c1 = f1.chans['V'] %}"
+ " /* {{ c2[0] }}:=V */ GP_SET_BITS({{c2[1]}}+o2,
"
+ " GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1)), p2);
"
+
+ # invalid mapping (there should be none, but who knows ...)
+ "{% else %} {{ raise(Error('channel conversion' +f1.name+ ' to ' +f2.name+ ' not supported')) }}"
+
+ # end of the loop
+ "{% endif %}"
+ "{% endfor %}"
+ "} while (0)nn"
+
+ # add version without offsets
+ "/* a version without offsets */n"
+ "#define GP_Pixel_{{ f1.name }}_TO_{{ f2.name }}(p1, p2) "
+ "(GP_Pixel_{{ f1.name }}_TO_{{ f2.name }}_OFFSET(p1, 0, p2, 0))n",
+ f1=f1, f2=f2, hmask=hmask, set=set)
+
diff --git a/pylib/gfxprim/generators/core/gen_pixeltype.py b/pylib/gfxprim/generators/core/gen_pixeltype.py
index ea3ae20..ba25a20 100644
--- a/pylib/gfxprim/generators/core/gen_pixeltype.py
+++ b/pylib/gfxprim/generators/core/gen_pixeltype.py
@@ -1,12 +1,6 @@
# Module generating C source and headers for various PixelTypes
# 2011 - Tomas Gavenciak <gavento(a)ucw.cz>
-"""
-The functions gen_* generate both source and header.
-Such functions accept (and then extend) two list of strins.
-These should be later joined with "" or "
".
-"""
-
from gfxprim.generators.pixeltype import pixeltypes, channels
from gfxprim.generators.utils import j2render as r, hmask
@@ -89,60 +83,19 @@ def gen_get_chs(ptype, header, code):
header.rbody(
"/* macros to get channels of pixel type {{ f.name }} */n"
"{% for c in f.chanslist %}"
- "#define GP_Pixel_GET_{{ c[0] }}_{{ f.name }}(p) (GP_GET_BITS({{ c[1] }}, {{ c[2] }}, (p)))n"
+ "#define GP_Pixel_GET_{{ c[0] }}_{{ f.name }}(p) (GP_GET_BITS({{ c[1] }}, {{ c[2] }}, (p)))n"
"{% endfor %}", f=ptype)
-def gen_convert_to(f1, f2, header, code):
- "Generate a macro converting from f1 to f2"
- "This function supports only RGBVA types (no palettes"
- allowed_chansets = [ set(list(s)) for s in ['RGB', 'RGBA', 'V', 'VA'] ]
- assert(set(f1.chans.keys()) in allowed_chansets)
- assert(set(f2.chans.keys()) in allowed_chansets)
-
+def gen_create(ptype, header, code):
+ "Generate GP_Pixel_CREATE_<TYPE> macros"
header.rbody(
- "n/*** {{ f1.name }} -> {{ f2.name }} ***n"
- " * macro storing p1 ({{ f1.name }} at bit-offset o1) in p2 ({{ f2.name }} at bit-offset o2),n"
- " * the relevant part of p2 is assumed to be clear (zero) */nn"
- "#define GP_Pixel_{{ f1.name }}_TO_{{ f2.name }}_OFFSET(p1, o1, p2, o2) do {
"
-
- ## set each of <TARGET> channels
- "{% for c2 in f2.chanslist %}"
-
- # case 1: just copy a channel
- "{%- if c2[0] in f1.chans.keys() %}{% set c1 = f1.chans[c2[0]] %}"
- " /* {{ c2[0] }}:={{ c1[0] }} */ GP_SET_BITS({{c2[1]}}+o2,
"
- " GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1)), p2);
"
-
- # case 2: set A to full opacity (not present in source)
- "{% elif c2[0]=='A' %}"
- " /* A:={{ hmask(c2[2]) }} */GP_SET_BITS({{c2[1]}}+o2, {{ hmask(c2[2]) }}, p2);
"
-
- # case 3: calculate V as average of RGB
- "{% elif c2[0]=='V' and set('RGB').issubset(set(f1.chans.keys())) %}"
- " /* V:=RGB_avg */ GP_SET_BITS({{c2[1]}}+o2, (
"
- "{% for c1 in [f1.chans['R'], f1.chans['G'], f1.chans['B']] %}"
- " /* {{c1[0]}} */ GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1), p2) +
"
- "{% endfor %}"
- " 0)/3);
"
-
- #- case 4: set each RGB to V
- "{% elif c2[0] in 'RGB' and 'V' in f1.chans.keys() %}{% set c1 = f1.chans['V'] %}"
- " /* {{ c2[0] }}:=V */ GP_SET_BITS({{c2[1]}}+o2,
"
- " GP_SCALE_VAL_{{c1[2]}}_{{c2[2]}}(GP_GET_BITS({{c1[1]}}+o1, {{c1[2]}}, p1)), p2);
"
-
- # invalid mapping (there should be none, but who knows ...)
- "{% else %} {{ raise(Error('channel conversion' +f1.name+ ' to ' +f2.name+ ' not supported')) }}"
-
- # end of the loop
- "{% endif %}"
- "{% endfor %}"
- "} while (0)nn"
-
- # add version without offsets
- "/* a version without offsets */n"
- "#define GP_Pixel_{{ f1.name }}_TO_{{ f2.name }}(p1, p2) "
- "(GP_Pixel_{{ f1.name }}_TO_{{ f2.name }}_OFFSET(p1, 0, p2, 0))n",
- f1=f1, f2=f2, hmask=hmask, set=set)
+ "/* macros to create GP_Pixel of pixel type {{ f.name }} directly from given values.n"
+ " * The values are NOT clipped to actual value ranges.*/n"
+ "#define GP_Pixel_CREATE_{{ f.name }}({{ args }}) (0
"
+ "{% for c in f.chanslist %}"
+ " + (({{ c[0] }}) << {{ c[1] }})
"
+ "{% endfor %}"
+ " )n", f=ptype, args=', '.join([c[0] for c in ptype.chanslist]))
def gen_get_pixel_addr(ptype, header, code):
"Generate GP_PIXEL_ADDR_<TYPE> and _OFFSET_<TYPE> macros"
diff --git a/pylib/gfxprim/generators/core/make_GP_Convert.py b/pylib/gfxprim/generators/core/make_GP_Convert.py
new file mode 100644
index 0000000..e8c7360
--- /dev/null
+++ b/pylib/gfxprim/generators/core/make_GP_Convert.py
@@ -0,0 +1,41 @@
+#!/usr/bin/python
+#
+# Script generating:
+#
+# GP_Convert.gen.c, GP_Convert.gen.h
+#
+# 2011 - Tomas Gavenciak <gavento(a)ucw.cz>
+#
+
+from gfxprim.generators.generator import *
+from gfxprim.generators.pixeltype import *
+from gfxprim.generators.core.gen_convert import *
+
+
+@generator(CHeaderGenerator(name = 'GP_Convert.gen.h'),
+ CSourceGenerator(name = 'GP_Convert.gen.c'),
+ descr = 'Convert PixelType values macros and functionsn'
+ 'Do not include directly, use GP_Convert.h',
+ authors = ["2011 - Tomas Gavenciak <gavento(a)ucw.cz>"])
+def core_GP_Convert_gen_h(h, c):
+ h.rhead('#include "GP_Common.h"n');
+ h.rhead('#include "GP_Context.h"n');
+ h.rhead('#include "GP_Pixel.h"nn');
+
+ h.rhead('#include "GP_Common.h"n');
+ c.rhead('#include "GP_Pixel.h"nn');
+
+ ## two base types for conversions
+ for bt in [pixeltypes['RGB888'], pixeltypes['RGBA8888']]:
+ gen_fixedtype_to_type(bt, h, c)
+ gen_type_to_fixedtype(bt, h, c)
+ ## Conversion macros
+ for t in pixeltypes.values():
+ if not t.is_palette() and t.number != 0:
+ gen_convert_to(t, bt, h, c)
+ gen_convert_to(bt, t, h, c)
+
+ ## Just experimental conversion macros
+ gen_convert_to(pixeltypes['RGB565'], pixeltypes['RGBA8888'], h, c)
+ gen_convert_to(pixeltypes['RGBA8888'], pixeltypes['V2'], h, c)
+ gen_convert_to(pixeltypes['VA12'], pixeltypes['RGBA8888'], h, c)
diff --git a/pylib/gfxprim/generators/core/make_GP_Pixel.py b/pylib/gfxprim/generators/core/make_GP_Pixel.py
index 21cb252..0ade754 100644
--- a/pylib/gfxprim/generators/core/make_GP_Pixel.py
+++ b/pylib/gfxprim/generators/core/make_GP_Pixel.py
@@ -60,11 +60,7 @@ def core_GP_Pixel_gen(h, c):
gen_print(t, h, c)
gen_get_chs(t, h, c)
gen_get_pixel_addr(t, h, c)
-
- ## Conversion macros
- gen_convert_to(pixeltypes['RGB565'], pixeltypes['RGBA8888'], h, c)
- gen_convert_to(pixeltypes['RGBA8888'], pixeltypes['V2'], h, c)
- gen_convert_to(pixeltypes['VA12'], pixeltypes['RGBA8888'], h, c)
+ gen_create(t, h, c)
@generator(CHeaderGenerator(name = 'GP_GetPutPixel.gen.h'),
diff --git a/pylib/gfxprim/generators/pixeltype.py b/pylib/gfxprim/generators/pixeltype.py
index 384930d..e43ffce 100644
--- a/pylib/gfxprim/generators/pixeltype.py
+++ b/pylib/gfxprim/generators/pixeltype.py
@@ -91,6 +91,9 @@ class PixelType(object):
def __str__(self):
return "<PixelType " + self.name + ">"
+ def is_palette(self):
+ return ('P' in self.chans)
+
def load_pixeltypes(defs_file = None):
"Initialize pixeltypes by loading the defs file.n"
"Looks for the file by parameter, env['PIXELTYPE_DEFS'] and "
diff --git a/pylib/gfxprim/generators/utils.py b/pylib/gfxprim/generators/utils.py
index 3ddc7ad..fe5abb4 100644
--- a/pylib/gfxprim/generators/utils.py
+++ b/pylib/gfxprim/generators/utils.py
@@ -19,6 +19,7 @@ def load_generators():
import gfxprim.generators.make_collected_tests
import gfxprim.generators.core.make_GP_Pixel
import gfxprim.generators.core.make_GP_Blit
+ import gfxprim.generators.core.make_GP_Convert
pass
def generate_file(fname):
http://repo.or.cz/w/gfxprim.git/commit/6aa9b93dc730b452effb253df5a051bc7916…
commit 6aa9b93dc730b452effb253df5a051bc791692ef
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Jun 11 22:37:20 2011 +0200
More pruning old code
diff --git a/libs/core/GP_Pixel.c b/libs/core/GP_Pixel.c
deleted file mode 100644
index eedd94a..0000000
--- a/libs/core/GP_Pixel.c
+++ /dev/null
@@ -1,235 +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_Core.h"
-
-/////// removed by gavento
-// struct PixelTypeInfo {
-// const char *type_name; /* human-readable name */
-// GP_ColorType color_type; /* color type used for this pixel type */
-// unsigned int bits; /* how many bits the pixel occupies */
-// };
-//
-// /* This table shows relations of pixel types to color types, their names
-// * and bits per pixel.
-// */
-// static struct PixelTypeInfo pixel_type_infos[] = {
-// { "Unknown pixel type", GP_NOCOLOR, 0 },
-// { "Palette 4bit", GP_PAL4, 4 },
-// { "Palette 8bit", GP_PAL8, 8 },
-// { "Grayscale 1bit", GP_G1, 1 },
-// { "Grayscale 2bits", GP_G2, 2 },
-// { "Grayscale 4bits", GP_G4, 4 },
-// { "Grayscale 8bits", GP_G8, 8 },
-// { "RGB 555", GP_RGB555, 16 },
-// { "BGR 555", GP_RGB555, 16 },
-// { "RGB 565", GP_RGB565, 16 },
-// { "BGR 565", GP_RGB565, 16 },
-// { "RGB 888", GP_RGB888, 24 },
-// { "BGR 888", GP_RGB888, 24 },
-// { "XRGB 8888", GP_RGB888, 32 },
-// { "RGBX 8888", GP_RGB888, 32 },
-// { "XBGR 8888", GP_RGB888, 32 },
-// { "BGRX 8888", GP_RGB888, 32 },
-// { "ARGB 8888", GP_RGBA8888, 32 },
-// { "RGBA 8888", GP_RGBA8888, 32 },
-// { "ABGR 8888", GP_RGBA8888, 32 },
-// { "BGRA 8888", GP_RGBA8888, 32 }
-// };
-//
-// GP_ColorType GP_PixelTypeToColorType(GP_PixelType type)
-// {
-// if (type >= GP_PIXEL_MAX)
-// return GP_COLMAX;
-//
-// return pixel_type_infos[type].color_type;
-// }
-//
-// #define CHECK_RET(ret) if (ret != GP_ESUCCESS && ret != GP_EUNPRECISE) return ret;
-//
-// GP_RetCode GP_ColorToPixelType(GP_PixelType pixel_type, GP_Color color, GP_Pixel *pixel)
-// {
-// if (pixel == NULL)
-// return GP_ENULLPTR;
-//
-// GP_RetCode ret;
-//
-// switch (pixel_type) {
-// case GP_PIXEL_PAL4:
-// ret = GP_ColorConvert(&color, GP_PAL4);
-// CHECK_RET(ret);
-// *pixel = color.pal4.index;
-// return ret;
-// break;
-// case GP_PIXEL_PAL8:
-// ret = GP_ColorConvert(&color, GP_PAL8);
-// CHECK_RET(ret);
-// *pixel = color.pal8.index;
-// return ret;
-// break;
-// case GP_PIXEL_G1:
-// ret = GP_ColorConvert(&color, GP_G1);
-// CHECK_RET(ret);
-// *pixel = color.g1.gray;
-// return ret;
-// break;
-// case GP_PIXEL_G2:
-// ret = GP_ColorConvert(&color, GP_G2);
-// CHECK_RET(ret);
-// *pixel = color.g2.gray;
-// return ret;
-// break;
-// case GP_PIXEL_G4:
-// ret = GP_ColorConvert(&color, GP_G4);
-// CHECK_RET(ret);
-// *pixel = color.g4.gray;
-// return ret;
-// break;
-// case GP_PIXEL_G8:
-// ret = GP_ColorConvert(&color, GP_G8);
-// CHECK_RET(ret);
-// *pixel = color.g8.gray;
-// return ret;
-// break;
-// case GP_PIXEL_RGB565:
-// ret = GP_ColorConvert(&color, GP_RGB565);
-// CHECK_RET(ret);
-// *pixel = color.rgb565.red << 0x0b |
-// color.rgb565.green << 0x05 |
-// color.rgb565.blue;
-// case GP_PIXEL_RGB888:
-// case GP_PIXEL_XRGB8888:
-// ret = GP_ColorConvert(&color, GP_RGB888);
-// CHECK_RET(ret);
-// *pixel = color.rgb888.red << 0x10 |
-// color.rgb888.green << 0x08 |
-// color.rgb888.blue;
-// return ret;
-// break;
-// case GP_PIXEL_BGR888:
-// case GP_PIXEL_XBGR8888:
-// ret = GP_ColorConvert(&color, GP_RGB888);
-// CHECK_RET(ret);
-// *pixel = color.rgb888.red |
-// color.rgb888.green << 0x08 |
-// color.rgb888.blue << 0x10;
-// return ret;
-// break;
-// case GP_PIXEL_RGBX8888:
-// ret = GP_ColorConvert(&color, GP_RGB888);
-// CHECK_RET(ret);
-// *pixel = color.rgb888.red << 0x18 |
-// color.rgb888.green << 0x10 |
-// color.rgb888.blue << 0x8;
-// return ret;
-// break;
-// case GP_PIXEL_BGRX8888:
-// ret = GP_ColorConvert(&color, GP_RGB888);
-// CHECK_RET(ret);
-// *pixel = color.rgb888.red << 0x08 |
-// color.rgb888.green << 0x10 |
-// color.rgb888.blue << 0x18;
-// return ret;
-// break;
-// case GP_PIXEL_ARGB8888:
-// ret = GP_ColorConvert(&color, GP_RGBA8888);
-// CHECK_RET(ret);
-// *pixel = color.rgba8888.red << 0x10 |
-// color.rgba8888.green << 0x08 |
-// color.rgba8888.blue |
-// color.rgba8888.alpha << 0x18;
-// return ret;
-// break;
-// case GP_PIXEL_RGBA8888:
-// ret = GP_ColorConvert(&color, GP_RGBA8888);
-// CHECK_RET(ret);
-// *pixel = color.rgba8888.red << 0x18 |
-// color.rgba8888.green << 0x10 |
-// color.rgba8888.blue << 0x08 |
-// color.rgba8888.alpha;
-// return ret;
-// break;
-// case GP_PIXEL_ABGR8888:
-// ret = GP_ColorConvert(&color, GP_RGBA8888);
-// CHECK_RET(ret);
-// *pixel = color.rgba8888.red |
-// color.rgba8888.green << 0x08 |
-// color.rgba8888.blue << 0x10 |
-// color.rgba8888.alpha << 0x18;
-// return ret;
-// break;
-// case GP_PIXEL_BGRA8888:
-// ret = GP_ColorConvert(&color, GP_RGBA8888);
-// CHECK_RET(ret);
-// *pixel = color.rgba8888.red << 0x08 |
-// color.rgba8888.green << 0x10 |
-// color.rgba8888.blue << 0x18 |
-// color.rgba8888.alpha;
-// return ret;
-// break;
-// case GP_PIXEL_MAX:
-// break;
-// }
-//
-// if (pixel_type >= GP_PIXEL_MAX)
-// return GP_EINVAL;
-// else
-// return GP_ENOIMPL;
-// }
-//
-// GP_RetCode GP_ColorToPixel(GP_Context *context, GP_Color color, GP_Pixel *pixel)
-// {
-// if (context == NULL || pixel == NULL)
-// return GP_ENULLPTR;
-//
-// return GP_ColorToPixelType(context->pixel_type, color, pixel);
-// }
-//
-// GP_RetCode GP_ColorNameToPixel(GP_Context *context, GP_ColorName name, GP_Pixel *pixel)
-// {
-// if (context == NULL || pixel == NULL)
-// return GP_ENULLPTR;
-//
-// GP_Color color = GP_COLNAME_PACK(name);
-// return GP_ColorToPixelType(context->pixel_type, color, pixel);
-// }
-//
-// GP_RetCode GP_ColorNameToPixelType(GP_PixelType pixel_type, GP_ColorName name, GP_Pixel *pixel)
-// {
-// if (pixel == NULL)
-// return GP_ENULLPTR;
-//
-// GP_Color color = GP_COLNAME_PACK(name);
-// return GP_ColorToPixelType(pixel_type, color, pixel);
-// }
-//
-// GP_RetCode GP_RGBToPixel(GP_Context *context, uint8_t r, uint8_t g, uint8_t b, GP_Pixel *pixel)
-// {
-// if (pixel == NULL)
-// return GP_ENULLPTR;
-//
-// GP_Color color = GP_RGB888_PACK(r, g, b);
-// return GP_ColorToPixelType(context->pixel_type, color, pixel);
-// }
http://repo.or.cz/w/gfxprim.git/commit/93c34cab6ae326bf2ff21a69c973a3922ca9…
commit 93c34cab6ae326bf2ff21a69c973a3922ca9ece7
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Jun 11 22:29:58 2011 +0200
Rename GP_Pixel_Access to GP_GetPutPixel
diff --git a/include/core/GP_Core.h b/include/core/GP_Core.h
index a00f1d7..6d45291 100644
--- a/include/core/GP_Core.h
+++ b/include/core/GP_Core.h
@@ -45,6 +45,6 @@
#include "core/GP_Pixel.h"
/* Individual pixel access */
-#include "core/GP_Pixel_Access.h"
+#include "core/GP_GetPutPixel.h"
#endif /* GP_CORE_H */
diff --git a/include/core/GP_Pixel_Access.h b/include/core/GP_GetPutPixel.h
similarity index 95%
rename from include/core/GP_Pixel_Access.h
rename to include/core/GP_GetPutPixel.h
index 331d7eb..102bf9a 100644
--- a/include/core/GP_Pixel_Access.h
+++ b/include/core/GP_GetPutPixel.h
@@ -20,8 +20,8 @@
* *
*****************************************************************************/
-#ifndef GP_PIXEL_ACCESS_H
-#define GP_PIXEL_ACCESS_H
+#ifndef CORE_GP_GETPUTPIXEL_H
+#define CORE_GP_GETPUTPIXEL_H
#include "GP_Context.h"
#include "GP_FnPerBpp.h"
@@ -30,7 +30,7 @@
/*
* Generated header
*/
-#include "GP_Pixel_Access.gen.h"
+#include "GP_GetPutPixel.gen.h"
/*
* GetPixel with context transformations and clipping.
@@ -62,4 +62,4 @@ static inline void GP_PutPixel_Raw(GP_Context *context, int x, int y, GP_Pixel p
context, x, y, p);
}
-#endif /* GP_PIXEL_ACCESS_H */
+#endif /* CORE_GP_GETPUTPIXEL_H */
diff --git a/include/gfx/GP_Gfx.h b/include/gfx/GP_Gfx.h
index 2f42cb1..aa578b4 100644
--- a/include/gfx/GP_Gfx.h
+++ b/include/gfx/GP_Gfx.h
@@ -37,7 +37,7 @@
#include "core/GP_Transform.h"
#include "core/GP_Context.h"
#include "core/GP_WritePixel.h"
-#include "core/GP_Pixel_Access.h"
+#include "core/GP_GetPutPixel.h"
#include "core/GP_Color.h"
/* public drawing API */
diff --git a/libs/core/GP_Pixel_Access.c b/libs/core/GP_GetPutPixel.c
similarity index 98%
rename from libs/core/GP_Pixel_Access.c
rename to libs/core/GP_GetPutPixel.c
index f2b8924..fe37216 100644
--- a/libs/core/GP_Pixel_Access.c
+++ b/libs/core/GP_GetPutPixel.c
@@ -20,7 +20,7 @@
* *
*****************************************************************************/
-#include "GP_Pixel_Access.h"
+#include "GP_GetPutPixel.h"
#include "GP_Transform.h"
GP_Pixel GP_GetPixel(GP_Context *context, int x, int y)
diff --git a/libs/core/Makefile b/libs/core/Makefile
index 3808736..9ed6c65 100644
--- a/libs/core/Makefile
+++ b/libs/core/Makefile
@@ -1,6 +1,6 @@
TOPDIR=../..
GENSOURCES=GP_Pixel.gen.c GP_Blit.gen.c
-GENHEADERS=GP_Pixel_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h GP_Pixel_Access.gen.h
+GENHEADERS=GP_Pixel_Scale.gen.h GP_Blit.gen.h GP_Pixel.gen.h GP_GetPutPixel.gen.h
CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
LIBNAME=core
diff --git a/pylib/gfxprim/generators/core/make_GP_Pixel.py b/pylib/gfxprim/generators/core/make_GP_Pixel.py
index 0a1ff3b..21cb252 100644
--- a/pylib/gfxprim/generators/core/make_GP_Pixel.py
+++ b/pylib/gfxprim/generators/core/make_GP_Pixel.py
@@ -67,8 +67,8 @@ def core_GP_Pixel_gen(h, c):
gen_convert_to(pixeltypes['VA12'], pixeltypes['RGBA8888'], h, c)
-@generator(CHeaderGenerator(name = 'GP_Pixel_Access.gen.h'),
- descr = 'Access pixel bytes, Put and GetPixelnDo not include directly, use GP_Pixel.h',
+@generator(CHeaderGenerator(name = 'GP_GetPutPixel.gen.h'),
+ descr = 'Access pixel bytes, Get and PutPixelnDo not include directly, use GP_Pixel.h',
authors = ["2011 - Tomas Gavenciak <gavento(a)ucw.cz>"])
def core_GP_Pixel_Scale_gen(h):
h.rhead('#include "GP_Common.h"nn');
http://repo.or.cz/w/gfxprim.git/commit/628bf75875173555777a15ce6a7fe7e91cd3…
commit 628bf75875173555777a15ce6a7fe7e91cd328b8
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Jun 11 22:13:05 2011 +0200
Added basic common pixeltypes to be generated
diff --git a/pylib/pixeltypes.py b/pylib/pixeltypes.py
index 7f77336..4762255 100644
--- a/pylib/pixeltypes.py
+++ b/pylib/pixeltypes.py
@@ -14,6 +14,9 @@
# a complete recompilation is required after any change.
#
+#
+# Standard RGB types
+#
PixelType(name='RGBx8888', size=32, chanslist=[
('R', 0, 8),
@@ -28,20 +31,56 @@ PixelType(name='RGBA8888', size=32, chanslist=[
('A', 24, 8)])
+PixelType(name='RGB888', size=24, chanslist=[
+ ('R', 0, 8),
+ ('G', 8, 8),
+ ('B', 16, 8)])
+
+
PixelType(name='RGB565', size=16, chanslist=[
('R', 0, 5),
('G', 5, 6),
('B', 11, 5)])
+#
+# Palette types
+#
+
+PixelType(name='P2', size=2, bit_endian='LE', chanslist=[
+ ('P', 0, 2)])
+
+
+PixelType(name='P4', size=4, bit_endian='LE', chanslist=[
+ ('P', 0, 4)])
-PixelType(name='V8', size=8, chanslist=[
- ('V', 0, 8)])
+
+PixelType(name='P8', size=8, bit_endian='LE', chanslist=[
+ ('P', 0, 8)])
+
+#
+# Gray-only pixel types
+#
+
+PixelType(name='V1', size=1, bit_endian='LE', chanslist=[
+ ('V', 0, 1)])
PixelType(name='V2', size=2, bit_endian='LE', chanslist=[
('V', 0, 2)])
+PixelType(name='V4', size=4, bit_endian='LE', chanslist=[
+ ('V', 0, 4)])
+
+
+PixelType(name='V8', size=8, bit_endian='LE', chanslist=[
+ ('V', 0, 8)])
+
+
+#
+# Experiments
+#
+
PixelType(name='VA12', size=4, bit_endian='BE', chanslist=[
('A', 1, 2),
('V', 3, 1)])
http://repo.or.cz/w/gfxprim.git/commit/cfd3858ce9e6a269b8903bd312e52259c48e…
commit cfd3858ce9e6a269b8903bd312e52259c48e318c
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Jun 11 22:11:23 2011 +0200
Drastic color/palette code pruning
Palettes to be reimplemented (did not work as such with gen. code anyway)
Color as (type, color) pair may be re-added much later
diff --git a/include/core/GP_Color.h b/include/core/GP_Color.h
index 8f11b03..3f13f95 100644
--- a/include/core/GP_Color.h
+++ b/include/core/GP_Color.h
@@ -26,101 +26,6 @@
#ifndef GP_COLOR_H
#define GP_COLOR_H
-#include <stdint.h>
-
-#include "GP_RetCode.h"
-
-#define GP_COLNAME_PACK(n) {.name = {GP_COLNAME, n}}
-#define GP_PALINDEX_PACK(palette, index) {.pal = {GP_PALETTE, index, palette}}
-#define GP_PAL4_PACK(index) {.pal4 = {GP_PAL4, index}}
-#define GP_PAL8_PACK(index) {.pal8 = {GP_PAL8, index}}
-#define GP_G1_PACK(g) {.g1 = {GP_G1, g}}
-#define GP_G2_PACK(g) {.g2 = {GP_G2, g}}
-#define GP_G4_PACK(g) {.g4 = {GP_G4, g}}
-#define GP_G8_PACK(g) {.g8 = {GP_G8, g}}
-#define GP_RGB555_PACK(r, g, b) {.rgb555 = {GP_RGB555, r, g, b}}
-#define GP_RGB565_PACK(r, g, b) {.rgb565 = {GP_RGB565, r, g, b}}
-#define GP_RGB666_PACK(r, g, b) {.rgb666 = {GP_RGB666, r, g, b}}
-#define GP_RGB888_PACK(r, g, b) {.rgb888 = {GP_RGB888, r, g, b}}
-#define GP_RGBA8888_PACK(r, g, b, a) {.rgba8888 = {GP_RGBA8888, r, g, b, a}}
-
-#define GP_COLNAME_FILL(col, n) do { - (col)->name.type = GP_COLNAME; - (col)->name.name = n; -} while (0)
-
-#define GP_PALINDEX_FILL(col, p, i) do { - (col)->pal.type = GP_PALETTE; - (col)->pal.index = i; - (col)->pal.palette = p; -} while (0)
-
-#define GP_PAL4_FILL(col, i) do { - (col)->pal4.type = GP_PAL4; - (col)->pal4.index = i; -} while (0)
-
-#define GP_PAL8_FILL(col, i) do { - (col)->pal8.type = GP_PAL8; - (col)->pal8.index = i; -} while (0)
-
-#define GP_G1_FILL(col, g) do { - (col)->g1.type = GP_G1; - (col)->g1.gray = g; -} while (0)
-
-#define GP_G2_FILL(col, g) do { - (col)->g2.type = GP_G2; - (col)->g2.gray = g; -} while (0)
-
-#define GP_G4_FILL(col, g) do { - (col)->g4.type = GP_G4; - (col)->g4.gray = g; -} while (0)
-
-#define GP_G8_FILL(col, g) do { - (col)->g8.type = GP_G8; - (col)->g8.gray = g; -} while (0)
-
-#define GP_RGB555_FILL(col, r, g, b) do {- (col)->rgb555.type = GP_RGB555; - (col)->rgb555.red = r; - (col)->rgb555.green = g; - (col)->rgb555.blue = b; -} while (0)
-
-#define GP_RGB565_FILL(col, r, g, b) do {- (col)->rgb565.type = GP_RGB565; - (col)->rgb565.red = r; - (col)->rgb565.green = g; - (col)->rgb565.blue = b; -} while (0)
-
-#define GP_RGB666_FILL(col, r, g, b) do {- (col)->rgb666.type = GP_RGB666; - (col)->rgb666.red = r; - (col)->rgb666.green = g; - (col)->rgb666.blue = b; -} while (0)
-
-#define GP_RGB888_FILL(col, r, g, b) do {- (col)->rgb888.type = GP_RGB888; - (col)->rgb888.red = r; - (col)->rgb888.green = g; - (col)->rgb888.blue = b; -} while (0)
-
-#define GP_RGBA8888_FILL(col, r, g, b, a) do {- (col)->rgba8888.type = GP_RGBA8888; - (col)->rgba8888.red = r; - (col)->rgba8888.green = g; - (col)->rgba8888.blue = b; - (col)->rgba8888.alpha = a; -} while (0)
-
typedef enum GP_ColorName {
GP_COL_BLACK,
GP_COL_RED,
@@ -136,131 +41,4 @@ typedef enum GP_ColorName {
GP_COL_MAX,
} GP_ColorName;
-typedef enum GP_ColorType {
- GP_NOCOLOR = 0,
- GP_COLNAME,
- GP_PALETTE,
- GP_PAL4,
- GP_PAL8,
- GP_G1,
- GP_G2,
- GP_G4,
- GP_G8,
- GP_RGB555,
- GP_RGB565,
- GP_RGB666,
- GP_RGB888,
- GP_RGBA8888,
- GP_COLMAX,
-} GP_ColorType;
-
-struct GP_ColName {
- enum GP_ColorType type;
- enum GP_ColorName name;
-};
-
-struct GP_ColPal {
- enum GP_ColorType type;
- uint16_t index;
- union GP_Palette *palette;
-};
-
-struct GP_ColPal4 {
- enum GP_ColorType type;
- uint8_t index:4;
-};
-
-struct GP_ColPal8 {
- enum GP_ColorType type;
- uint8_t index;
-};
-
-struct GP_ColRGB888 {
- enum GP_ColorType type;
- uint8_t red;
- uint8_t green;
- uint8_t blue;
-};
-
-struct GP_ColG1 {
- enum GP_ColorType type;
- uint8_t gray:1;
-};
-
-struct GP_ColG2 {
- enum GP_ColorType type;
- uint8_t gray:2;
-};
-
-struct GP_ColG4 {
- enum GP_ColorType type;
- uint8_t gray:4;
-};
-
-struct GP_ColG8 {
- enum GP_ColorType type;
- uint8_t gray;
-};
-
-struct GP_ColRGBA8888 {
- enum GP_ColorType type;
- uint8_t red;
- uint8_t green;
- uint8_t blue;
- uint8_t alpha;
-};
-
-struct GP_ColRGB555 {
- enum GP_ColorType type;
- uint16_t red:5;
- uint16_t green:5;
- uint16_t blue:5;
-};
-
-struct GP_ColRGB565 {
- enum GP_ColorType type;
- uint16_t red:5;
- uint16_t green:6;
- uint16_t blue:5;
-};
-
-struct GP_ColRGB666 {
- enum GP_ColorType type;
- uint32_t red:6;
- uint32_t green:6;
- uint32_t blue:6;
-};
-
-typedef union GP_Color {
- enum GP_ColorType type;
- struct GP_ColName name;
- struct GP_ColPal pal;
- struct GP_ColPal4 pal4;
- struct GP_ColPal8 pal8;
- struct GP_ColG1 g1;
- struct GP_ColG2 g2;
- struct GP_ColG4 g4;
- struct GP_ColG8 g8;
- struct GP_ColRGB888 rgb888;
- struct GP_ColRGB555 rgb555;
- struct GP_ColRGB565 rgb565;
- struct GP_ColRGB666 rgb666;
- struct GP_ColRGBA8888 rgba8888;
-} GP_Color;
-
-/*
- * Convers color pointed by *color to type.
- */
-enum GP_RetCode GP_ColorConvert(GP_Color *color, GP_ColorType type);
-
-/*
- * Returns color type name.
- */
-const char *GP_ColorTypeName(GP_ColorType type);
-
-/*
- * Print color into stdout in human-readable format.
- */
-void GP_ColorPrint(GP_Color *color);
-
#endif /* GP_COLOR_H */
diff --git a/include/core/GP_Palette.h b/include/core/GP_Palette.h
deleted file mode 100644
index 69f1854..0000000
--- a/include/core/GP_Palette.h
+++ /dev/null
@@ -1,75 +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_PALETTE_H
-#define GP_PALETTE_H
-
-#include <stdint.h>
-
-#include "GP_RetCode.h"
-#include "GP_Color.h"
-
-/*
- * Usage:
- *
- * struct GP_RGB888 pal_cols[] = {
- * {0xff, 0x00, 0xff},
- * ...
- * };
- *
- * GP_Palette my_palette = GP_PAL_RGB888_PACK(pal_cols);
- */
-#define GP_PAL_RGB888_PACK(cols) {.rgb888 = {GP_RGB888, - sizeof (cols) / sizeof (struct GP_RGB888),- cols}}
-
-struct GP_RGB888 {
- uint8_t red;
- uint8_t green;
- uint8_t blue;
-};
-
-struct GP_PalRGB888 {
- enum GP_ColorType type;
- uint16_t size;
- struct GP_RGB888 *colors;
-};
-
-typedef union GP_Palette {
- enum GP_ColorType type;
- struct GP_PalRGB888 rgb888;
-} GP_Palette;
-
-/*
- * Converts palette color to direct color.
- */
-enum GP_RetCode GP_PaletteColorToColor(GP_Color *color);
-
-/*
- * Print palette into stdout in human-readable format.
- */
-void GP_PalettePrint(GP_Palette *palette);
-
-#endif /* GP_PALETTE_H */
diff --git a/libs/core/GP_Color.c b/libs/core/GP_Color.c
index b2e7a0a..e6f2c53 100644
--- a/libs/core/GP_Color.c
+++ b/libs/core/GP_Color.c
@@ -23,10 +23,7 @@
* *
*****************************************************************************/
-#include <stdio.h>
-
-#include "GP_Palette.h"
-#include "GP_Color.h"
+#include <stdint.h>
static char *color_names[] = {
"black ",
@@ -56,799 +53,3 @@ static uint8_t rgb888_colors[][3] = {
{0xff, 0xff, 0xff}, /* white */
};
-static const char *color_type_names[] = {
- "Invalid color"
- "ColorName",
- "Index to In Memory Palette",
- "HW Palete 4bit",
- "HW Palete 8bit",
- "Grayscale 1bit",
- "Grayscale 2bit",
- "Grayscale 4bit",
- "Grayscale 8bit",
- "RGB 555",
- "RGB 565",
- "RGB 666",
- "RGB 888",
- "RGBA 8888",
-};
-
-static enum GP_RetCode conv_from_name(GP_Color *color, GP_ColorType type)
-{
- enum GP_ColorName i = color->name.name;
-
- if (i >= GP_COL_MAX)
- return GP_EINVAL;
-
- switch (type) {
- case GP_NOCOLOR:
- return GP_EINVAL;
- break;
- case GP_PAL4:
- case GP_PAL8:
- return GP_EINVAL;
- break;
- case GP_G1:
- break;
- case GP_G2:
- break;
- case GP_G4:
- GP_G4_FILL(color, ((rgb888_colors[i][0] +
- rgb888_colors[i][1] +
- rgb888_colors[i][2])/3)>>4);
- return GP_EUNPRECISE;
- break;
- case GP_G8:
- GP_G8_FILL(color, (rgb888_colors[i][0] +
- rgb888_colors[i][1] +
- rgb888_colors[i][2])/3);
- return GP_EUNPRECISE;
- break;
- case GP_RGB555:
- GP_RGB555_FILL(color, rgb888_colors[i][0]>>3,
- rgb888_colors[i][1]>>3,
- rgb888_colors[i][2]>>3);
- return GP_ESUCCESS;
- break;
- case GP_RGB565:
- GP_RGB565_FILL(color, rgb888_colors[i][0]>>3,
- rgb888_colors[i][1]>>2,
- rgb888_colors[i][2]>>3);
- return GP_ESUCCESS;
- break;
- case GP_RGB666:
- GP_RGB666_FILL(color, rgb888_colors[i][0]>>2,
- rgb888_colors[i][1]>>2,
- rgb888_colors[i][2]>>2);
- return GP_ESUCCESS;
- break;
- case GP_RGB888:
- GP_RGB888_FILL(color, rgb888_colors[i][0],
- rgb888_colors[i][1],
- rgb888_colors[i][2]);
- return GP_ESUCCESS;
- break;
- case GP_RGBA8888:
- GP_RGBA8888_FILL(color, rgb888_colors[i][0],
- rgb888_colors[i][1],
- rgb888_colors[i][2], 0xff);
- return GP_ESUCCESS;
- break;
- case GP_COLNAME:
- case GP_COLMAX:
- case GP_PALETTE:
- break;
- }
-
- if (type >= GP_COLMAX)
- return GP_EINVAL;
- else
- return GP_ENOIMPL;
-}
-
-const char *GP_ColorTypeName(GP_ColorType type)
-{
- if (type >= GP_COLMAX)
- return "UNKNOWN";
-
- return color_type_names[type];
-}
-
-static enum GP_RetCode conv_from_g1(GP_Color *color, GP_ColorType type)
-{
- struct GP_ColG1 *col = &color->g1;
-
- switch (type) {
- case GP_NOCOLOR:
- return GP_EINVAL;
- break;
- case GP_PAL4:
- case GP_PAL8:
- return GP_EINVAL;
- break;
- case GP_G1:
- return GP_ESUCCESS;
- break;
- case GP_G2:
- GP_G2_FILL(color, col->gray * 0x03);
- return GP_ESUCCESS;
- break;
- case GP_G4:
- GP_G4_FILL(color, col->gray * 0x0f);
- return GP_ESUCCESS;
- break;
- case GP_G8:
- GP_G8_FILL(color, col->gray * 0xff);
- return GP_ESUCCESS;
- break;
- case GP_RGB555:
- GP_RGB555_FILL(color, col->gray * 0x1f,
- col->gray * 0x1f,
- col->gray * 0x1f);
- return GP_ESUCCESS;
- break;
- case GP_RGB565:
- GP_RGB565_FILL(color, col->gray * 0x1f,
- col->gray * 0x3f,
- col->gray * 0x1f);
- return GP_ESUCCESS;
- break;
- case GP_RGB666:
- GP_RGB666_FILL(color, col->gray * 0x3f,
- col->gray * 0x3f,
- col->gray * 0x3f);
- return GP_ESUCCESS;
- break;
- case GP_RGB888:
- GP_RGB888_FILL(color, col->gray * 0xff,
- col->gray * 0xff,
- col->gray * 0xff);
- return GP_ESUCCESS;
- break;
- case GP_RGBA8888:
- GP_RGBA8888_FILL(color, col->gray * 0xff,
- col->gray * 0xff,
- col->gray * 0xff, 0xff);
- return GP_ESUCCESS;
- break;
- case GP_COLMAX:
- case GP_COLNAME:
- case GP_PALETTE:
- break;
- }
-
- if (type >= GP_COLMAX)
- return GP_EINVAL;
- else
- return GP_ENOIMPL;
-}
-
-static enum GP_RetCode conv_from_g2(GP_Color *color, GP_ColorType type)
-{
- struct GP_ColG2 *col = &color->g2;
-
- switch (type) {
- case GP_NOCOLOR:
- return GP_EINVAL;
- break;
- case GP_PAL4:
- case GP_PAL8:
- return GP_EINVAL;
- break;
- case GP_G1:
- GP_G1_FILL(color, col->gray>>2);
- return GP_EUNPRECISE;
- break;
- case GP_G2:
- return GP_ESUCCESS;
- break;
- case GP_G4:
- GP_G4_FILL(color, col->gray * 0x0f / 0x03);
- return GP_ESUCCESS;
- break;
- case GP_G8:
- GP_G8_FILL(color, col->gray * 0xff / 0x03);
- return GP_ESUCCESS;
- break;
- case GP_RGB555:
- GP_RGB555_FILL(color, col->gray * 0x1f / 0x03,
- col->gray * 0x1f / 0x03,
- col->gray * 0x1f / 0x03);
- return GP_ESUCCESS;
- break;
- case GP_RGB565:
- GP_RGB565_FILL(color, col->gray * 0x1f / 0x03,
- col->gray * 0x3f / 0x03,
- col->gray * 0x1f / 0x03);
- return GP_ESUCCESS;
- break;
- case GP_RGB666:
- GP_RGB666_FILL(color, col->gray * 0x3f / 0x03,
- col->gray * 0x3f / 0x03,
- col->gray * 0x3f / 0x03);
- return GP_ESUCCESS;
- break;
- case GP_RGB888:
- GP_RGB888_FILL(color, col->gray * 0xff / 0x03,
- col->gray * 0xff / 0x03,
- col->gray * 0xff / 0x03);
- return GP_ESUCCESS;
- break;
- case GP_RGBA8888:
- GP_RGBA8888_FILL(color, col->gray * 0xff / 0x03,
- col->gray * 0xff / 0x03,
- col->gray * 0xff / 0x03, 0xff);
- return GP_ESUCCESS;
- break;
- case GP_COLMAX:
- case GP_COLNAME:
- case GP_PALETTE:
- break;
- }
-
- if (type >= GP_COLMAX)
- return GP_EINVAL;
- else
- return GP_ENOIMPL;
-}
-
-static enum GP_RetCode conv_from_g4(GP_Color *color, GP_ColorType type)
-{
- struct GP_ColG4 *col = &color->g4;
-
- switch (type) {
- case GP_NOCOLOR:
- return GP_EINVAL;
- break;
- case GP_PAL4:
- case GP_PAL8:
- return GP_EINVAL;
- break;
- case GP_G1:
- GP_G1_FILL(color, col->gray>>3);
- return GP_EUNPRECISE;
- break;
- case GP_G2:
- GP_G2_FILL(color, col->gray>>2);
- return GP_EUNPRECISE;
- break;
- case GP_G4:
- return GP_ESUCCESS;
- break;
- case GP_G8:
- GP_G8_FILL(color, col->gray * 0xff / 0x0f);
- return GP_ESUCCESS;
- break;
- case GP_RGB555:
- GP_RGB555_FILL(color, col->gray * 0x1f / 0x0f,
- col->gray * 0x1f / 0x0f,
- col->gray * 0x1f / 0x0f);
- return GP_ESUCCESS;
- break;
- case GP_RGB565:
- GP_RGB565_FILL(color, col->gray * 0x1f / 0x0f,
- col->gray * 0x3f / 0x0f,
- col->gray * 0x1f / 0x0f);
- return GP_ESUCCESS;
- break;
- case GP_RGB666:
- GP_RGB666_FILL(color, col->gray * 0x3f / 0x0f,
- col->gray * 0x3f / 0x0f,
- col->gray * 0x3f / 0x0f);
- return GP_ESUCCESS;
- break;
- case GP_RGB888:
- GP_RGB888_FILL(color, col->gray * 0xff / 0x0f,
- col->gray * 0xff / 0x0f,
- col->gray * 0xff / 0x0f);
- return GP_ESUCCESS;
- break;
- case GP_RGBA8888:
- GP_RGBA8888_FILL(color, col->gray * 0xff / 0x0f,
- col->gray * 0xff / 0x0f,
- col->gray * 0xff / 0x0f, 0xff);
- return GP_ESUCCESS;
- break;
- case GP_COLMAX:
- case GP_COLNAME:
- case GP_PALETTE:
- break;
- }
-
- if (type >= GP_COLMAX)
- return GP_EINVAL;
- else
- return GP_ENOIMPL;
-}
-
-static enum GP_RetCode conv_from_g8(GP_Color *color, GP_ColorType type)
-{
- struct GP_ColG8 *col = &color->g8;
-
- switch (type) {
- case GP_NOCOLOR:
- return GP_EINVAL;
- break;
- case GP_PAL4:
- case GP_PAL8:
- return GP_EINVAL;
- break;
- case GP_G1:
- GP_G1_FILL(color, col->gray / 8);
- return GP_EUNPRECISE;
- break;
- case GP_G2:
- GP_G2_FILL(color, col->gray / 4);
- return GP_EUNPRECISE;
- break;
- case GP_G4:
- GP_G4_FILL(color, col->gray / 2);
- return GP_EUNPRECISE;
- break;
- case GP_G8:
- return GP_ESUCCESS;
- break;
- case GP_RGB555:
- GP_RGB555_FILL(color, col->gray * 0x1f / 0xff,
- col->gray * 0x1f / 0xff,
- col->gray * 0x1f / 0xff);
- return GP_ESUCCESS;
- break;
- case GP_RGB565:
- GP_RGB565_FILL(color, col->gray * 0x1f / 0xff,
- col->gray * 0x3f / 0xff,
- col->gray * 0x1f / 0xff);
- return GP_ESUCCESS;
- break;
- case GP_RGB666:
- GP_RGB666_FILL(color, col->gray * 0x3f / 0xff,
- col->gray * 0x3f / 0xff,
- col->gray * 0x3f / 0xff);
- return GP_ESUCCESS;
- break;
- case GP_RGB888:
- GP_RGB888_FILL(color, col->gray,
- col->gray,
- col->gray);
- return GP_ESUCCESS;
- break;
- case GP_RGBA8888:
- GP_RGBA8888_FILL(color, col->gray,
- col->gray,
- col->gray, 0xff);
- return GP_ESUCCESS;
- break;
- case GP_COLMAX:
- case GP_COLNAME:
- case GP_PALETTE:
- break;
- }
-
- if (type >= GP_COLMAX)
- return GP_EINVAL;
- else
- return GP_ENOIMPL;
-}
-
-static enum GP_RetCode conv_from_rgb555(GP_Color *color, GP_ColorType type)
-{
- struct GP_ColRGB555 *col = &color->rgb555;
- uint8_t val;
-
- switch (type) {
- case GP_NOCOLOR:
- return GP_EINVAL;
- break;
- case GP_PAL4:
- case GP_PAL8:
- return GP_EINVAL;
- break;
- case GP_G1:
- val = ((col->red + col->green + col->blue) / 3)>>4;
- GP_G1_FILL(color, val);
- return GP_EUNPRECISE;
- break;
- case GP_G2:
- val = ((col->red + col->green + col->blue) / 3)>>3;
- GP_G2_FILL(color, val);
- return GP_EUNPRECISE;
- break;
- case GP_G4:
- val = ((col->red + col->green + col->blue) / 3)>>2;
- GP_G4_FILL(color, val);
- return GP_EUNPRECISE;
- break;
- case GP_G8:
- val = (0xff * (col->red + col->green + col->blue)) /
- (3 * 0x1f);
- GP_G8_FILL(color, val);
- return GP_EUNPRECISE;
- break;
- case GP_RGB555:
- return GP_ESUCCESS;
- break;
- case GP_RGB565:
- GP_RGB565_FILL(color, col->red, col->green << 1,
- col->blue);
- return GP_ESUCCESS;
- break;
- case GP_RGB666:
- GP_RGB666_FILL(color, 0x3f * col->red / 0x1f,
- 0x3f * col->green / 0x1f,
- 0x3f * col->blue / 0x1f);
- return GP_ESUCCESS;
- break;
- case GP_RGB888:
- GP_RGB888_FILL(color, 0xff * col->red / 0x1f,
- 0xff * col->green / 0x1f,
- 0xff * col->blue / 0x1f);
- return GP_ESUCCESS;
- break;
- case GP_RGBA8888:
- GP_RGBA8888_FILL(color, 0xff * col->red / 0x1f,
- 0xff * col->green / 0x1f,
- 0xff * col->blue / 0x1f, 0xff);
- return GP_ESUCCESS;
- break;
- case GP_COLMAX:
- case GP_COLNAME:
- case GP_PALETTE:
- break;
- }
-
- if (type >= GP_COLMAX)
- return GP_EINVAL;
- else
- return GP_ENOIMPL;
-}
-
-static enum GP_RetCode conv_from_rgb888(GP_Color *color, GP_ColorType type)
-{
- struct GP_ColRGB888 *col = &color->rgb888;
- uint8_t val;
-
- switch (type) {
- case GP_NOCOLOR:
- return GP_EINVAL;
- break;
- case GP_PAL4:
- case GP_PAL8:
- return GP_EINVAL;
- break;
- case GP_G1:
- val = ((col->red + col->green + col->blue)/3)>>7;
- GP_G1_FILL(color, val);
- return GP_EUNPRECISE;
- break;
- case GP_G2:
- val = ((col->red + col->green + col->blue)/3)>>6;
- GP_G2_FILL(color, val);
- return GP_EUNPRECISE;
- break;
- case GP_G4:
- val = ((col->red + col->green + col->blue)/3)>>4;
- GP_G4_FILL(color, val);
- return GP_EUNPRECISE;
- break;
- case GP_G8:
- val = ((col->red + col->green + col->blue)/3);
- GP_G8_FILL(color, val);
- return GP_EUNPRECISE;
- break;
- case GP_RGB555:
- GP_RGB555_FILL(color, col->red>>3,
- col->green>>3,
- col->blue>>3);
- return GP_EUNPRECISE;
- break;
- case GP_RGB565:
- GP_RGB565_FILL(color, col->red>>3, col->green>>2,
- col->blue>>3);
- return GP_EUNPRECISE;
- break;
- case GP_RGB666:
- GP_RGB666_FILL(color, col->red>>2, col->green>>2,
- col->blue>>2);
- return GP_EUNPRECISE;
- break;
- case GP_RGB888:
- return GP_ESUCCESS;
- break;
- case GP_RGBA8888:
- GP_RGBA8888_FILL(color, col->red, col->green,
- col->blue, 0xff);
- return GP_ESUCCESS;
- break;
-
- case GP_COLMAX:
- case GP_COLNAME:
- case GP_PALETTE:
- break;
- }
-
- if (type >= GP_COLMAX)
- return GP_EINVAL;
- else
- return GP_ENOIMPL;
-}
-
-static enum GP_RetCode conv_from_rgba8888(GP_Color *color, GP_ColorType type)
-{
- struct GP_ColRGBA8888 *col = &color->rgba8888;
- uint8_t val;
-
- switch (type) {
- case GP_NOCOLOR:
- return GP_EINVAL;
- break;
- case GP_PAL4:
- case GP_PAL8:
- return GP_EINVAL;
- break;
- case GP_G1:
- val = ((col->red + col->green + col->blue)/3)>>7;
- GP_G1_FILL(color, val);
- return GP_EUNPRECISE;
- break;
- case GP_G2:
- val = ((col->red + col->green + col->blue)/3)>>6;
- GP_G2_FILL(color, val);
- return GP_EUNPRECISE;
- break;
- case GP_G4:
- val = ((col->red + col->green + col->blue)/3)>>4;
- GP_G4_FILL(color, val);
- return GP_EUNPRECISE;
- break;
- case GP_G8:
- val = ((col->red + col->green + col->blue)/3);
- GP_G8_FILL(color, val);
- return GP_EUNPRECISE;
- break;
- case GP_RGB555:
- GP_RGB555_FILL(color, col->red>>3,
- col->green>>3,
- col->blue>>3);
- return GP_EUNPRECISE;
- break;
- case GP_RGB888:
- GP_RGB888_FILL(color, col->red,
- col->green,
- col->blue);
- return GP_EUNPRECISE;
- break;
- case GP_RGBA8888:
- return GP_ESUCCESS;
- break;
- case GP_COLMAX:
- case GP_COLNAME:
- case GP_PALETTE:
- break;
- }
-
- if (type >= GP_COLMAX)
- return GP_EINVAL;
- else
- return GP_ENOIMPL;
-}
-
-static enum GP_RetCode color_convert(GP_Color *color, GP_ColorType type)
-{
- switch (color->type) {
- case GP_NOCOLOR:
- return GP_EINVAL;
- break;
- case GP_PAL4:
- case GP_PAL8:
- return GP_EINVAL;
- break;
- case GP_COLNAME:
- return conv_from_name(color, type);
- break;
- case GP_G1:
- return conv_from_g1(color, type);
- break;
- case GP_G2:
- return conv_from_g2(color, type);
- break;
- case GP_G4:
- return conv_from_g4(color, type);
- break;
- case GP_G8:
- return conv_from_g8(color, type);
- break;
- case GP_RGB888:
- return conv_from_rgb888(color, type);
- break;
- case GP_RGBA8888:
- return conv_from_rgba8888(color, type);
- break;
- case GP_RGB555:
- return conv_from_rgb555(color, type);
- break;
- case GP_COLMAX:
- case GP_PALETTE:
- break;
- }
-
- if (color->type >= GP_COLMAX)
- return GP_EINVAL;
- else
- return GP_ENOIMPL;
-}
-
-GP_RetCode GP_ColorConvert(GP_Color *color, GP_ColorType type)
-{
- if (!color)
- return GP_ENULLPTR;
-
- /* nothing to do */
- if (color->type == type)
- return GP_ESUCCESS;
-
- GP_RetCode ret;
-
- /* convert palette color to color */
- if (color->type == GP_PALETTE) {
- ret = GP_PaletteColorToColor(color);
-
- if (ret != GP_ESUCCESS)
- return ret;
- }
-
- /* convert color */
- return color_convert(color, type);
-}
-
-static void print_name(struct GP_ColName *color)
-{
- printf(" TYPE NAMEn");
-
- if (color->name > GP_COL_MAX) {
- printf("COLNAME invalidn");
- return;
- }
-
- printf("COLNAME %sn", color_names[color->name]);
-}
-
-static void print_palette(struct GP_ColPal *color)
-{
- printf("Palette index %04un", color->index);
- GP_PalettePrint(color->palette);
-}
-
-static void print_pal4(struct GP_ColPal4 *color)
-{
- printf("HW Palette index 0x%01u", color->index);
-}
-
-static void print_pal8(struct GP_ColPal8 *color)
-{
- printf("HW Palette index 0x%02u", color->index);
-}
-
-static void print_g1(struct GP_ColG1 *color)
-{
- printf(" TYPE Gn");
- printf(" G1 0x%xn", color->gray);
-}
-
-static void print_g2(struct GP_ColG2 *color)
-{
- printf(" TYPE Gn");
- printf(" G2 0x%xn", color->gray);
-}
-
-static void print_g4(struct GP_ColG4 *color)
-{
- printf(" TYPE Gn");
- printf(" G4 0x%02xn", color->gray);
-}
-
-static void print_g8(struct GP_ColG8 *color)
-{
- printf(" TYPE Gn");
- printf(" G8 0x%02xn", color->gray);
-}
-
-static void print_rgb555(struct GP_ColRGB555 *color)
-{
- printf(" TYPE R G Bn");
- printf("RGB555 0x%02x 0x%02x 0x%02xn", color->red,
- color->green,
- color->blue);
-}
-
-static void print_rgb565(struct GP_ColRGB565 *color)
-{
- printf(" TYPE R G Bn");
- printf("RGB565 0x%02x 0x%02x 0x%02xn", color->red,
- color->green,
- color->blue);
-}
-
-static void print_rgb666(struct GP_ColRGB666 *color)
-{
- printf(" TYPE R G Bn");
- printf("RGB666 0x%02x 0x%02x 0x%02xn", color->red,
- color->green,
- color->blue);
-}
-static void print_rgb888(struct GP_ColRGB888 *color)
-{
- printf(" TYPE R G Bn");
- printf("RGB888 0x%02x 0x%02x 0x%02xn", color->red,
- color->green,
- color->blue);
-}
-
-static void print_rgba8888(struct GP_ColRGBA8888 *color)
-{
- printf(" TYPE R G B An");
- printf("RGBA8888 0x%02x 0x%02x 0x%02x 0x%02xn", color->red,
- color->green,
- color->blue,
- color->alpha);
-}
-
-void GP_ColorPrint(GP_Color *color)
-{
- switch (color->type) {
- case GP_COLNAME:
- print_name(&color->name);
- return;
- break;
- case GP_PALETTE:
- print_palette(&color->pal);
- return;
- break;
- case GP_PAL4:
- print_pal4(&color->pal4);
- return;
- break;
- case GP_PAL8:
- print_pal8(&color->pal8);
- break;
- case GP_G1:
- print_g1(&color->g1);
- return;
- break;
- case GP_G2:
- print_g2(&color->g2);
- return;
- break;
- case GP_G4:
- print_g4(&color->g4);
- return;
- break;
- case GP_G8:
- print_g8(&color->g8);
- return;
- break;
- case GP_RGB555:
- print_rgb555(&color->rgb555);
- return;
- break;
- case GP_RGB565:
- print_rgb565(&color->rgb565);
- return;
- break;
- case GP_RGB666:
- print_rgb666(&color->rgb666);
- return;
- break;
- case GP_RGB888:
- print_rgb888(&color->rgb888);
- return;
- break;
- case GP_RGBA8888:
- print_rgba8888(&color->rgba8888);
- return;
- break;
- case GP_COLMAX:
- break;
- }
-
- printf("Invalid color type (%u)n", color->type);
-}
diff --git a/libs/core/GP_Palette.c b/libs/core/GP_Palette.c
deleted file mode 100644
index 01224f8..0000000
--- a/libs/core/GP_Palette.c
+++ /dev/null
@@ -1,83 +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 <stdio.h>
-
-#include "GP_Color.h"
-#include "GP_Palette.h"
-
-enum GP_RetCode GP_PaletteColorToColor(GP_Color *color)
-{
- struct GP_ColPal *pal;
- GP_Palette *palette;
- uint16_t index;
-
- if (color->type != GP_PALETTE)
- return GP_EINVAL;
-
- pal = &color->pal;
- palette = pal->palette;
- index = pal->index;
-
- switch (pal->palette->type) {
- case GP_RGB888:
- if (index >= palette->rgb888.size)
- return GP_EINVAL;
-
- GP_RGB888_FILL(color, palette->rgb888.colors[index].red,
- palette->rgb888.colors[index].green,
- palette->rgb888.colors[index].blue);
- return GP_ESUCCESS;
- break;
- default:
- return GP_ENOIMPL;
- }
-}
-
-static void print_rgb888(struct GP_PalRGB888 *palette)
-{
- uint16_t i;
-
- printf("palette format rgb888 (size = %u)n", palette->size);
- printf(" NR R G Bn");
-
- for (i = 0; i < palette->size; i++) {
- printf("%04u: 0x%.2x 0x%.2x 0x%.2xn", i,
- palette->colors[i].red,
- palette->colors[i].green,
- palette->colors[i].blue);
- }
-}
-
-void GP_PalettePrint(GP_Palette *palette)
-{
- switch (palette->type) {
- case GP_RGB888:
- print_rgb888(&palette->rgb888);
- break;
- default:
- break;
- }
-}
-----------------------------------------------------------------------
Summary of changes:
.../GP_Pixel_Access.c => include/core/GP_Blit.h | 39 +-
include/core/GP_Color.h | 222 ------
include/core/GP_Context.h | 1 +
include/core/GP_Convert.h | 111 +++
include/core/GP_Core.h | 2 +-
.../core/{GP_Pixel_Access.h => GP_GetPutPixel.h} | 8 +-
include/core/GP_Palette.h | 75 --
include/core/GP_Pixel.h | 39 +-
include/gfx/GP_Gfx.h | 2 +-
libs/core/GP_Blit.c | 13 +-
libs/core/GP_Color.c | 801 +-------------------
libs/core/{GP_Pixel_Access.c => GP_GetPutPixel.c} | 2 +-
libs/core/GP_Palette.c | 83 --
libs/core/GP_Pixel.c | 235 ------
libs/core/Makefile | 5 +-
pylib/gfxprim/generators/core/gen_blit.py | 28 +-
pylib/gfxprim/generators/core/gen_convert.py | 116 +++
.../{gen_pixel_access.py => gen_getputpixel.py} | 0
pylib/gfxprim/generators/core/gen_pixeltype.py | 67 +--
pylib/gfxprim/generators/core/make_GP_Blit.py | 2 +-
pylib/gfxprim/generators/core/make_GP_Convert.py | 59 ++
pylib/gfxprim/generators/core/make_GP_Pixel.py | 33 +-
pylib/gfxprim/generators/pixeltype.py | 10 +-
pylib/gfxprim/generators/utils.py | 1 +
pylib/pixeltypes.py | 43 +-
25 files changed, 400 insertions(+), 1597 deletions(-)
copy libs/core/GP_Pixel_Access.c => include/core/GP_Blit.h (66%)
create mode 100644 include/core/GP_Convert.h
rename include/core/{GP_Pixel_Access.h => GP_GetPutPixel.h} (95%)
delete mode 100644 include/core/GP_Palette.h
rename libs/core/{GP_Pixel_Access.c => GP_GetPutPixel.c} (98%)
delete mode 100644 libs/core/GP_Palette.c
delete mode 100644 libs/core/GP_Pixel.c
create mode 100644 pylib/gfxprim/generators/core/gen_convert.py
rename pylib/gfxprim/generators/core/{gen_pixel_access.py => gen_getputpixel.py} (100%)
create mode 100644 pylib/gfxprim/generators/core/make_GP_Convert.py
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.")
1
0
[repo.or.cz] gfxprim.git branch generate updated: fb094cd7f8086ddb9e59b91224c5fef9702136fa
by gavento 05 Jun '11
by gavento 05 Jun '11
05 Jun '11
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, generate has been updated
via fb094cd7f8086ddb9e59b91224c5fef9702136fa (commit)
from 1e00e08031c90d4f8d1b987d4908c9d2c938671a (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/fb094cd7f8086ddb9e59b91224c5fef97021…
commit fb094cd7f8086ddb9e59b91224c5fef9702136fa
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sun Jun 5 13:00:56 2011 +0200
Fix a typo
diff --git a/libs/core/GP_Blit.c b/libs/core/GP_Blit.c
index a316597..29e90e8 100644
--- a/libs/core/GP_Blit.c
+++ b/libs/core/GP_Blit.c
@@ -71,6 +71,6 @@ void GP_Blit_Naive(const GP_Context *c1, int x1, int y1, int w, int h,
for (int i = 0; i < w; i++)
for (int j = 0; j < h; j++) {
GP_Pixel p = GP_GetPixel(c1, x1 + i, y1 + j);
- GP_PutPixel(c2, x2 + i, y2 + j);
+ GP_PutPixel(c2, x2 + i, y2 + j, p);
}
}
-----------------------------------------------------------------------
Summary of changes:
libs/core/GP_Blit.c | 2 +-
1 files changed, 1 insertions(+), 1 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.")
1
0
Hi all,
With metan, we discussed Context, blits, drawing and clipping in core.
My proposal would be to remove clipping information from Context and
to think about some structure for "Drawing context". This structure
could also include other style information and would act as a wrapper
around context and used in convenience drawing functions.
The goal is to simplify the base api and modularize the library. I
believe that we should allow separate use of any part of the library
as much as possible - library supporting all kinds of weird devices
can see many uses both with variable subset of the modules.
Arguments to move clipping from Context to drawing are
* One use of clipping is convenience when drawing primitives. This
should be handled with drawing functions. There, clipping can save
some complicated reasoning.
* Blits should not respect clipping. Blitting a superset of
clip-region is very frequent and even if needed, calculating
intersection of two rectangles is very easy.
* One use-case of clipping is "user" routines drawing inside windows
etc. This can be done using subcontexts (context pointing to part of
memory of other context). This has also the advantage of coordinate
system being always (0,0) and solves the problem when (clipped) "user"
drawing routine would like to use clipping itself. Of course that
every context is still "naturally" clipped by (0,0,w,h).
>From my own experience, I used clipping very rarely, but I see its
value as a convenience mechanism. Having two variants of drawing
functions - one "bare" (unclipped, without implicit style information,
etc.) and an optional set of "convenience" functions (clipping, using
implicit style info on BGcolor, clipping, aliasing, font, ...) would
be the best of both.
It still remains a question how to implement such wrapper (structure
pointing to a context? context-independent structure? something
extensible or fixed? ...). I haven't given it much thought. Any ideas?
If there is an important use-case that I forgot to mention or if there
is any technical problem, bring it on.
Best,
Tomas
3
6