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: 71f1574977b03a901b7381fb3aca1c6d0c3ed33d
by metan 30 Oct '11
by metan 30 Oct '11
30 Oct '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 71f1574977b03a901b7381fb3aca1c6d0c3ed33d (commit)
from b964f56ae4fe0a0a48f16fc18a8daec953acb3cc (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/71f1574977b03a901b7381fb3aca1c6d0c3e…
commit 71f1574977b03a901b7381fb3aca1c6d0c3ed33d
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Oct 30 17:48:04 2011 +0100
Proved myself wrong, we need to read last two bytes.
Still haven't tried the code, just proved, while
riding the train, that sometimes we need to get
last two bytes.
diff --git a/include/core/GP_GetSetBits.h b/include/core/GP_GetSetBits.h
index bd55fe2..d724828 100644
--- a/include/core/GP_GetSetBits.h
+++ b/include/core/GP_GetSetBits.h
@@ -27,8 +27,8 @@
*/
-#ifndef GP_GET_SET_BITS_H
-#define GP_GET_SET_BITS_H
+#ifndef CORE_GP_GET_SET_BITS_H
+#define CORE_GP_GET_SET_BITS_H
/*
* Helper macros to read/write parts of words
@@ -122,6 +122,7 @@
#define GP_SET_BITS3_ALIGNED(offset, len, dest, val) do { uint32_t v; v = ((uint8_t *)dest)[0]; + v |= ((uint8_t *)dest)[1]<<8; v |= ((uint8_t *)dest)[2]<<16; GP_SET_BITS(offset, len, v, val); @@ -134,6 +135,7 @@
#define GP_SET_BITS4_ALIGNED(offset, len, dest, val) do { uint32_t v; v = ((uint8_t *)dest)[0]; + v |= ((uint8_t *)dest)[2]<<16; v |= ((uint8_t *)dest)[3]<<24; GP_SET_BITS(offset, len, v, val); @@ -145,4 +147,4 @@
} while (0)
-#endif /* GP_GET_SET_BITS_H */
+#endif /* CORE_GP_GET_SET_BITS_H */
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_GetSetBits.h | 8 +++++---
1 files changed, 5 insertions(+), 3 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: b964f56ae4fe0a0a48f16fc18a8daec953acb3cc
by metan 30 Oct '11
by metan 30 Oct '11
30 Oct '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 b964f56ae4fe0a0a48f16fc18a8daec953acb3cc (commit)
from 3037f6a8d06bf7262dbaf15395affd4e241fad1d (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/b964f56ae4fe0a0a48f16fc18a8daec953ac…
commit b964f56ae4fe0a0a48f16fc18a8daec953acb3cc
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sun Oct 30 17:41:16 2011 +0100
Changed the filter API (hopefully this is final version).
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index f372bf5..beb69e2 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -217,13 +217,13 @@ static GP_RetCode rotate(GP_Context **c, const char *params)
switch (rot) {
case 0:
- res = GP_FilterRotate90(*c, progress_callback);
+ res = GP_FilterRotate90(*c, NULL, progress_callback);
break;
case 1:
- res = GP_FilterRotate180(*c, progress_callback);
+ res = GP_FilterRotate180(*c, NULL, progress_callback);
break;
case 2:
- res = GP_FilterRotate270(*c, progress_callback);
+ res = GP_FilterRotate270(*c, NULL, progress_callback);
break;
}
diff --git a/include/filters/GP_Rotate.h b/include/filters/GP_Rotate.h
index daa8287..245e3c2 100644
--- a/include/filters/GP_Rotate.h
+++ b/include/filters/GP_Rotate.h
@@ -40,7 +40,14 @@
void GP_FilterMirrorH_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback);
-GP_Context *GP_FilterMirrorH(const GP_Context *src,
+/*
+ * Mirrors bitmap horizontally.
+ *
+ * If dst is NULL, new bitmap is allocated.
+ *
+ * Returns pointer to destination bitmap or NULL if allocation failed.
+ */
+GP_Context *GP_FilterMirrorH(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback);
/*
@@ -51,14 +58,21 @@ GP_Context *GP_FilterMirrorH(const GP_Context *src,
void GP_FilterMirrorV_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback);
-GP_Context *GP_FilterMirrorV(const GP_Context *src,
+/*
+ * Mirrors bitmap vertically.
+ *
+ * If dst is NULL, new bitmap is allocated.
+ *
+ * Returns pointer to destination bitmap or NULL if allocation failed.
+ */
+GP_Context *GP_FilterMirrorV(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback);
/*
* Rotate context by 90, 180 and 270.
*
* Doesn't work 'in place'. The contexts must have equal pixel_type size must
- * match the rotated size size (is equal for 180 and swapped for 90 and 270).
+ * match the rotated size (is equal for 180 and swapped for 90 and 270).
*/
void GP_FilterRotate90_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback);
@@ -69,7 +83,30 @@ void GP_FilterRotate180_Raw(const GP_Context *src, GP_Context *dst,
void GP_FilterRotate270_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallback *callback);
-typedef enum GP_FilterRotation {
+/*
+ * Rotate the context by 90, 180, 270.
+ *
+ * If dst is NULL, new bitmap is allocated.
+ *
+ * Returns pointer to destination bitmap or NULL if allocation failed.
+ */
+GP_Context *GP_FilterRotate90(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+
+GP_Context *GP_FilterRotate180(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+
+GP_Context *GP_FilterRotate270(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+
+/*
+ * Calls a symmetry filter on bitmap.
+ *
+ * If dst is NULL, new bitmap is allocated.
+ *
+ * Returns pointer to destination bitmap or NULL if allocation failed.
+ */
+typedef enum GP_FilterSymmetries {
GP_ROTATE_90,
GP_ROTATE_CW = GP_ROTATE_90,
GP_ROTATE_180,
@@ -77,32 +114,10 @@ typedef enum GP_FilterRotation {
GP_ROTATE_CCW = GP_ROTATE_270,
GP_MIRROR_H,
GP_MIRROR_V,
-} GP_FilterRotation;
-
-void GP_FilterRotate_Raw(const GP_Context *src, GP_Context *dst,
- GP_FilterRotation rotation,
- GP_ProgressCallback *callback);
-
-GP_Context *GP_FilterRotate(const GP_Context *context,
- GP_FilterRotation rotation,
- GP_ProgressCallback *callback);
+} GP_FilterSymmetries;
-static inline GP_Context *GP_FilterRotate90(const GP_Context *src,
- GP_ProgressCallback *callback)
-{
- return GP_FilterRotate(src, GP_ROTATE_90, callback);
-}
-
-static inline GP_Context *GP_FilterRotate180(const GP_Context *src,
- GP_ProgressCallback *callback)
-{
- return GP_FilterRotate(src, GP_ROTATE_180, callback);
-}
-
-static inline GP_Context *GP_FilterRotate270(const GP_Context *src,
- GP_ProgressCallback *callback)
-{
- return GP_FilterRotate(src, GP_ROTATE_270, callback);
-}
+GP_Context *GP_FilterSymmetry(const GP_Context *src, GP_Context *dst,
+ GP_FilterSymmetries symmetry,
+ GP_ProgressCallback *callback);
#endif /* FILTERS_GP_ROTATE_H */
diff --git a/libs/filters/GP_Rotate.c b/libs/filters/GP_Rotate.c
index ea7ae0a..73987e7 100644
--- a/libs/filters/GP_Rotate.c
+++ b/libs/filters/GP_Rotate.c
@@ -53,8 +53,49 @@ void GP_FilterMirrorH_Raw(const GP_Context *src, GP_Context *dst,
GP_ProgressCallbackDone(callback);
}
+GP_Context *GP_FilterMirrorH(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ if (dst == NULL) {
+ dst = GP_ContextCopy(src, 0);
+
+ if (dst == NULL)
+ return NULL;
+ } else {
+ GP_ASSERT(src->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+ GP_ASSERT(src->w <= dst->w && src->h <= dst->h,
+ "Destination is not big enough");
+ }
+
+ GP_FilterMirrorH_Raw(src, dst, callback);
+
+ return dst;
+}
+
+
+GP_Context *GP_FilterMirrorV(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ if (dst == NULL) {
+ dst = GP_ContextCopy(src, 0);
+
+ if (dst == NULL)
+ return NULL;
+ } else {
+ GP_ASSERT(src->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+ GP_ASSERT(src->w <= dst->w && src->h <= dst->h,
+ "Destination is not big enough");
+ }
+
+ GP_FilterMirrorV_Raw(src, dst, callback);
+
+ return dst;
+}
+
void GP_FilterRotate180_Raw(const GP_Context *src, GP_Context *dst,
- GP_ProgressCallback *callback)
+ GP_ProgressCallback *callback)
{
#warning FIXME: Callbacks, faster algorighm?
@@ -62,53 +103,82 @@ void GP_FilterRotate180_Raw(const GP_Context *src, GP_Context *dst,
GP_FilterMirrorH_Raw(dst, dst, callback);
}
-void GP_FilterRotate_Raw(const GP_Context *src, GP_Context *dst,
- GP_FilterRotation rotation,
- GP_ProgressCallback *callback)
+GP_Context *GP_FilterRotate90(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
- switch (rotation) {
- case GP_ROTATE_90:
- GP_FilterRotate90_Raw(src, dst, callback);
- break;
- case GP_ROTATE_180:
- GP_FilterRotate180_Raw(src, dst, callback);
- break;
- case GP_ROTATE_270:
- GP_FilterRotate270_Raw(src, dst, callback);
- break;
- case GP_MIRROR_H:
- GP_FilterMirrorH_Raw(src, dst, callback);
- break;
- case GP_MIRROR_V:
- GP_FilterMirrorV_Raw(src, dst, callback);
- break;
+ if (dst == NULL) {
+ dst = GP_ContextAlloc(src->h, src->w, src->pixel_type);
+
+ if (dst == NULL)
+ return NULL;
+ } else {
+ GP_ASSERT(src->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+ GP_ASSERT(src->w <= dst->h && src->h <= dst->w,
+ "Destination is not big enough");
}
+
+ GP_FilterRotate90_Raw(src, dst, callback);
+
+ return dst;
}
-GP_Context *GP_FilterRotate(const GP_Context *context,
- GP_FilterRotation rotation,
- GP_ProgressCallback *callback)
+GP_Context *GP_FilterRotate180(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
- GP_Size w = context->w;
- GP_Size h = context->h;
-
- switch (rotation) {
- case GP_ROTATE_90:
- case GP_ROTATE_270:
- GP_SWAP(w, h);
- break;
- default:
- break;
+ if (dst == NULL) {
+ dst = GP_ContextCopy(src, 0);
+
+ if (dst == NULL)
+ return NULL;
+ } else {
+ GP_ASSERT(src->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+ GP_ASSERT(src->w <= dst->w && src->h <= dst->h,
+ "Destination is not big enough");
}
- GP_Context *ret = GP_ContextAlloc(w, h, context->pixel_type);
+ GP_FilterRotate180_Raw(src, dst, callback);
+
+ return dst;
+}
- if (unlikely(ret == NULL)) {
- GP_DEBUG(1, "Malloc failed :(");
- return NULL;
+GP_Context *GP_FilterRotate270(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ if (dst == NULL) {
+ dst = GP_ContextAlloc(src->h, src->w, src->pixel_type);
+
+ if (dst == NULL)
+ return NULL;
+ } else {
+ GP_ASSERT(src->pixel_type == dst->pixel_type,
+ "The src and dst pixel types must match");
+ GP_ASSERT(src->w <= dst->h && src->h <= dst->w,
+ "Destination is not big enough");
}
- GP_FilterRotate_Raw(context, ret, rotation, callback);
+ GP_FilterRotate270_Raw(src, dst, callback);
+
+ return dst;
+}
+
+GP_Context *GP_FilterSymmetry(const GP_Context *src, GP_Context *dst,
+ GP_FilterSymmetries symmetry,
+ GP_ProgressCallback *callback)
+{
+ switch (symmetry) {
+ case GP_ROTATE_90:
+ return GP_FilterRotate90(src, dst, callback);
+ case GP_ROTATE_180:
+ return GP_FilterRotate180(src, dst, callback);
+ case GP_ROTATE_270:
+ return GP_FilterRotate270(src, dst, callback);
+ case GP_MIRROR_H:
+ return GP_FilterMirrorH(src, dst, callback);
+ case GP_MIRROR_V:
+ return GP_FilterMirrorV(src, dst, callback);
+ }
- return ret;
+ return NULL;
}
-----------------------------------------------------------------------
Summary of changes:
demos/grinder/grinder.c | 6 +-
include/filters/GP_Rotate.h | 75 +++++++++++++---------
libs/filters/GP_Rotate.c | 148 +++++++++++++++++++++++++++++++-----------
3 files changed, 157 insertions(+), 72 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: 3037f6a8d06bf7262dbaf15395affd4e241fad1d
by metan 27 Oct '11
by metan 27 Oct '11
27 Oct '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 3037f6a8d06bf7262dbaf15395affd4e241fad1d (commit)
via a8f1ba07c9863cdda6b55a7b82fb35fbe55758a9 (commit)
via bcaa19c8129a6bcaac8a3640979e91135c016846 (commit)
via 828d02ecb1948597d7f7b83e86f15e7bb7ca9164 (commit)
from 7d1c1b2c4aeef95941109cbdc5707eff6ad0a36f (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/3037f6a8d06bf7262dbaf15395affd4e241f…
commit 3037f6a8d06bf7262dbaf15395affd4e241fad1d
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Oct 27 23:07:13 2011 +0200
Rewrote rotate and mirror filters.
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index 26d6d0d..f372bf5 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -213,18 +213,49 @@ static GP_RetCode rotate(GP_Context **c, const char *params)
return GP_EINVAL;
}
+ GP_Context *res = NULL;
+
switch (rot) {
case 0:
- GP_RotateCW(*c);
+ res = GP_FilterRotate90(*c, progress_callback);
break;
case 1:
- GP_MirrorV(*c);
- GP_MirrorH(*c);
+ res = GP_FilterRotate180(*c, progress_callback);
break;
case 2:
- GP_RotateCCW(*c);
+ res = GP_FilterRotate270(*c, progress_callback);
break;
}
+
+ if (res == NULL)
+ return GP_ENOMEM;
+
+ GP_ContextFree(*c);
+ *c = res;
+
+ return GP_ESUCCESS;
+}
+
+/* mirror filter */
+
+static struct param mirror_params[] = {
+ {"vert", PARAM_BOOL, "mirror vertically", NULL, NULL},
+ {"horiz", PARAM_BOOL, "mirror horizontally", NULL, NULL},
+ {NULL, 0, NULL, NULL, NULL}
+};
+
+static GP_RetCode mirror(GP_Context **c, const char *params)
+{
+ int vert = 0, horiz = 0;
+
+ if (param_parse(params, mirror_params, "mirror", param_err, &vert, &horiz))
+ return GP_EINVAL;
+
+ if (vert)
+ GP_FilterMirrorV_Raw(*c, *c, progress_callback);
+
+ if (horiz)
+ GP_FilterMirrorH_Raw(*c, *c, progress_callback);
return GP_ESUCCESS;
}
@@ -334,9 +365,10 @@ struct filter {
};
static struct filter filter_table[] = {
- {"resize", "resize image by given ratio", resize_params, resize},
- {"scale", "scale image to given width and height", scale_params, scale},
{"rotate", "rotate image", rotate_params, rotate},
+ {"mirror", "mirror vertically/horizontally", mirror_params, mirror},
+ {"scale", "scale image to given width and height", scale_params, scale},
+ {"resize", "resize image by given ratio", resize_params, resize},
{"bright", "alter image brightness", bright_params, bright},
{"contrast", "alter image contrast", contrast_params, contrast},
{"invert", "inverts image", invert_params, invert},
diff --git a/demos/grinder/params.c b/demos/grinder/params.c
index d2dbfb9..17aebb9 100644
--- a/demos/grinder/params.c
+++ b/demos/grinder/params.c
@@ -183,6 +183,39 @@ int set_int(int *res, char *val)
return 0;
}
+static char *bool_false[] = {
+ "No",
+ "False",
+ "Off",
+ NULL
+};
+
+static char *bool_true[] = {
+ "Yes",
+ "True",
+ "On",
+ NULL
+};
+
+int set_bool(int *res, char *val)
+{
+ unsigned int i;
+
+ for (i = 0; bool_false[i] != NULL; i++)
+ if (!strcasecmp(val, bool_false[i])) {
+ *res = 0;
+ return 0;
+ }
+
+ for (i = 0; bool_true[i] != NULL; i++)
+ if (!strcasecmp(val, bool_true[i])) {
+ *res = 1;
+ return 0;
+ }
+
+ return 1;
+}
+
int set_float(float *res, char *val)
{
char *end;
@@ -269,7 +302,11 @@ int param_parse(const char *params, const struct param *param_desc, void *priv,
switch (param_desc[i].type) {
case PARAM_BOOL:
-
+ if ((ret = set_bool(arg, values[pos]))) {
+ CALL_ERR_CALLBACK(err, ¶m_desc[i],
+ values[pos], priv);
+ goto err;
+ }
break;
case PARAM_INT:
if ((ret = set_int(arg, values[pos]))) {
diff --git a/include/filters/GP_Rotate.h b/include/filters/GP_Rotate.h
index e73b0fe..daa8287 100644
--- a/include/filters/GP_Rotate.h
+++ b/include/filters/GP_Rotate.h
@@ -16,42 +16,93 @@
* 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> *
* *
*****************************************************************************/
/*
- GP_Context in place rotations.
+ GP_Context rotations and mirroring.
*/
-#ifndef GP_ROTATE_H
-#define GP_ROTATE_H
+#ifndef FILTERS_GP_ROTATE_H
+#define FILTERS_GP_ROTATE_H
#include "core/GP_Context.h"
+#include "GP_Filter.h"
/*
* Mirror horizontally.
+ *
+ * Works 'in place'. The contexts must have equal pixel_type and size.
*/
-GP_RetCode GP_MirrorH(GP_Context *context);
+void GP_FilterMirrorH_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+
+GP_Context *GP_FilterMirrorH(const GP_Context *src,
+ GP_ProgressCallback *callback);
/*
* Mirror vertically
+ *
+ * Works 'in place'. The contexts must have equal pixel_type and size.
*/
-GP_RetCode GP_MirrorV(GP_Context *context);
+void GP_FilterMirrorV_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
-/*
- * Rotate clockwise.
- */
-GP_RetCode GP_RotateCW(GP_Context *context);
+GP_Context *GP_FilterMirrorV(const GP_Context *src,
+ GP_ProgressCallback *callback);
/*
- * Rotate counter clockwise.
+ * Rotate context by 90, 180 and 270.
+ *
+ * Doesn't work 'in place'. The contexts must have equal pixel_type size must
+ * match the rotated size size (is equal for 180 and swapped for 90 and 270).
*/
-GP_RetCode GP_RotateCCW(GP_Context *context);
+void GP_FilterRotate90_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+
+void GP_FilterRotate180_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+
+void GP_FilterRotate270_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback);
+
+typedef enum GP_FilterRotation {
+ GP_ROTATE_90,
+ GP_ROTATE_CW = GP_ROTATE_90,
+ GP_ROTATE_180,
+ GP_ROTATE_270,
+ GP_ROTATE_CCW = GP_ROTATE_270,
+ GP_MIRROR_H,
+ GP_MIRROR_V,
+} GP_FilterRotation;
+
+void GP_FilterRotate_Raw(const GP_Context *src, GP_Context *dst,
+ GP_FilterRotation rotation,
+ GP_ProgressCallback *callback);
+
+GP_Context *GP_FilterRotate(const GP_Context *context,
+ GP_FilterRotation rotation,
+ GP_ProgressCallback *callback);
+
+static inline GP_Context *GP_FilterRotate90(const GP_Context *src,
+ GP_ProgressCallback *callback)
+{
+ return GP_FilterRotate(src, GP_ROTATE_90, callback);
+}
+
+static inline GP_Context *GP_FilterRotate180(const GP_Context *src,
+ GP_ProgressCallback *callback)
+{
+ return GP_FilterRotate(src, GP_ROTATE_180, callback);
+}
+
+static inline GP_Context *GP_FilterRotate270(const GP_Context *src,
+ GP_ProgressCallback *callback)
+{
+ return GP_FilterRotate(src, GP_ROTATE_270, callback);
+}
-#endif /* GP_ROTATE_H */
+#endif /* FILTERS_GP_ROTATE_H */
diff --git a/libs/filters/GP_MirrorV.gen.c.t b/libs/filters/GP_MirrorV.gen.c.t
new file mode 100644
index 0000000..c696349
--- /dev/null
+++ b/libs/filters/GP_MirrorV.gen.c.t
@@ -0,0 +1,44 @@
+%% extends "base.c.t"
+
+%% block descr
+Vertical Mirror alogorithm
+%% endblock
+
+%% block body
+
+#include "core/GP_GetPutPixel.h"
+#include "core/GP_Debug.h"
+#include "GP_Rotate.h"
+
+%% for ps in pixelsizes
+void GP_MirrorV_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ uint32_t x, y;
+ GP_Pixel tmp;
+
+ GP_DEBUG(1, "Mirroring image vertically %ux%u", src->w, src->h);
+
+ for (x = 0; x < src->w/2; x++) {
+ uint32_t xm = src->w - x - 1;
+ for (y = 0; y < src->h; y++) {
+ tmp = GP_GetPixel_Raw_{{ ps.suffix }}(src, x, y);
+ GP_PutPixel_Raw_{{ ps.suffix }}(dst, x, y, GP_GetPixel_Raw_{{ ps.suffix }}(src, xm, y));
+ GP_PutPixel_Raw_{{ ps.suffix }}(dst, xm, y, tmp);
+ }
+
+ if (callback != NULL && x % 100 == 0)
+ GP_ProgressCallbackReport(callback, 200.00 * x / src->w);
+ }
+
+ GP_ProgressCallbackDone(callback);
+}
+
+%% endfor
+
+void GP_FilterMirrorV_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ GP_FN_PER_BPP_CONTEXT(GP_MirrorV_Raw, src, src, dst, callback);
+}
+%% endblock body
diff --git a/libs/filters/GP_Rotate.c b/libs/filters/GP_Rotate.c
index 513b969..ea7ae0a 100644
--- a/libs/filters/GP_Rotate.c
+++ b/libs/filters/GP_Rotate.c
@@ -16,10 +16,7 @@
* 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> *
* *
*****************************************************************************/
@@ -30,66 +27,88 @@
#include <string.h>
-#include "algo/GP_MirrorV.algo.h"
-
-GP_RetCode GP_MirrorH(GP_Context *context)
+void GP_FilterMirrorH_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
- uint32_t bpr = context->bytes_per_row;
+ uint32_t bpr = src->bytes_per_row;
uint8_t buf[bpr];
uint32_t y;
- if (context == NULL)
- return GP_ENULLPTR;
+ GP_DEBUG(1, "Mirroring image horizontally %ux%u", src->w, src->h);
- for (y = 0; y < context->h/2; y++) {
- uint8_t *l1 = context->pixels + bpr * y;
- uint8_t *l2 = context->pixels + bpr * (context->h - y - 1);
+ #warning FIXME: non byte aligned pixels
+
+ for (y = 0; y < src->h/2; y++) {
+ uint8_t *l1 = dst->pixels + bpr * y;
+ uint8_t *l2 = dst->pixels + bpr * (src->h - y - 1);
memcpy(buf, l1, bpr);
memcpy(l1, l2, bpr);
memcpy(l2, buf, bpr);
+
+ if (callback != NULL && y % 100 == 0)
+ GP_ProgressCallbackReport(callback, 200.00 * y / src->h);
}
- return GP_ESUCCESS;
+ GP_ProgressCallbackDone(callback);
}
-/* Generate mirror functions per BPP */
-GP_DEF_FFN_PER_BPP(GP_MirrorV, DEF_MIRRORV_FN)
-
-GP_RetCode GP_MirrorV(GP_Context *context)
+void GP_FilterRotate180_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
{
- if (context == NULL)
- return GP_ENULLPTR;
+ #warning FIXME: Callbacks, faster algorighm?
- GP_FN_PER_BPP_CONTEXT(GP_MirrorV, context, context);
-
- return GP_ESUCCESS;
+ GP_FilterMirrorV_Raw(src, dst, NULL);
+ GP_FilterMirrorH_Raw(dst, dst, callback);
}
-#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)
+void GP_FilterRotate_Raw(const GP_Context *src, GP_Context *dst,
+ GP_FilterRotation rotation,
+ GP_ProgressCallback *callback)
{
- if (context == NULL)
- return GP_ENULLPTR;
-
- GP_FN_RET_PER_BPP_CONTEXT(GP_RotateCW, context, context);
-
- return GP_ENOIMPL;
+ switch (rotation) {
+ case GP_ROTATE_90:
+ GP_FilterRotate90_Raw(src, dst, callback);
+ break;
+ case GP_ROTATE_180:
+ GP_FilterRotate180_Raw(src, dst, callback);
+ break;
+ case GP_ROTATE_270:
+ GP_FilterRotate270_Raw(src, dst, callback);
+ break;
+ case GP_MIRROR_H:
+ GP_FilterMirrorH_Raw(src, dst, callback);
+ break;
+ case GP_MIRROR_V:
+ GP_FilterMirrorV_Raw(src, dst, callback);
+ break;
+ }
}
-/* Generate Rotate functions per BPP */
-GP_DEF_FFN_PER_BPP(GP_RotateCCW, DEF_ROTATECCW_FN)
-
-GP_RetCode GP_RotateCCW(GP_Context *context)
+GP_Context *GP_FilterRotate(const GP_Context *context,
+ GP_FilterRotation rotation,
+ GP_ProgressCallback *callback)
{
- if (context == NULL)
- return GP_ENULLPTR;
+ GP_Size w = context->w;
+ GP_Size h = context->h;
+
+ switch (rotation) {
+ case GP_ROTATE_90:
+ case GP_ROTATE_270:
+ GP_SWAP(w, h);
+ break;
+ default:
+ break;
+ }
+
+ GP_Context *ret = GP_ContextAlloc(w, h, context->pixel_type);
+
+ if (unlikely(ret == NULL)) {
+ GP_DEBUG(1, "Malloc failed :(");
+ return NULL;
+ }
- GP_FN_RET_PER_BPP_CONTEXT(GP_RotateCCW, context, context);
+ GP_FilterRotate_Raw(context, ret, rotation, callback);
- return GP_ENOIMPL;
+ return ret;
}
diff --git a/libs/filters/GP_Rotate.gen.c.t b/libs/filters/GP_Rotate.gen.c.t
new file mode 100644
index 0000000..9ef7bd9
--- /dev/null
+++ b/libs/filters/GP_Rotate.gen.c.t
@@ -0,0 +1,71 @@
+%% extends "base.c.t"
+
+%% block descr
+Vertical Mirror alogorithm
+%% endblock
+
+%% block body
+
+#include "core/GP_Debug.h"
+#include "core/GP_GetPutPixel.h"
+#include "GP_Rotate.h"
+
+%% for ps in pixelsizes
+void GP_FilterRotate90_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ uint32_t x, y;
+
+ GP_DEBUG(1, "Rotating image by 90 %ux%u", src->w, src->h);
+
+ for (x = 0; x < src->w; x++) {
+ for (y = 0; y < src->h; y++) {
+ uint32_t yr = src->h - y - 1;
+ GP_PutPixel_Raw_{{ ps.suffix }}(dst, yr, x, GP_GetPixel_Raw_{{ ps.suffix }}(src, x, y));
+ }
+
+ if (callback != NULL && x % 100 == 0)
+ GP_ProgressCallbackReport(callback, 100.00 * x / src->w);
+ }
+
+ GP_ProgressCallbackDone(callback);
+}
+
+%% endfor
+
+void GP_FilterRotate90_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ GP_FN_PER_BPP_CONTEXT(GP_FilterRotate90_Raw, src, src, dst, callback);
+}
+
+%% for ps in pixelsizes
+void GP_FilterRotate270_Raw_{{ ps.suffix }}(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ uint32_t x, y;
+
+ GP_DEBUG(1, "Rotating image by 270 %ux%u", src->w, src->h);
+
+ for (x = 0; x < src->w; x++) {
+ for (y = 0; y < src->h; y++) {
+ uint32_t xr = src->w - x - 1;
+ GP_PutPixel_Raw_{{ ps.suffix }}(dst, y, xr, GP_GetPixel_Raw_{{ ps.suffix }}(src, x, y));
+ }
+
+ if (callback != NULL && x % 100 == 0)
+ GP_ProgressCallbackReport(callback, 100.00 * x / src->w);
+ }
+
+ GP_ProgressCallbackDone(callback);
+}
+
+%% endfor
+
+void GP_FilterRotate270_Raw(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ GP_FN_PER_BPP_CONTEXT(GP_FilterRotate270_Raw, src, src, dst, callback);
+}
+
+%% endblock body
diff --git a/libs/filters/Makefile b/libs/filters/Makefile
index bd5ed37..8133fb0 100644
--- a/libs/filters/Makefile
+++ b/libs/filters/Makefile
@@ -1,5 +1,6 @@
TOPDIR=../..
-GENSOURCES=GP_Brightness.gen.c GP_Contrast.gen.c GP_Invert.gen.c
+GENSOURCES=GP_Brightness.gen.c GP_Contrast.gen.c GP_Invert.gen.c+ GP_MirrorV.gen.c GP_Rotate.gen.c
GENHEADERS=
CSOURCES=$(filter-out $(wildcard *.gen.c),$(wildcard *.c))
LIBNAME=filters
diff --git a/libs/filters/algo/GP_MirrorV.algo.h b/libs/filters/algo/GP_MirrorV.algo.h
deleted file mode 100644
index 6555700..0000000
--- a/libs/filters/algo/GP_MirrorV.algo.h
+++ /dev/null
@@ -1,42 +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-2011 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-
-#define DEF_MIRRORV_FN(FN_NAME, CONTEXT_T, PIXEL_T, PUTPIXEL, GETPIXEL) -void FN_NAME(CONTEXT_T context) -{ - uint32_t x, y; - PIXEL_T tmp; -- for (x = 0; x < context->w/2; x++) { - uint32_t xm = context->w - x - 1; - for (y = 0; y < context->h; y++) { - tmp = GETPIXEL(context, x, y); -- PUTPIXEL(context, x, y, GETPIXEL(context, xm, y)); - PUTPIXEL(context, xm, y, tmp); - } - } -}
diff --git a/libs/filters/algo/GP_Rotate.algo.h b/libs/filters/algo/GP_Rotate.algo.h
deleted file mode 100644
index bc7528d..0000000
--- a/libs/filters/algo/GP_Rotate.algo.h
+++ /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-2011 Jiri "BlueBear" Dluhos *
- * <jiri.bluebear.dluhos(a)gmail.com> *
- * *
- * Copyright (C) 2009-2011 Cyril Hrubis <metan(a)ucw.cz> *
- * *
- *****************************************************************************/
-
-#include "core/GP_Common.h"
-#include "core/GP_Context.h"
-
-#define DEF_ROTATECW_FN(FN_NAME, CONTEXT_T, PIXEL_T, PUTPIXEL, GETPIXEL) -GP_RetCode FN_NAME(CONTEXT_T context) -{ - uint32_t x, y; - CONTEXT_T tmp; -- tmp = GP_ContextCopy(context, GP_COPY_WITH_PIXELS); -- if (tmp == NULL) - return GP_ENOMEM; -- GP_SWAP(context->w, context->h); -- context->bytes_per_row = GP_CALC_ROW_SIZE(context->pixel_type, - context->w); -- for (x = 0; x < tmp->w; x++) { - for (y = 0; y < tmp->h; y++) { - uint32_t yr = tmp->h - y - 1; - PUTPIXEL(context, yr, x, GETPIXEL(tmp, x, y)); - } - } -- GP_ContextFree(tmp); -- return GP_ESUCCESS; -}
-
-#define DEF_ROTATECCW_FN(FN_NAME, CONTEXT_T, PIXEL_T, PUTPIXEL, GETPIXEL) -GP_RetCode FN_NAME(CONTEXT_T context) -{ - uint32_t x, y; - CONTEXT_T tmp; -- tmp = GP_ContextCopy(context, GP_COPY_WITH_PIXELS); -- if (tmp == NULL) - return GP_ENOMEM; -- GP_SWAP(context->w, context->h); -- context->bytes_per_row = GP_CALC_ROW_SIZE(context->pixel_type, - context->w); -- for (x = 0; x < tmp->w; x++) { - for (y = 0; y < tmp->h; y++) { - uint32_t xr = tmp->w - x - 1; - PUTPIXEL(context, y, xr, GETPIXEL(tmp, x, y)); - } - } -- GP_ContextFree(tmp); -- return GP_ESUCCESS; -}
http://repo.or.cz/w/gfxprim.git/commit/a8f1ba07c9863cdda6b55a7b82fb35fbe557…
commit a8f1ba07c9863cdda6b55a7b82fb35fbe55758a9
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Oct 27 21:06:31 2011 +0200
Add missing linker flag.
diff --git a/tests/drivers/Makefile b/tests/drivers/Makefile
index 664900d..28ea051 100644
--- a/tests/drivers/Makefile
+++ b/tests/drivers/Makefile
@@ -1,4 +1,4 @@
-LDFLAGS=-L../../build/ -lGP -lpng -ldl
+LDFLAGS=-L../../build/ -lGP -lpng -ldl -ljpeg
INCLUDE=-I../../include
# Some warnings are triggered only with -O2
# thuss added here
http://repo.or.cz/w/gfxprim.git/commit/bcaa19c8129a6bcaac8a3640979e91135c01…
commit bcaa19c8129a6bcaac8a3640979e91135c016846
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Oct 27 16:40:09 2011 +0000
Add context offset.
This is first step for subcontexes for
non byte alignes pixel types.
diff --git a/include/core/GP_Context.h b/include/core/GP_Context.h
index 6bc244c..00138df 100644
--- a/include/core/GP_Context.h
+++ b/include/core/GP_Context.h
@@ -36,10 +36,16 @@
/* This structure holds all information needed for drawing into an image. */
typedef struct GP_Context {
uint8_t *pixels; /* pointer to image pixels */
- uint8_t bpp; /* values: 1, 2, 4, 8, 16, 24, 32 */
+ uint8_t bpp; /* pixel length in bits */
uint32_t bytes_per_row;
uint32_t w; /* width in pixels */
uint32_t h; /* height in pixels */
+ /*
+ * Row bit offset. The offset is ignored for byte aligned pixels.
+ * Basically it's used for non aligned pixels with combination
+ * with subcontextes.
+ */
+ uint8_t offset;
GP_PixelType pixel_type; /* hardware pixel format */
diff --git a/include/core/GP_GetPutPixel.h b/include/core/GP_GetPutPixel.h
index 599da1d..0cd7661 100644
--- a/include/core/GP_GetPutPixel.h
+++ b/include/core/GP_GetPutPixel.h
@@ -67,4 +67,9 @@ static inline void GP_PutPixel_Raw(GP_Context *context, int x, int y,
context, x, y, p);
}
+/*
+ * Returns pixel offset.
+ */
+uint8_t GP_PixelAddrOffset(GP_Coord x, GP_PixelType pixel_type);
+
#endif /* CORE_GP_GETPUTPIXEL_H */
diff --git a/libs/core/GP_Context.c b/libs/core/GP_Context.c
index 0ce6342..83c9f73 100644
--- a/libs/core/GP_Context.c
+++ b/libs/core/GP_Context.c
@@ -52,6 +52,7 @@ GP_Context *GP_ContextCopy(const GP_Context *src, int flag)
new->bpp = src->bpp;
new->bytes_per_row = src->bytes_per_row;
+ new->offset = 0;
new->w = src->w;
new->h = src->h;
@@ -66,7 +67,6 @@ GP_Context *GP_ContextCopy(const GP_Context *src, int flag)
new->free_pixels = 1;
return new;
-
}
GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type)
@@ -87,6 +87,7 @@ GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type)
context->pixels = pixels;
context->bpp = bpp;
context->bytes_per_row = bpr;
+ context->offset = 0;
context->w = w;
context->h = h;
@@ -140,6 +141,8 @@ GP_Context *GP_ContextSubContext(GP_Context *context, GP_Coord x, GP_Coord y,
ret->bpp = context->bpp;
ret->bytes_per_row = context->bytes_per_row;
+ ret->offset = (context->offset +
+ GP_PixelAddrOffset(x, context->pixel_type)) % 8;
ret->w = w;
ret->h = h;
@@ -169,7 +172,7 @@ GP_RetCode GP_ContextDump(GP_Context *context, const char *path)
for (y = 0; y < context->h; y++) {
for (x = 0; x < context->bytes_per_row; x++)
fprintf(f, "0x%02x ", ((uint8_t *)context->pixels)
- [y * context->bytes_per_row + x]);
+ [y * context->bytes_per_row + x]);
fprintf(f, "n");
}
diff --git a/libs/core/GP_GetPutPixel.c b/libs/core/GP_GetPutPixel.c
index 774be54..6550275 100644
--- a/libs/core/GP_GetPutPixel.c
+++ b/libs/core/GP_GetPutPixel.c
@@ -37,3 +37,10 @@ void GP_PutPixel(GP_Context *context, int x, int y, GP_Pixel p)
if (!GP_PIXEL_IS_CLIPPED(context, x, y))
GP_PutPixel_Raw(context, x, y, p);
}
+
+uint8_t GP_PixelAddrOffset(GP_Coord x, GP_PixelType pixel_type)
+{
+ GP_FN_RET_PER_BPP_PIXELTYPE(GP_PIXEL_ADDR_OFFSET, pixel_type, x);
+
+ return 0;
+}
diff --git a/libs/core/GP_Pixel.c b/libs/core/GP_Pixel.c
index 98dc0d0..bedaf14 100644
--- a/libs/core/GP_Pixel.c
+++ b/libs/core/GP_Pixel.c
@@ -28,8 +28,8 @@
#include "GP_Debug.h"
#include "GP_Pixel.h"
-static const GP_PixelTypeChannel *get_channel(const GP_PixelTypeDescription *desc,
- const char *name)
+static const GP_PixelTypeChannel *
+get_channel(const GP_PixelTypeDescription *desc, const char *name)
{
unsigned int i;
@@ -115,8 +115,9 @@ GP_PixelType GP_PixelRGBLookup(uint32_t rsize, uint32_t roff,
{
unsigned int i;
- GP_DEBUG(1, "Looking up Pixel R %08x %08x G %08x %08x B %08x %08x size %u",
- rsize, roff, gsize, goff, bsize, boff, bits_per_pixel);
+ GP_DEBUG(1, "Looking up Pixel R %08x %08x G %08x %08x B %08x %08x "
+ "size %u", rsize, roff, gsize, goff, bsize, boff,
+ bits_per_pixel);
for (i = 0; i < GP_PIXEL_MAX; i++) {
const GP_PixelTypeChannel *r, *g, *b, *a;
http://repo.or.cz/w/gfxprim.git/commit/828d02ecb1948597d7f7b83e86f15e7bb7ca…
commit 828d02ecb1948597d7f7b83e86f15e7bb7ca9164
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Thu Oct 27 16:02:32 2011 +0000
Remove (hopefuly) last function with T prefix.
diff --git a/include/core/GP_GetPutPixel.h b/include/core/GP_GetPutPixel.h
index 9d9b7be..599da1d 100644
--- a/include/core/GP_GetPutPixel.h
+++ b/include/core/GP_GetPutPixel.h
@@ -57,13 +57,6 @@ static inline GP_Pixel GP_GetPixel_Raw(const GP_Context *context, int x, int y)
*/
void GP_PutPixel(GP_Context *context, int x, int y, GP_Pixel p);
-//TODO: This is the same as GP_PutPixel
-static inline void GP_TPutPixel(GP_Context *context, GP_Coord x, GP_Coord y,
- GP_Pixel p)
-{
- GP_PutPixel(context, x, y, p);
-}
-
/*
* Version of PutPixel without transformations nor border checking.
*/
-----------------------------------------------------------------------
Summary of changes:
demos/grinder/grinder.c | 44 +++++++++++++--
demos/grinder/params.c | 39 +++++++++++++-
include/core/GP_Context.h | 8 ++-
include/core/GP_GetPutPixel.h | 12 ++--
include/filters/GP_Rotate.h | 83 ++++++++++++++++++++++-----
libs/core/GP_Context.c | 7 ++-
libs/core/GP_GetPutPixel.c | 7 ++
libs/core/GP_Pixel.c | 9 ++-
libs/filters/GP_MirrorV.gen.c.t | 44 +++++++++++++++
libs/filters/GP_Rotate.c | 105 ++++++++++++++++++++--------------
libs/filters/GP_Rotate.gen.c.t | 71 +++++++++++++++++++++++
libs/filters/Makefile | 3 +-
libs/filters/algo/GP_MirrorV.algo.h | 42 --------------
libs/filters/algo/GP_Rotate.algo.h | 83 ---------------------------
tests/drivers/Makefile | 2 +-
15 files changed, 352 insertions(+), 207 deletions(-)
create mode 100644 libs/filters/GP_MirrorV.gen.c.t
create mode 100644 libs/filters/GP_Rotate.gen.c.t
delete mode 100644 libs/filters/algo/GP_MirrorV.algo.h
delete mode 100644 libs/filters/algo/GP_Rotate.algo.h
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos(a)gmail.com
if you want to unsubscribe, or site admin admin(a)repo.or.cz if you receive
no reply.
--
gfxprim.git ("A simple 2D graphics library with emphasis on correctness and well-defined operation.")
1
0
[repo.or.cz] gfxprim.git branch generate updated: 7d1c1b2c4aeef95941109cbdc5707eff6ad0a36f
by metan 25 Oct '11
by metan 25 Oct '11
25 Oct '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 7d1c1b2c4aeef95941109cbdc5707eff6ad0a36f (commit)
from c8554f3ed96486d4ef20838b260c369f61c61b3c (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/7d1c1b2c4aeef95941109cbdc5707eff6ad0…
commit 7d1c1b2c4aeef95941109cbdc5707eff6ad0a36f
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Oct 25 16:08:45 2011 +0000
fbshow: fix timeval reinitalization.
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index e6c6212..76dcb99 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -143,13 +143,16 @@ int main(int argc, char *argv[])
FD_ZERO(&rfds);
FD_SET(drv->fd, &rfds);
struct timeval tv = {.tv_sec = sleep_sec, .tv_usec = 0};
+ struct timeval *tvp = sleep_sec ? &tv : NULL;
for (;;) {
int ret;
if (drv != NULL) {
- ret = select(drv->fd + 1, &rfds, NULL, NULL, &tv);
-
+ ret = select(drv->fd + 1, &rfds, NULL, NULL, tvp);
+
+ tv.tv_sec = sleep_sec;
+
switch (ret) {
case -1:
GP_FramebufferExit(fb);
-----------------------------------------------------------------------
Summary of changes:
demos/fbshow/fbshow.c | 7 +++++--
1 files changed, 5 insertions(+), 2 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: c8554f3ed96486d4ef20838b260c369f61c61b3c
by metan 25 Oct '11
by metan 25 Oct '11
25 Oct '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 c8554f3ed96486d4ef20838b260c369f61c61b3c (commit)
from 298530749895f3e6eb2805c4cb422e217e85586a (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/c8554f3ed96486d4ef20838b260c369f61c6…
commit c8554f3ed96486d4ef20838b260c369f61c61b3c
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Oct 25 19:40:48 2011 +0200
Loaders: Added experimental JPEG support.
diff --git a/app.mk b/app.mk
index 4c90884..9b31c14 100644
--- a/app.mk
+++ b/app.mk
@@ -2,6 +2,8 @@ ifndef APPS
$(error APPS not defined, fix your library Makefile)
endif
+LDFLAGS+=-lpng -ljpeg
+
all: $(APPS)
CLEAN+=$(APPS)
diff --git a/include/loaders/GP_Loaders.h b/include/loaders/GP_JPG.h
similarity index 74%
copy from include/loaders/GP_Loaders.h
copy to include/loaders/GP_JPG.h
index a245e9a..bef6e10 100644
--- a/include/loaders/GP_Loaders.h
+++ b/include/loaders/GP_JPG.h
@@ -16,33 +16,36 @@
* 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-2011 Cyril Hrubis <metan(a)ucw.cz> *
* *
*****************************************************************************/
/*
-
- Core include file for loaders API.
+
+ JPG support using jpeg library.
*/
-#ifndef GP_LOADERS_H
-#define GP_LOADERS_H
+#ifndef GP_JPG_H
+#define GP_JPG_H
#include "core/GP_Context.h"
-#include "GP_PBM.h"
-#include "GP_PGM.h"
-#include "GP_PPM.h"
+/*
+ * Opens up file and checks signature. Upon successful return the file
+ * possition would be set to eight bytes (exactly after the PNG signature).
+ */
+GP_RetCode GP_OpenJPG(const char *src_path, FILE **f);
-#include "GP_PNG.h"
+/*
+ * Reads PNG from an open FILE. Expects the file possition set after the eight
+ * bytes PNG signature.
+ */
+GP_RetCode GP_ReadJPG(FILE *f, GP_Context **res);
/*
- * Tries to load image accordingly to extension.
+ * Loads a PNG file into GP_Context. The Context is newly allocated.
*/
-GP_RetCode GP_LoadImage(const char *src_path, GP_Context **res);
+GP_RetCode GP_LoadJPG(const char *src_path, GP_Context **res);
-#endif /* GP_LOADERS_H */
+#endif /* GP_JPG_H */
diff --git a/include/loaders/GP_Loaders.h b/include/loaders/GP_Loaders.h
index a245e9a..e3ff703 100644
--- a/include/loaders/GP_Loaders.h
+++ b/include/loaders/GP_Loaders.h
@@ -40,6 +40,8 @@
#include "GP_PNG.h"
+#include "GP_JPG.h"
+
/*
* Tries to load image accordingly to extension.
*/
diff --git a/libs/loaders/GP_JPG.c b/libs/loaders/GP_JPG.c
new file mode 100644
index 0000000..69ddd55
--- /dev/null
+++ b/libs/loaders/GP_JPG.c
@@ -0,0 +1,182 @@
+/*****************************************************************************
+ * 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-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+/*
+
+ JPG image support using jpeg library.
+
+ */
+
+#include <stdint.h>
+#include <inttypes.h>
+
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+#include <setjmp.h>
+
+#include <jpeglib.h>
+
+#include <GP_Context.h>
+#include <GP_Debug.h>
+
+GP_RetCode GP_OpenJPG(const char *src_path, FILE **f)
+{
+ *f = fopen(src_path, "rb");
+
+ if (*f == NULL) {
+ GP_DEBUG(1, "Failed to open '%s' : %s",
+ src_path, strerror(errno));
+ return GP_EBADFILE;
+ }
+
+ //TODO: check signature and rewind the stream
+
+ return GP_ESUCCESS;
+}
+
+struct my_jpg_err {
+ struct jpeg_error_mgr error_mgr;
+
+ jmp_buf setjmp_buf;
+};
+
+static void my_error_exit(j_common_ptr cinfo)
+{
+ struct my_jpg_err *my_err = (struct my_jpg_err*) cinfo->err;
+
+ GP_DEBUG(1, "ERROR reading jpeg file");
+
+ longjmp(my_err->setjmp_buf, 1);
+}
+
+static const char *get_colorspace(J_COLOR_SPACE color_space)
+{
+ switch (color_space) {
+ case JCS_GRAYSCALE:
+ return "Grayscale";
+ case JCS_RGB:
+ return "RGB";
+ case JCS_YCbCr:
+ return "YCbCr";
+ case JCS_CMYK:
+ return "CMYK";
+ case JCS_YCCK:
+ return "YCCK";
+ default:
+ return "Unknown";
+ };
+}
+
+GP_RetCode GP_ReadJPG(FILE *f, GP_Context **res)
+{
+ struct jpeg_decompress_struct cinfo;
+ struct my_jpg_err my_err;
+ GP_Context *ret = NULL;
+
+ cinfo.err = jpeg_std_error(&my_err.error_mgr);
+ my_err.error_mgr.error_exit = my_error_exit;
+
+ if (setjmp(my_err.setjmp_buf)) {
+ jpeg_destroy_decompress(&cinfo);
+ GP_ContextFree(ret);
+ fclose(f);
+ return GP_EBADFILE;
+ }
+
+ jpeg_create_decompress(&cinfo);
+ jpeg_stdio_src(&cinfo, f);
+
+ jpeg_read_header(&cinfo, TRUE);
+
+ GP_DEBUG(1, "Have %s JPEG size %ux%u %i channels",
+ get_colorspace(cinfo.jpeg_color_space),
+ cinfo.image_width, cinfo.image_height,
+ cinfo.num_components);
+
+ GP_Pixel pixel_type;
+
+ switch (cinfo.out_color_space) {
+ case JCS_GRAYSCALE:
+ pixel_type = GP_PIXEL_G8;
+ break;
+ case JCS_RGB:
+ pixel_type = GP_PIXEL_RGB888;
+ break;
+ default:
+ pixel_type = GP_PIXEL_UNKNOWN;
+ }
+
+ if (pixel_type == GP_PIXEL_UNKNOWN) {
+ GP_DEBUG(1, "Can't handle %s JPEG output format",
+ get_colorspace(cinfo.out_color_space));
+ jpeg_destroy_decompress(&cinfo);
+ fclose(f);
+ return GP_EBADFILE;
+ }
+
+ ret = GP_ContextAlloc(cinfo.image_width, cinfo.image_height,
+ pixel_type);
+
+ if (ret == NULL) {
+ GP_DEBUG(1, "Malloc failed :(");
+ jpeg_destroy_decompress(&cinfo);
+ fclose(f);
+ return GP_ENOMEM;
+ }
+
+ jpeg_start_decompress(&cinfo);
+
+ while (cinfo.output_scanline < cinfo.output_height) {
+ uint32_t y = cinfo.output_scanline;
+
+ JSAMPROW addr = (void*)GP_PIXEL_ADDR(ret, 0, y);
+ jpeg_read_scanlines(&cinfo, &addr, 1);
+
+ //TODO: fixme bigendian?
+ /* fix the pixel, as we want in fact BGR */
+ uint32_t i;
+
+ for (i = 0; i < ret->w; i++) {
+ uint8_t *pix = GP_PIXEL_ADDR(ret, i, y);
+ GP_SWAP(pix[0], pix[2]);
+ }
+ }
+
+ jpeg_finish_decompress(&cinfo);
+ jpeg_destroy_decompress(&cinfo);
+ fclose(f);
+ *res = ret;
+
+ return GP_ESUCCESS;
+}
+
+GP_RetCode GP_LoadJPG(const char *src_path, GP_Context **res)
+{
+ FILE *f;
+ GP_RetCode ret;
+
+ if ((ret = GP_OpenJPG(src_path, &f)))
+ return ret;
+
+ return GP_ReadJPG(f, res);
+}
diff --git a/libs/loaders/GP_Loaders.c b/libs/loaders/GP_Loaders.c
index 63f1da5..8f69d03 100644
--- a/libs/loaders/GP_Loaders.c
+++ b/libs/loaders/GP_Loaders.c
@@ -56,6 +56,20 @@ GP_RetCode GP_LoadImage(const char *src_path, GP_Context **res)
src_path[len - 3] == 'P')
ret = GP_LoadPNG(src_path, res);
break;
+ case 'p':
+ case 'P':
+ if (src_path[len - 3] == 'j' ||
+ src_path[len - 3] == 'J')
+ ret = GP_LoadJPG(src_path, res);
+ break;
+ case 'e':
+ case 'E':
+ if ((src_path[len - 3] == 'p' ||
+ src_path[len - 3] == 'P') &&
+ (src_path[len - 4] == 'j' ||
+ src_path[len - 4] == 'J'))
+ ret = GP_LoadJPG(src_path, res);
+ break;
}
break;
/* PPM, PGM, PBM, PNM */
-----------------------------------------------------------------------
Summary of changes:
app.mk | 2 +
include/loaders/{GP_PNG.h => GP_JPG.h} | 14 ++--
include/loaders/GP_Loaders.h | 2 +
libs/loaders/GP_JPG.c | 182 ++++++++++++++++++++++++++++++++
libs/loaders/GP_Loaders.c | 14 +++
5 files changed, 207 insertions(+), 7 deletions(-)
copy include/loaders/{GP_PNG.h => GP_JPG.h} (88%)
create mode 100644 libs/loaders/GP_JPG.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
[repo.or.cz] gfxprim.git branch generate updated: 298530749895f3e6eb2805c4cb422e217e85586a
by metan 25 Oct '11
by metan 25 Oct '11
25 Oct '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 298530749895f3e6eb2805c4cb422e217e85586a (commit)
via 4bf88545a7e86d3a925a83e19ba7c92920a14cb5 (commit)
via 48642159e541d480d808e876239566e8b1077de5 (commit)
from 859d22427003b1d4be3f536075d48a847bcd2c8a (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/298530749895f3e6eb2805c4cb422e217e85…
commit 298530749895f3e6eb2805c4cb422e217e85586a
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Oct 25 12:51:00 2011 +0000
Fix merge.
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index 12d4626..e6c6212 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -48,7 +48,7 @@ static GP_Context *image_to_display(GP_Context *img, uint32_t w, uint32_t h)
{
float rat = calc_img_size(img->w, img->h, w, h);
- return GP_FilterResize(img, NULL, GP_INTER_CUBIC, img->w * rat, img->h * rat);
+ return GP_FilterResize(img, NULL, GP_INTERP_CUBIC, img->w * rat, img->h * rat);
}
static int show_image(GP_Framebuffer *fb, const char *img_path, int clear)
http://repo.or.cz/w/gfxprim.git/commit/4bf88545a7e86d3a925a83e19ba7c92920a1…
commit 4bf88545a7e86d3a925a83e19ba7c92920a14cb5
Merge: 4864215 859d224
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Oct 25 12:31:24 2011 +0000
Merge branch 'generate' of git://repo.or.cz/gfxprim into generate
http://repo.or.cz/w/gfxprim.git/commit/48642159e541d480d808e876239566e8b107…
commit 48642159e541d480d808e876239566e8b1077de5
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Oct 24 17:56:37 2011 +0200
Base for framebuffer image viewer.
diff --git a/demos/Makefile b/demos/Makefile
index 571580a..eddfa9f 100644
--- a/demos/Makefile
+++ b/demos/Makefile
@@ -1,3 +1,3 @@
TOPDIR=..
-SUBDIRS=grinder
+SUBDIRS=grinder fbshow
include $(TOPDIR)/include.mk
diff --git a/demos/fbshow/Makefile b/demos/fbshow/Makefile
new file mode 100644
index 0000000..2ca7439
--- /dev/null
+++ b/demos/fbshow/Makefile
@@ -0,0 +1,11 @@
+TOPDIR=../..
+
+CSOURCES=$(shell echo *.c)
+
+INCLUDE=
+LDLIBS+=-lGP -L$(TOPDIR)/build/ -lpng
+
+APPS=fbshow
+
+include $(TOPDIR)/include.mk
+include $(TOPDIR)/app.mk
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
new file mode 100644
index 0000000..12d4626
--- /dev/null
+++ b/demos/fbshow/fbshow.c
@@ -0,0 +1,214 @@
+/*****************************************************************************
+ * 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-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+ /*
+
+ Simple framebuffer image viewer.
+
+ */
+
+#include <unistd.h>
+
+#include <GP.h>
+#include <backends/GP_Framebuffer.h>
+#include <input/GP_InputDriverLinux.h>
+
+static GP_Pixel black_pixel;
+static GP_Pixel white_pixel;
+
+static float calc_img_size(uint32_t img_w, uint32_t img_h,
+ uint32_t src_w, uint32_t src_h)
+{
+ float w_rat = 1.00 * src_w / img_w;
+ float h_rat = 1.00 * src_h / img_h;
+
+ return GP_MIN(w_rat, h_rat);
+}
+
+static GP_Context *image_to_display(GP_Context *img, uint32_t w, uint32_t h)
+{
+ float rat = calc_img_size(img->w, img->h, w, h);
+
+ return GP_FilterResize(img, NULL, GP_INTER_CUBIC, img->w * rat, img->h * rat);
+}
+
+static int show_image(GP_Framebuffer *fb, const char *img_path, int clear)
+{
+ GP_Context *img;
+
+ if (clear) {
+ char buf[100];
+ snprintf(buf, sizeof(buf), "Loading '%s'", img_path);
+ GP_Fill(&fb->context, black_pixel);
+ GP_BoxCenteredText(&fb->context, NULL, 0, 0,
+ fb->context.w, fb->context.h,
+ buf, white_pixel);
+ }
+
+ if (GP_LoadImage(img_path, &img) == 0) {
+ GP_Context *img2 = image_to_display(img, fb->context.w, fb->context.h);
+
+ GP_ContextFree(img);
+
+ if (img2 == NULL)
+ return 1;
+
+ uint32_t cx = (fb->context.w - img2->w)/2;
+ uint32_t cy = (fb->context.h - img2->h)/2;
+
+ GP_Fill(&fb->context, black_pixel);
+
+ GP_Blit(img2, 0, 0, img2->w, img2->h, &fb->context, cx, cy);
+
+ GP_ContextFree(img2);
+ }
+
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ GP_Framebuffer *fb;
+ GP_InputDriverLinux *drv = NULL;
+ char *input_dev = NULL;
+ int sleep_sec = 0;
+
+ int opt;
+
+ while ((opt = getopt(argc, argv, "i:s:")) != -1) {
+ switch (opt) {
+ case 'i':
+ input_dev = optarg;
+ break;
+ case 's':
+ sleep_sec = atoi(optarg);
+ break;
+ default:
+ fprintf(stderr, "Invalid paramter '%c'n", opt);
+ }
+ }
+
+ GP_SetDebugLevel(10);
+
+ if (input_dev == NULL) {
+ sleep_sec = 1;
+ } else {
+ drv = GP_InputDriverLinuxOpen(input_dev);
+
+ if (drv == NULL) {
+ fprintf(stderr, "Failed to initalize input device '%s'n",
+ input_dev);
+ return 1;
+ }
+ }
+
+ fb = GP_FramebufferInit("/dev/fb0");
+
+ if (fb == NULL) {
+ fprintf(stderr, "Failed to initalize framebuffern");
+ return 1;
+ }
+
+ GP_EventSetScreenSize(fb->context.w, fb->context.h);
+
+ black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, &fb->context);
+ white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, &fb->context);
+
+ int argf = optind;
+ int argn = argf;
+
+ show_image(fb, argv[argf], 1);
+
+ /* Initalize select */
+ fd_set rfds;
+ FD_ZERO(&rfds);
+ FD_SET(drv->fd, &rfds);
+ struct timeval tv = {.tv_sec = sleep_sec, .tv_usec = 0};
+
+ for (;;) {
+ int ret;
+
+ if (drv != NULL) {
+ ret = select(drv->fd + 1, &rfds, NULL, NULL, &tv);
+
+ switch (ret) {
+ case -1:
+ GP_FramebufferExit(fb);
+ return 0;
+ break;
+ case 0:
+ argn++;
+ if (argn >= argc)
+ argn = argf;
+
+ show_image(fb, argv[argn], 0);
+ break;
+ default:
+ while (GP_InputDriverLinuxRead(drv));
+ }
+
+ FD_SET(drv->fd, &rfds);
+ } else {
+ sleep(sleep_sec);
+
+ argn++;
+ if (argn >= argc)
+ argn = argf;
+
+ show_image(fb, argv[argn], 0);
+ }
+
+ /* Read and parse events */
+ GP_Event ev;
+
+ while (GP_EventGet(&ev)) {
+
+ GP_EventDump(&ev);
+
+ switch (ev.type) {
+ case GP_EV_KEY:
+ if (ev.code != GP_EV_KEY_DOWN)
+ continue;
+
+ switch (ev.val.key.key) {
+ case GP_KEY_ENTER:
+ GP_FramebufferExit(fb);
+ return 0;
+ break;
+ case GP_KEY_ESC:
+ case GP_KEY_SPACE:
+ case GP_KEY_Q:
+ argn++;
+ if (argn >= argc)
+ argn = argf;
+ show_image(fb, argv[argn], 1);
+ break;
+ }
+ break;
+ }
+ }
+ }
+
+ GP_FramebufferExit(fb);
+
+ return 0;
+}
diff --git a/demos/fbshow/runtest.sh b/demos/fbshow/runtest.sh
new file mode 100755
index 0000000..163c76c
--- /dev/null
+++ b/demos/fbshow/runtest.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+#
+# Run dynamically linked test.
+#
+
+PROG="$1"
+shift
+
+echo "LD_LIBRARY_PATH=../../build/ ./$PROG $@"
+LD_LIBRARY_PATH=../../build/ ./$PROG "$@"
-----------------------------------------------------------------------
Summary of changes:
demos/Makefile | 2 +-
demos/{grinder => fbshow}/Makefile | 6 +-
demos/fbshow/fbshow.c | 214 ++++++++++++++++++++++++++++++++
{tests/SDL => demos/fbshow}/runtest.sh | 2 +-
4 files changed, 218 insertions(+), 6 deletions(-)
copy demos/{grinder => fbshow}/Makefile (68%)
create mode 100644 demos/fbshow/fbshow.c
copy {tests/SDL => demos/fbshow}/runtest.sh (72%)
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: 859d22427003b1d4be3f536075d48a847bcd2c8a
by metan 25 Oct '11
by metan 25 Oct '11
25 Oct '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 859d22427003b1d4be3f536075d48a847bcd2c8a (commit)
via 4500e9d17c2657652e54e1ff4796d09bbef67952 (commit)
from 040f8cdfb686e243d75d7c4e27c36b495d76656f (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/859d22427003b1d4be3f536075d48a847bcd…
commit 859d22427003b1d4be3f536075d48a847bcd2c8a
Merge: 040f8cd 4500e9d
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Oct 25 12:24:02 2011 +0200
Merge ssh://192.168.1.1/home/metan/Devel/gfxprim into generate
http://repo.or.cz/w/gfxprim.git/commit/4500e9d17c2657652e54e1ff4796d09bbef6…
commit 4500e9d17c2657652e54e1ff4796d09bbef67952
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Tue Oct 25 14:13:47 2011 +0200
Filters: INTER -> INTERP.
diff --git a/include/filters/GP_Resize.h b/include/filters/GP_Resize.h
index 54acaed..05f80c7 100644
--- a/include/filters/GP_Resize.h
+++ b/include/filters/GP_Resize.h
@@ -47,8 +47,8 @@
#include "GP_Filter.h"
typedef enum GP_InterpolationType {
- GP_INTER_NN, /* Nearest Neighbour */
- GP_INTER_CUBIC, /* Bicubic */
+ GP_INTERP_NN, /* Nearest Neighbour */
+ GP_INTERP_CUBIC, /* Bicubic */
} GP_InterpolationType;
void GP_FilterResize_Raw(GP_Context *src, GP_Context *res,
diff --git a/libs/filters/GP_Resize.c b/libs/filters/GP_Resize.c
index 6f944a6..192d5f5 100644
--- a/libs/filters/GP_Resize.c
+++ b/libs/filters/GP_Resize.c
@@ -214,10 +214,10 @@ void GP_FilterResize_Raw(GP_Context *src, GP_Context *res,
GP_InterpolationType type)
{
switch (type) {
- case GP_INTER_NN:
+ case GP_INTERP_NN:
GP_FilterInterpolate_NN(src, res, callback);
break;
- case GP_INTER_CUBIC:
+ case GP_INTERP_CUBIC:
GP_FilterInterpolate_Cubic(src, res, callback);
break;
}
-----------------------------------------------------------------------
Summary of changes:
include/filters/GP_Resize.h | 4 ++--
libs/filters/GP_Resize.c | 4 ++--
2 files changed, 4 insertions(+), 4 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: 040f8cdfb686e243d75d7c4e27c36b495d76656f
by metan 24 Oct '11
by metan 24 Oct '11
24 Oct '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 040f8cdfb686e243d75d7c4e27c36b495d76656f (commit)
from fb50f1facaec877cd3b8a71f6d621648ebc0f451 (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/040f8cdfb686e243d75d7c4e27c36b495d76…
commit 040f8cdfb686e243d75d7c4e27c36b495d76656f
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Oct 24 17:46:32 2011 +0200
Added input driver desctructor + typedef.
diff --git a/include/input/GP_InputDriverLinux.h b/include/input/GP_InputDriverLinux.h
index ed70c15..ea5b370 100644
--- a/include/input/GP_InputDriverLinux.h
+++ b/include/input/GP_InputDriverLinux.h
@@ -31,7 +31,7 @@
#include <stdint.h>
-struct GP_InputDriverLinux {
+typedef struct GP_InputDriverLinux {
/* fd */
int fd;
@@ -51,11 +51,19 @@ struct GP_InputDriverLinux {
int abs_press_max;
uint8_t abs_flag;
-};
+} GP_InputDriverLinux;
+/*
+ * Initalize and allocate input driver.
+ */
struct GP_InputDriverLinux *GP_InputDriverLinuxOpen(const char *path);
/*
+ * Close the fd, free memory.
+ */
+void GP_InputDriverLinuxClose(struct GP_InputDriverLinux *self);
+
+/*
* Called when there are data ready on input device.
*
* May or may not generate GP_Event.
diff --git a/libs/input/GP_InputDriverLinux.c b/libs/input/GP_InputDriverLinux.c
index a0f4ddf..05557dd 100644
--- a/libs/input/GP_InputDriverLinux.c
+++ b/libs/input/GP_InputDriverLinux.c
@@ -142,6 +142,15 @@ struct GP_InputDriverLinux *GP_InputDriverLinuxOpen(const char *path)
return ret;
}
+void GP_InputDriverLinuxClose(struct GP_InputDriverLinux *self)
+{
+ GP_DEBUG(1, "Closing input device");
+ print_name(self->fd);
+
+ close(self->fd);
+ free(self);
+}
+
static void input_rel(struct GP_InputDriverLinux *self, struct input_event *ev)
{
GP_DEBUG(4, "Relative event");
-----------------------------------------------------------------------
Summary of changes:
include/input/GP_InputDriverLinux.h | 12 ++++++++++--
libs/input/GP_InputDriverLinux.c | 9 +++++++++
2 files changed, 19 insertions(+), 2 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: fb50f1facaec877cd3b8a71f6d621648ebc0f451
by metan 24 Oct '11
by metan 24 Oct '11
24 Oct '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 fb50f1facaec877cd3b8a71f6d621648ebc0f451 (commit)
via d8cb24d4ac08ad588cda79f2a5c1e96e48587484 (commit)
from 1a1eb5042ec3cb87352d5d8d3f051ba7f600a7ed (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/fb50f1facaec877cd3b8a71f6d621648ebc0…
commit fb50f1facaec877cd3b8a71f6d621648ebc0f451
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Oct 24 15:30:25 2011 +0000
Fixes for abs linux event driver.
diff --git a/libs/input/GP_Event.c b/libs/input/GP_Event.c
index e5beb2e..129f1ee 100644
--- a/libs/input/GP_Event.c
+++ b/libs/input/GP_Event.c
@@ -119,6 +119,8 @@ const char *GP_EventKeyName(enum GP_EventKeyValue key)
return "RightButton";
case GP_BTN_MIDDLE:
return "MiddleButton";
+ case GP_BTN_PEN:
+ return "Pen";
default:
return "Unknown";
};
@@ -151,6 +153,16 @@ static void dump_key(struct GP_Event *ev)
}
+static void dump_abs(struct GP_Event *ev)
+{
+ switch (ev->code) {
+ case GP_EV_ABS_POS:
+ printf("POSSITION %u %u %un",
+ ev->cursor_x, ev->cursor_y, ev->val.abs.pressure);
+ break;
+ }
+}
+
void GP_EventDump(struct GP_Event *ev)
{
printf("EVENT (%u) ", (unsigned int)ev->time.tv_sec % 10000);
@@ -163,8 +175,10 @@ void GP_EventDump(struct GP_Event *ev)
dump_rel(ev);
break;
case GP_EV_ABS:
- printf("EVENT ABSn");
+ dump_abs(ev);
break;
+ default:
+ printf("Unknown %un", ev->type);
}
}
@@ -229,7 +243,7 @@ void GP_EventPushAbs(uint32_t x, uint32_t y, uint32_t pressure,
{
/* event header */
cur_state.type = GP_EV_ABS;
- cur_state.code = GP_EV_REL_POS;
+ cur_state.code = GP_EV_ABS_POS;
cur_state.val.abs.x = x;
cur_state.val.abs.y = y;
cur_state.val.abs.pressure = pressure;
@@ -239,9 +253,11 @@ void GP_EventPushAbs(uint32_t x, uint32_t y, uint32_t pressure,
set_time(time);
- /* set global cursor */
- cur_state.cursor_x = x * screen_w / x_max;
- cur_state.cursor_y = y * screen_h / y_max;
+ /* set global cursor, pressure == 0 is penup */
+ if (pressure != 0) {
+ cur_state.cursor_x = x * screen_w / x_max;
+ cur_state.cursor_y = y * screen_h / y_max;
+ }
/* put it into queue */
event_put(&cur_state);
diff --git a/libs/input/GP_InputDriverLinux.c b/libs/input/GP_InputDriverLinux.c
index 22138cd..a0f4ddf 100644
--- a/libs/input/GP_InputDriverLinux.c
+++ b/libs/input/GP_InputDriverLinux.c
@@ -144,7 +144,7 @@ struct GP_InputDriverLinux *GP_InputDriverLinuxOpen(const char *path)
static void input_rel(struct GP_InputDriverLinux *self, struct input_event *ev)
{
- GP_DEBUG(3, "Relative event");
+ GP_DEBUG(4, "Relative event");
switch (ev->code) {
case REL_X:
@@ -162,7 +162,7 @@ static void input_rel(struct GP_InputDriverLinux *self, struct input_event *ev)
static void input_abs(struct GP_InputDriverLinux *self, struct input_event *ev)
{
- GP_DEBUG(3, "Absolute event");
+ GP_DEBUG(4, "Absolute event");
switch (ev->code) {
case ABS_X:
@@ -184,7 +184,7 @@ static void input_abs(struct GP_InputDriverLinux *self, struct input_event *ev)
static void input_key(struct GP_InputDriverLinux *self, struct input_event *ev)
{
- GP_DEBUG(3, "Key event");
+ GP_DEBUG(4, "Key event");
(void) self;
@@ -213,7 +213,7 @@ static void do_sync(struct GP_InputDriverLinux *self)
static void input_syn(struct GP_InputDriverLinux *self, struct input_event *ev)
{
- GP_DEBUG(3, "Sync event");
+ GP_DEBUG(4, "Sync event");
switch (ev->code) {
case 0:
@@ -229,27 +229,30 @@ int GP_InputDriverLinuxRead(struct GP_InputDriverLinux *self)
struct input_event ev;
int ret;
- while ((ret = read(self->fd, &ev, sizeof(ev))) != -1) {
- switch (ev.type) {
- case EV_REL:
- input_rel(self, &ev);
- break;
- case EV_ABS:
- input_abs(self, &ev);
- break;
- case EV_KEY:
- input_key(self, &ev);
- break;
- case EV_SYN:
- input_syn(self, &ev);
- break;
- default:
- GP_DEBUG(3, "Unhandled type %i", ev.type);
- }
- }
+ ret = read(self->fd, &ev, sizeof(ev));
if (ret == -1 && errno == EAGAIN)
return 0;
+ if (ret < 1)
+ return -1;
+
+ switch (ev.type) {
+ case EV_REL:
+ input_rel(self, &ev);
+ break;
+ case EV_ABS:
+ input_abs(self, &ev);
+ break;
+ case EV_KEY:
+ input_key(self, &ev);
+ break;
+ case EV_SYN:
+ input_syn(self, &ev);
+ break;
+ default:
+ GP_DEBUG(3, "Unhandled type %i", ev.type);
+ }
+
return 1;
}
diff --git a/tests/drivers/linux_input.c b/tests/drivers/linux_input.c
index 04a0480..86b75a6 100644
--- a/tests/drivers/linux_input.c
+++ b/tests/drivers/linux_input.c
@@ -24,8 +24,6 @@
*/
-#include <math.h>
-
#include <GP.h>
#include <input/GP_InputDriverLinux.h>
@@ -33,7 +31,7 @@ int main(int argc, char *argv[])
{
struct GP_InputDriverLinux *drv;
- GP_SetDebugLevel(10);
+ GP_SetDebugLevel(2);
if (argc != 2) {
printf("Usage: %s /dev/input/eventXn", argv[0]);
@@ -50,14 +48,12 @@ int main(int argc, char *argv[])
GP_EventSetScreenSize(640, 480);
for (;;) {
- GP_InputDriverLinuxRead(drv);
+ while (GP_InputDriverLinuxRead(drv) >= 1);
- while (GP_EventQueued()) {
- GP_Event ev;
+ GP_Event ev;
- GP_EventGet(&ev);
+ while (GP_EventGet(&ev))
GP_EventDump(&ev);
- }
usleep(1000);
}
http://repo.or.cz/w/gfxprim.git/commit/d8cb24d4ac08ad588cda79f2a5c1e96e4858…
commit d8cb24d4ac08ad588cda79f2a5c1e96e48587484
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Oct 24 15:27:42 2011 +0000
Fix the Set/Get/Reset Key not to touch out of the array.
diff --git a/include/input/GP_Event.h b/include/input/GP_Event.h
index 126c0c2..cb412f1 100644
--- a/include/input/GP_Event.h
+++ b/include/input/GP_Event.h
@@ -39,6 +39,8 @@
#define GP_EVENT_QUEUE_SIZE 32
+#define GP_EVENT_KEYMAP_BYTES 36
+
enum GP_EventType {
GP_EV_KEY = 1, /* key/button press event */
GP_EV_REL = 2, /* relative event */
@@ -204,6 +206,9 @@ enum GP_EventKeyValue {
GP_BTN_FORWARD = 0x115,
GP_BTN_BACK = 0x116,
GP_BTN_TASK = 0x117,
+
+ /* Touchscreen pen */
+ GP_BTN_PEN = 0x14a,
};
enum GP_EventRelCode {
@@ -264,7 +269,7 @@ typedef struct GP_Event {
* Bitmap of pressed keys including mouse buttons
* accumulated for all input devices.
*/
- uint8_t keys_pressed[36];
+ uint8_t keys_pressed[GP_EVENT_KEYMAP_BYTES];
} GP_Event;
/*
@@ -328,18 +333,27 @@ void GP_EventPush(uint16_t type, uint32_t code, int32_t value,
static inline void GP_EventSetKey(struct GP_Event *ev,
uint32_t key)
{
+ if (key >= GP_EVENT_KEYMAP_BYTES * 8)
+ return;
+
ev->keys_pressed[(key)/8] |= 1<<((key)%8);
}
static inline int GP_EventGetKey(struct GP_Event *ev,
uint32_t key)
{
+ if (key >= GP_EVENT_KEYMAP_BYTES * 8)
+ return 0;
+
return !!(ev->keys_pressed[(key)/8] & (1<<((key)%8)));
}
static inline void GP_EventResetKey(struct GP_Event *ev,
uint32_t key)
{
+ if (key >= GP_EVENT_KEYMAP_BYTES * 8)
+ return;
+
ev->keys_pressed[(key)/8] &= ~(1<<((key)%8));
}
-----------------------------------------------------------------------
Summary of changes:
include/input/GP_Event.h | 16 ++++++++++++-
libs/input/GP_Event.c | 26 +++++++++++++++++----
libs/input/GP_InputDriverLinux.c | 47 ++++++++++++++++++++-----------------
tests/drivers/linux_input.c | 12 +++------
4 files changed, 65 insertions(+), 36 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: 1a1eb5042ec3cb87352d5d8d3f051ba7f600a7ed
by metan 24 Oct '11
by metan 24 Oct '11
24 Oct '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 1a1eb5042ec3cb87352d5d8d3f051ba7f600a7ed (commit)
from cbea4b71a8151b445c662f50b12b50dccb7285c9 (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/1a1eb5042ec3cb87352d5d8d3f051ba7f600…
commit 1a1eb5042ec3cb87352d5d8d3f051ba7f600a7ed
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Mon Oct 24 17:15:10 2011 +0200
Quick and dirty linux event input driver.
diff --git a/include/input/GP_InputDriverLinux.h b/include/input/GP_InputDriverLinux.h
new file mode 100644
index 0000000..ed70c15
--- /dev/null
+++ b/include/input/GP_InputDriverLinux.h
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * 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-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+/*
+
+ Linux input device driver.
+
+ */
+
+#ifndef GP_INPUT_DRIVER_LINUX_H
+#define GP_INPUT_DRIVER_LINUX_H
+
+#include <stdint.h>
+
+struct GP_InputDriverLinux {
+ /* fd */
+ int fd;
+
+ /* to store rel coordinates */
+ int rel_x;
+ int rel_y;
+
+ uint8_t rel_flag;
+
+ /* to store abs coordinates */
+ int abs_x;
+ int abs_y;
+ int abs_press;
+
+ int abs_x_max;
+ int abs_y_max;
+ int abs_press_max;
+
+ uint8_t abs_flag;
+};
+
+struct GP_InputDriverLinux *GP_InputDriverLinuxOpen(const char *path);
+
+/*
+ * Called when there are data ready on input device.
+ *
+ * May or may not generate GP_Event.
+ *
+ * Returns 0 on succes -1 on error and errno is set.
+ */
+int GP_InputDriverLinuxRead(struct GP_InputDriverLinux *self);
+
+#endif /* GP_INPUT_DRIVER_LINUX_H */
diff --git a/libs/input/GP_InputDriverLinux.c b/libs/input/GP_InputDriverLinux.c
new file mode 100644
index 0000000..22138cd
--- /dev/null
+++ b/libs/input/GP_InputDriverLinux.c
@@ -0,0 +1,255 @@
+/*****************************************************************************
+ * 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-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <linux/input.h>
+
+#include "core/GP_Debug.h"
+
+#include "GP_Event.h"
+#include "GP_InputDriverLinux.h"
+
+int get_version(int fd)
+{
+ int ver;
+
+ if (ioctl(fd, EVIOCGVERSION, &ver))
+ return -1;
+
+ GP_DEBUG(2, "Input version %u.%u.%u",
+ ver>>16, (ver>>8)&0xff, ver&0xff);
+
+ return 0;
+}
+
+/*
+ * Returns size on success just as read()
+ */
+int get_name(int fd, char *buf, size_t buf_len)
+{
+ int ret;
+
+ if ((ret = ioctl(fd, EVIOCGNAME(buf_len), buf)) <= 0)
+ return -1;
+
+ return ret;
+}
+
+void print_name(int fd)
+{
+ char name[64];
+
+ if (GP_GetDebugLevel() < 2)
+ return;
+
+ if (get_name(fd, name, sizeof(name)) > 0)
+ GP_DEBUG(2, "Input device name '%s'", name);
+}
+
+void try_load_callibration(struct GP_InputDriverLinux *self)
+{
+ long bit = 0;
+ int abs[5];
+
+ ioctl(self->fd, EVIOCGBIT(EV_ABS, EV_ABS), &bit);
+
+ if (!bit) {
+ GP_DEBUG(3, "Not an absolute input device");
+ return;
+ }
+
+ if (!ioctl(self->fd, EVIOCGABS(ABS_X), abs)) {
+ GP_DEBUG(3, "ABS X = <%i,%i>", abs[1], abs[2]);
+ self->abs_x_max = abs[2];
+ }
+
+ if (!ioctl(self->fd, EVIOCGABS(ABS_Y), abs)) {
+ GP_DEBUG(3, "ABS Y = <%i,%i>", abs[1], abs[2]);
+ self->abs_y_max = abs[2];
+ }
+
+ if (!ioctl(self->fd, EVIOCGABS(ABS_PRESSURE), abs)) {
+ GP_DEBUG(3, "ABS P = <%i,%i>", abs[1], abs[2]);
+ self->abs_press_max = abs[2];
+ }
+}
+
+struct GP_InputDriverLinux *GP_InputDriverLinuxOpen(const char *path)
+{
+ int fd;
+ struct GP_InputDriverLinux *ret;
+
+ GP_DEBUG(2, "Opening '%s'", path);
+
+ fd = open(path, O_RDONLY | O_NONBLOCK);
+
+ if (fd < 0) {
+ GP_DEBUG(1, "Failed to open '%s': %s", path, strerror(errno));
+ return NULL;
+ }
+
+ if (get_version(fd)) {
+ GP_DEBUG(1, "Failed ioctl(), not a input device?");
+ return NULL;
+ }
+
+ print_name(fd);
+
+ ret = malloc(sizeof(struct GP_InputDriverLinux));
+
+ if (ret == NULL) {
+ GP_DEBUG(1, "Malloc failed :(");
+ close(fd);
+ return NULL;
+ }
+
+ ret->fd = fd;
+
+ ret->rel_x = 0;
+ ret->rel_y = 0;
+ ret->rel_flag = 0;
+
+ ret->abs_x = 0;
+ ret->abs_y = 0;
+ ret->abs_press = 0;
+ ret->abs_flag = 0;
+
+ try_load_callibration(ret);
+
+ return ret;
+}
+
+static void input_rel(struct GP_InputDriverLinux *self, struct input_event *ev)
+{
+ GP_DEBUG(3, "Relative event");
+
+ switch (ev->code) {
+ case REL_X:
+ self->rel_x = ev->value;
+ self->rel_flag = 1;
+ break;
+ case REL_Y:
+ self->rel_y = ev->value;
+ self->rel_flag = 1;
+ break;
+ default:
+ GP_DEBUG(3, "Unhandled code %i", ev->code);
+ }
+}
+
+static void input_abs(struct GP_InputDriverLinux *self, struct input_event *ev)
+{
+ GP_DEBUG(3, "Absolute event");
+
+ switch (ev->code) {
+ case ABS_X:
+ self->abs_x = ev->value;
+ self->abs_flag = 1;
+ break;
+ case ABS_Y:
+ self->abs_y = ev->value;
+ self->abs_flag = 1;
+ break;
+ case ABS_PRESSURE:
+ self->abs_press = ev->value;
+ self->abs_flag = 1;
+ break;
+ default:
+ GP_DEBUG(3, "Unhandled code %i", ev->code);
+ }
+}
+
+static void input_key(struct GP_InputDriverLinux *self, struct input_event *ev)
+{
+ GP_DEBUG(3, "Key event");
+
+ (void) self;
+
+ GP_EventPushKey(ev->code, ev->value, NULL);
+}
+
+static void do_sync(struct GP_InputDriverLinux *self)
+{
+ if (self->rel_flag) {
+ self->rel_flag = 0;
+ GP_EventPushRel(self->rel_x, self->rel_y, NULL);
+ self->rel_x = 0;
+ self->rel_y = 0;
+ }
+
+ if (self->abs_flag) {
+ self->abs_flag = 0;
+ GP_EventPushAbs(self->abs_x, self->abs_y, self->abs_press,
+ self->abs_x_max, self->abs_y_max,
+ self->abs_press_max, NULL);
+ self->abs_x = 0;
+ self->abs_y = 0;
+ self->abs_press = 0;
+ }
+}
+
+static void input_syn(struct GP_InputDriverLinux *self, struct input_event *ev)
+{
+ GP_DEBUG(3, "Sync event");
+
+ switch (ev->code) {
+ case 0:
+ do_sync(self);
+ break;
+ default:
+ GP_DEBUG(3, "Unhandled code %i", ev->code);
+ }
+}
+
+int GP_InputDriverLinuxRead(struct GP_InputDriverLinux *self)
+{
+ struct input_event ev;
+ int ret;
+
+ while ((ret = read(self->fd, &ev, sizeof(ev))) != -1) {
+ switch (ev.type) {
+ case EV_REL:
+ input_rel(self, &ev);
+ break;
+ case EV_ABS:
+ input_abs(self, &ev);
+ break;
+ case EV_KEY:
+ input_key(self, &ev);
+ break;
+ case EV_SYN:
+ input_syn(self, &ev);
+ break;
+ default:
+ GP_DEBUG(3, "Unhandled type %i", ev.type);
+ }
+ }
+
+ if (ret == -1 && errno == EAGAIN)
+ return 0;
+
+ return 1;
+}
diff --git a/tests/drivers/linux_input.c b/tests/drivers/linux_input.c
new file mode 100644
index 0000000..04a0480
--- /dev/null
+++ b/tests/drivers/linux_input.c
@@ -0,0 +1,66 @@
+/*****************************************************************************
+ * 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-2011 Cyril Hrubis <metan(a)ucw.cz> *
+ * *
+ *****************************************************************************/
+
+ /*
+
+ */
+
+#include <math.h>
+
+#include <GP.h>
+#include <input/GP_InputDriverLinux.h>
+
+int main(int argc, char *argv[])
+{
+ struct GP_InputDriverLinux *drv;
+
+ GP_SetDebugLevel(10);
+
+ if (argc != 2) {
+ printf("Usage: %s /dev/input/eventXn", argv[0]);
+ return 1;
+ }
+
+ drv = GP_InputDriverLinuxOpen(argv[1]);
+
+ if (drv == NULL) {
+ printf("Failed to open input devicen");
+ return 1;
+ }
+
+ GP_EventSetScreenSize(640, 480);
+
+ for (;;) {
+ GP_InputDriverLinuxRead(drv);
+
+ while (GP_EventQueued()) {
+ GP_Event ev;
+
+ GP_EventGet(&ev);
+ GP_EventDump(&ev);
+ }
+
+ usleep(1000);
+ }
+
+ return 0;
+}
-----------------------------------------------------------------------
Summary of changes:
.../{GP_InputDriverSDL.h => GP_InputDriverLinux.h} | 40 +++-
libs/input/GP_InputDriverLinux.c | 255 ++++++++++++++++++++
.../GP_Loaders.h => tests/drivers/linux_input.c | 52 +++--
3 files changed, 324 insertions(+), 23 deletions(-)
copy include/input/{GP_InputDriverSDL.h => GP_InputDriverLinux.h} (71%)
create mode 100644 libs/input/GP_InputDriverLinux.c
copy include/loaders/GP_Loaders.h => tests/drivers/linux_input.c (74%)
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