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 pywrap updated: ce520ce10439ac3e63d5819e136ee623d5531206
by gavento 26 Nov '11
by gavento 26 Nov '11
26 Nov '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, pywrap has been updated
via ce520ce10439ac3e63d5819e136ee623d5531206 (commit)
via 7a8c83f1ad322edbb2043c40fe8d653cdad0a881 (commit)
via ac154bd7aed285ba0abd85c0ba30ffe6d913b0b9 (commit)
from 5827000a1971b8ffd2a91f01bbd65da6e4779e9e (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/ce520ce10439ac3e63d5819e136ee623d553…
commit ce520ce10439ac3e63d5819e136ee623d5531206
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Nov 26 23:52:44 2011 +0100
Fix abort message buffer size
Forgotten at 24 bytes from testing
diff --git a/include/core/GP_Common.h b/include/core/GP_Common.h
index 14eee71..0b96897 100644
--- a/include/core/GP_Common.h
+++ b/include/core/GP_Common.h
@@ -83,7 +83,7 @@
void SWIG_exception(const char *msg);
-#define GP_INTERNAL_ABORT_BUFSIZE 24
+#define GP_INTERNAL_ABORT_BUFSIZE 1024
#define GP_INTERNAL_ABORT(str_abort_msg_, ...) do { char bufstart[GP_INTERNAL_ABORT_BUFSIZE], *buf = bufstart; char *bufend = buf + GP_INTERNAL_ABORT_BUFSIZE;
http://repo.or.cz/w/gfxprim.git/commit/7a8c83f1ad322edbb2043c40fe8d653cdad0…
commit 7a8c83f1ad322edbb2043c40fe8d653cdad0a881
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Nov 26 23:51:24 2011 +0100
Add macro to check for valid PixelType
.. and use it instead of GP_PIXEL_MAX
diff --git a/include/core/GP_Pixel.h b/include/core/GP_Pixel.h
index 2b06cee..294c022 100644
--- a/include/core/GP_Pixel.h
+++ b/include/core/GP_Pixel.h
@@ -117,13 +117,16 @@ typedef struct {
extern const GP_PixelTypeDescription const GP_PixelTypes[];
+#define GP_CHECK_VALID_PIXELTYPE(type) + GP_CHECK(((type) > 0) && ((type) < GP_PIXEL_MAX), "Invalid PixelType %d", (type))
+
/*
* Convert pixel type to name.
*/
static inline const char *GP_PixelTypeName(GP_PixelType type)
{
- GP_CHECK(type < GP_PIXEL_MAX);
+ GP_CHECK_VALID_PIXELTYPE(type);
return GP_PixelTypes[type].name;
}
@@ -133,7 +136,7 @@ static inline const char *GP_PixelTypeName(GP_PixelType type)
static inline uint32_t GP_PixelSize(GP_PixelType type)
{
- GP_CHECK(type < GP_PIXEL_MAX);
+ GP_CHECK_VALID_PIXELTYPE(type);
return GP_PixelTypes[type].size;
}
diff --git a/libs/core/GP_Context.c b/libs/core/GP_Context.c
index 73e926e..48c3315 100644
--- a/libs/core/GP_Context.c
+++ b/libs/core/GP_Context.c
@@ -72,6 +72,7 @@ GP_Context *GP_ContextCopy(const GP_Context *src, int flag)
GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type)
{
+ GP_CHECK_VALID_PIXELTYPE(type);
GP_Context *context = malloc(sizeof(GP_Context));
uint32_t bpp = GP_PixelSize(type);
uint32_t bpr = (bpp * w) / 8 + !!((bpp * w) % 8);
http://repo.or.cz/w/gfxprim.git/commit/ac154bd7aed285ba0abd85c0ba30ffe6d913…
commit ac154bd7aed285ba0abd85c0ba30ffe6d913b0b9
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Nov 26 23:32:06 2011 +0100
Remove forgotten debug messages
diff --git a/pylib/context.py b/pylib/context.py
index e7c8c41..d65008a 100644
--- a/pylib/context.py
+++ b/pylib/context.py
@@ -70,10 +70,7 @@ def extend_context_class(_context_class = core.Context):
"""Converts context to a different pixel type, allocates new context.
See GP_ContextConvert() for details."""
pixeltype_no = target_type ## TODO also accept PixelType
- print "A1"
- c = core.GP_ContextConvert(self, pixeltype_no)
- print "A2"
- return c
+ return core.GP_ContextConvert(self, pixeltype_no)
@extend(_context_class)
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_Common.h | 2 +-
include/core/GP_Pixel.h | 7 +++++--
libs/core/GP_Context.c | 1 +
pylib/context.py | 5 +----
4 files changed, 8 insertions(+), 7 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 master updated: 5cdba1dbc960776f21bdd7e9a07a4546ad918ea3
by gavento 26 Nov '11
by gavento 26 Nov '11
26 Nov '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, master has been updated
via 5cdba1dbc960776f21bdd7e9a07a4546ad918ea3 (commit)
via 86f0ef66d88f47ebb9ac8b9a1a30a83e3b449d2b (commit)
from eb0fe417461ded37e79ffa76e90cedf1b39af555 (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/5cdba1dbc960776f21bdd7e9a07a4546ad91…
commit 5cdba1dbc960776f21bdd7e9a07a4546ad918ea3
Merge: 86f0ef6 eb0fe41
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Nov 26 23:31:25 2011 +0100
Merge branch 'master' of git://repo.or.cz/gfxprim
http://repo.or.cz/w/gfxprim.git/commit/86f0ef66d88f47ebb9ac8b9a1a30a83e3b44…
commit 86f0ef66d88f47ebb9ac8b9a1a30a83e3b449d2b
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Nov 26 23:24:11 2011 +0100
Fix GP_ContextConvert
... a little, still not ideal, but IMO not worth it
diff --git a/libs/core/GP_Context.c b/libs/core/GP_Context.c
index 7079901..73e926e 100644
--- a/libs/core/GP_Context.c
+++ b/libs/core/GP_Context.c
@@ -110,11 +110,13 @@ GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type)
GP_Context *GP_ContextConvert(const GP_Context *src,
GP_PixelType dst_pixel_type)
{
- GP_Context *ret = GP_ContextAlloc(src->w, src->h, dst_pixel_type);
+ int w = GP_ContextW(src);
+ int h = GP_ContextH(src);
+ GP_Context *ret = GP_ContextAlloc(w, h, dst_pixel_type);
if (ret == NULL)
return NULL;
- GP_Blit_Naive(src, 0, 0, src->w, src->h, ret, 0, 0);
+ GP_Blit(src, 0, 0, w, h, ret, 0, 0);
return ret;
}
-----------------------------------------------------------------------
Summary of changes:
libs/core/GP_Context.c | 6 ++++--
1 files changed, 4 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 pywrap updated: 5827000a1971b8ffd2a91f01bbd65da6e4779e9e
by gavento 26 Nov '11
by gavento 26 Nov '11
26 Nov '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, pywrap has been updated
via 5827000a1971b8ffd2a91f01bbd65da6e4779e9e (commit)
via ab8476d63945f607819a2e3b2fdd998f90fb8fb7 (commit)
via 0c4bfea569c5fc142b2b2dfe88eae6fb1af1bb4c (commit)
via 79c70696f823e96d2c85d07035fefc109f62db7d (commit)
via cc5f16de4ff693a60f55a5b335367b3a8ffd3a40 (commit)
via 4a0d49ee3217ef629843a671587ae0e4c1659564 (commit)
via 268e020540d7c79ee472d75c1f959228f419b82b (commit)
via cac343079cd56a28eac9e54ca3ab4aeee3fba683 (commit)
via 5e645909989e30e94ffe9eacf2177f441d44c2d6 (commit)
via 9655adbc1de7cf63dd3510bb57f6fec95248c010 (commit)
via 761929b143cb585ace1dd3c97cbe2f6be2952b80 (commit)
via a21a7b420ab39c6c833aa878898295f61978c909 (commit)
from d028c5b88bfbe818f650dac41671b7dc74fab584 (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/5827000a1971b8ffd2a91f01bbd65da6e477…
commit 5827000a1971b8ffd2a91f01bbd65da6e4779e9e
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Nov 26 23:27:00 2011 +0100
Add convert and copy methods to Context (python)
diff --git a/pylib/context.py b/pylib/context.py
index 03187a7..e7c8c41 100644
--- a/pylib/context.py
+++ b/pylib/context.py
@@ -60,6 +60,23 @@ def extend_context_class(_context_class = core.Context):
return c
@extend(_context_class)
+ def copy(self, withdata):
+ "Copy the context to a new context. Pixel data are copie optionally."
+ flags = core.GP_COPY_WITH_PIXELS if withdata else 0
+ return core.GP_ContextCopy(self, flags)
+
+ @extend(_context_class)
+ def convert(self, target_type):
+ """Converts context to a different pixel type, allocates new context.
+ See GP_ContextConvert() for details."""
+ pixeltype_no = target_type ## TODO also accept PixelType
+ print "A1"
+ c = core.GP_ContextConvert(self, pixeltype_no)
+ print "A2"
+ return c
+
+
+ @extend(_context_class)
def save(self, filename, format=None):
"""Save the image in given format (or guess it from the extension)
http://repo.or.cz/w/gfxprim.git/commit/ab8476d63945f607819a2e3b2fdd998f90fb…
commit ab8476d63945f607819a2e3b2fdd998f90fb8fb7
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Nov 26 23:25:46 2011 +0100
Move setting new GP_Context ownership to SWIG
For several context-allocating functions in GP_Context.c
diff --git a/include/core/gfxprim_core.swig b/include/core/gfxprim_core.swig
index 4cdb160..d497c8f 100644
--- a/include/core/gfxprim_core.swig
+++ b/include/core/gfxprim_core.swig
@@ -80,8 +80,6 @@ GP_Context memory allocation is handled by gfxprim, deallocation by GP_ContextFr
The wrapper can be used without owning the GP_Context struct by setting self.this
and self.thisown.") GP_Context;
-%include "GP_Context.h"
-
%extend GP_Context {
~GP_Context() {
GP_DEBUG(2, "[wrapper] GP_ContextFree (%dx%d raw, %dbpp, free_pixels:%d)",
@@ -90,6 +88,14 @@ and self.thisown.") GP_Context;
}
};
+/* Indicate new wrapper-owned GP_Context */
+%newobject GP_ContextAlloc;
+%newobject GP_ContextCopy;
+%newobject GP_ContextSubContext;
+%newobject GP_ContextConvert;
+
+%include "GP_Context.h"
+
/*
* Context manipulation
diff --git a/pylib/context.py b/pylib/context.py
index 1837b23..03187a7 100644
--- a/pylib/context.py
+++ b/pylib/context.py
@@ -56,7 +56,6 @@ def extend_context_class(_context_class = core.Context):
def subcontext(self, x, y, w, h):
"Create a subcontext (rectangular view)."
c = core.GP_ContextSubContext(self, None, x, y, w, h)
- c.thisown = True # GP_Context IS owned (but not the pixel data)
c.parent = self
return c
@@ -93,7 +92,6 @@ def extend_context_class(_context_class = core.Context):
pixeltype_no = pixeltype if isinstance(pixeltype, int) else 0 # !!!
# TODO: actually accept a PixelType
c = core.GP_ContextAlloc(w, h, pixeltype_no)
- c.thisown = True
return c
@extend(_context_class, name='load')
@@ -101,7 +99,6 @@ def extend_context_class(_context_class = core.Context):
def load(filename):
"Load image from given file, guess type."
c = loaders.GP_LoadImage_SWIG(filename)
- c.thisown = True
return c
http://repo.or.cz/w/gfxprim.git/commit/0c4bfea569c5fc142b2b2dfe88eae6fb1af1…
commit 0c4bfea569c5fc142b2b2dfe88eae6fb1af1bb4c
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Nov 26 23:24:11 2011 +0100
Fix GP_ContextConvert
... a little, still not ideal, but IMO not worth it
diff --git a/libs/core/GP_Context.c b/libs/core/GP_Context.c
index 7079901..73e926e 100644
--- a/libs/core/GP_Context.c
+++ b/libs/core/GP_Context.c
@@ -110,11 +110,13 @@ GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type)
GP_Context *GP_ContextConvert(const GP_Context *src,
GP_PixelType dst_pixel_type)
{
- GP_Context *ret = GP_ContextAlloc(src->w, src->h, dst_pixel_type);
+ int w = GP_ContextW(src);
+ int h = GP_ContextH(src);
+ GP_Context *ret = GP_ContextAlloc(w, h, dst_pixel_type);
if (ret == NULL)
return NULL;
- GP_Blit_Naive(src, 0, 0, src->w, src->h, ret, 0, 0);
+ GP_Blit(src, 0, 0, w, h, ret, 0, 0);
return ret;
}
http://repo.or.cz/w/gfxprim.git/commit/79c70696f823e96d2c85d07035fefc109f62…
commit 79c70696f823e96d2c85d07035fefc109f62db7d
Merge: d028c5b cc5f16d
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Nov 26 21:48:44 2011 +0100
Merge branch 'master' of git://repo.or.cz/gfxprim into pywrap
-----------------------------------------------------------------------
Summary of changes:
demos/fbshow/fbshow.c | 158 ++++++++++++++++++++++------
demos/grinder/grinder.c | 4 +-
doc/context.txt | 4 +-
include/core/GP_Context.h | 7 +-
include/core/gfxprim_core.swig | 10 ++-
include/filters/GP_FilterParam.h | 25 +++++
include/filters/GP_Resize.h | 5 +-
include/text/GP_Font.h | 8 +-
include/text/GP_Text.h | 56 +++++++---
include/text/GP_TextMetric.h | 29 +++---
include/text/GP_TextStyle.h | 6 +-
libs/core/GP_Context.c | 23 ++---
libs/filters/GP_FilterParam.c | 32 ++++++
libs/filters/GP_Resize.c | 174 ++++++++++++++++++++++++++++---
libs/text/GP_Text.c | 215 ++++++++++++++++++--------------------
pylib/context.py | 20 +++-
pylib/templates/filter.point.c.t | 2 +-
tests/SDL/blittest.c | 5 +-
tests/SDL/fileview.c | 3 +-
tests/SDL/fonttest.c | 13 ++-
tests/SDL/input.c | 20 +++-
tests/SDL/shapetest.c | 2 +-
tests/SDL/showimage.c | 7 +-
tests/SDL/subcontext.c | 2 +-
tests/SDL/textaligntest.c | 12 +-
tests/drivers/framebuffer_test.c | 4 +-
26 files changed, 595 insertions(+), 251 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 master updated: eb0fe417461ded37e79ffa76e90cedf1b39af555
by metan 26 Nov '11
by metan 26 Nov '11
26 Nov '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, master has been updated
via eb0fe417461ded37e79ffa76e90cedf1b39af555 (commit)
from cc5f16de4ff693a60f55a5b335367b3a8ffd3a40 (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/eb0fe417461ded37e79ffa76e90cedf1b39a…
commit eb0fe417461ded37e79ffa76e90cedf1b39af555
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Nov 26 23:23:35 2011 +0100
fbshow: Switch to bicubic integer implementation.
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index 4510312..3943ffc 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -155,12 +155,12 @@ static void *image_loader(void *ptr)
GP_Context *ret;
- callback.priv = "Blurring Image";
- if (GP_FilterGaussianBlur(img, img, 0.3/rat, 0.3/rat, &callback) == NULL)
- return NULL;
+// callback.priv = "Blurring Image";
+// if (GP_FilterGaussianBlur(img, img, 0.3/rat, 0.3/rat, &callback) == NULL)
+// return NULL;
callback.priv = "Resampling Image";
- ret = GP_FilterResize(img, NULL, GP_INTERP_CUBIC, img->w * rat, img->h * rat, &callback);
+ ret = GP_FilterResize(img, NULL, GP_INTERP_CUBIC_INT, img->w * rat, img->h * rat, &callback);
GP_ContextFree(img);
if (ret == NULL)
-----------------------------------------------------------------------
Summary of changes:
demos/fbshow/fbshow.c | 8 ++++----
1 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 master updated: cc5f16de4ff693a60f55a5b335367b3a8ffd3a40
by gavento 26 Nov '11
by gavento 26 Nov '11
26 Nov '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, master has been updated
via cc5f16de4ff693a60f55a5b335367b3a8ffd3a40 (commit)
via 4a0d49ee3217ef629843a671587ae0e4c1659564 (commit)
from 268e020540d7c79ee472d75c1f959228f419b82b (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/cc5f16de4ff693a60f55a5b335367b3a8ffd…
commit cc5f16de4ff693a60f55a5b335367b3a8ffd3a40
Merge: 4a0d49e 268e020
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Nov 26 21:38:16 2011 +0100
Merge branch 'master' of git://repo.or.cz/gfxprim
diff --cc demos/fbshow/fbshow.c
index ead85bf,8c1a2e7..4510312
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@@ -109,9 -143,12 +143,12 @@@ static void *image_loader(void *ptr
float rat = calc_img_size(img->w, img->h, w, h);
+ w = img->w;
+ h = img->h;
+
/* Workaround */
if (img->pixel_type != GP_PIXEL_RGB888) {
- GP_Context *tmp = GP_ContextConvert(img, NULL, GP_PIXEL_RGB888);
+ GP_Context *tmp = GP_ContextConvert(img, GP_PIXEL_RGB888);
GP_ContextFree(img);
img = tmp;
}
http://repo.or.cz/w/gfxprim.git/commit/4a0d49ee3217ef629843a671587ae0e4c165…
commit 4a0d49ee3217ef629843a671587ae0e4c1659564
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Nov 26 21:29:11 2011 +0100
Neuter GP_ContextConvert (always alloc)
Make GP_ContextConvert always allocate a new GP_Context
* Consistent allocation behavior (=> less leaks)
* The other variant is just a blit (make another wrapper if required)
* Easier wrapping
Note: the variant was buggy anyway (direct use of context->w)
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index bf18f3f..ead85bf 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -111,7 +111,7 @@ static void *image_loader(void *ptr)
/* Workaround */
if (img->pixel_type != GP_PIXEL_RGB888) {
- GP_Context *tmp = GP_ContextConvert(img, NULL, GP_PIXEL_RGB888);
+ GP_Context *tmp = GP_ContextConvert(img, GP_PIXEL_RGB888);
GP_ContextFree(img);
img = tmp;
}
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index 2a9ec43..2defb20 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -443,7 +443,7 @@ static GP_RetCode dither(GP_Context **c, const char *params)
//TODO: so far we convert the context back to RGB888
//(so we can do further work with it)
- GP_ContextConvert(bw, *c, (*c)->pixel_type);
+ GP_Blit(bw, 0, 0, GP_ContextW(bw), GP_ContextH(bw), *c, 0, 0);
GP_ContextFree(bw);
diff --git a/doc/context.txt b/doc/context.txt
index 2e102f1..a98d21a 100644
--- a/doc/context.txt
+++ b/doc/context.txt
@@ -147,8 +147,8 @@ GP_Context *GP_ContextConvert(const GP_Context *src, GP_Context *dst,
GP_PixelType dst_pixel_type);
-------------------------------------------------------------------------------
-This provides basic context conversion functionality. If 'NULL' is passed as
-dst, the context for result is allocated and returned.
+Provides basic context conversion functionality.
+A newly allocated context is returned.
This fuction does no error distribution but only integer
division/multiplication for each pixel channel.
diff --git a/include/core/GP_Context.h b/include/core/GP_Context.h
index cbe3742..664f15b 100644
--- a/include/core/GP_Context.h
+++ b/include/core/GP_Context.h
@@ -115,16 +115,19 @@ GP_Context *GP_ContextSubContext(GP_Context *context, GP_Context *subcontext,
GP_Coord x, GP_Coord y, GP_Size w, GP_Size h);
/*
- * Converts context to different pixel type.
+ * Converts context to a different pixel type.
+ * Returns a newly allocated context.
*
* This is naive implementation that doesn't do any ditherings or error
* diffusions.
*/
-GP_Context *GP_ContextConvert(const GP_Context *src, GP_Context *dst,
+GP_Context *GP_ContextConvert(const GP_Context *src,
GP_PixelType dst_pixel_type);
/*
* Free context.
+ *
+ * If context->free_pixels, also free pixel data.
*/
void GP_ContextFree(GP_Context *context);
diff --git a/libs/core/GP_Context.c b/libs/core/GP_Context.c
index 23ae77b..7079901 100644
--- a/libs/core/GP_Context.c
+++ b/libs/core/GP_Context.c
@@ -107,25 +107,14 @@ GP_Context *GP_ContextAlloc(GP_Size w, GP_Size h, GP_PixelType type)
return context;
}
-GP_Context *GP_ContextConvert(const GP_Context *src, GP_Context *dst,
+GP_Context *GP_ContextConvert(const GP_Context *src,
GP_PixelType dst_pixel_type)
{
- GP_Context *ret = dst;
-
- if (ret == NULL) {
- ret = GP_ContextAlloc(src->w, src->h, dst_pixel_type);
-
- if (ret == NULL)
- return NULL;
- } else {
- GP_ASSERT(dst->pixel_type == dst_pixel_type,
- "Destination pixel type doesn't match");
- GP_ASSERT(src->w <= dst->w && src->h <= dst->h,
- "Destination is not big enough");
- }
+ GP_Context *ret = GP_ContextAlloc(src->w, src->h, dst_pixel_type);
+ if (ret == NULL)
+ return NULL;
GP_Blit_Naive(src, 0, 0, src->w, src->h, ret, 0, 0);
-
return ret;
}
diff --git a/tests/SDL/blittest.c b/tests/SDL/blittest.c
index 1a4ed83..be39c83 100644
--- a/tests/SDL/blittest.c
+++ b/tests/SDL/blittest.c
@@ -184,7 +184,7 @@ int main(int argc, char *argv[])
GP_SDL_ContextFromSurface(&context, display);
- bitmap_conv = GP_ContextConvert(bitmap_raw, NULL, context.pixel_type);
+ bitmap_conv = GP_ContextConvert(bitmap_raw, context.pixel_type);
change_bitmap();
black = GP_ColorToContextPixel(GP_COL_BLACK, &context);
-----------------------------------------------------------------------
Summary of changes:
demos/fbshow/fbshow.c | 2 +-
demos/grinder/grinder.c | 2 +-
doc/context.txt | 4 ++--
include/core/GP_Context.h | 7 +++++--
libs/core/GP_Context.c | 19 ++++---------------
tests/SDL/blittest.c | 2 +-
6 files changed, 14 insertions(+), 22 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 master updated: 268e020540d7c79ee472d75c1f959228f419b82b
by metan 26 Nov '11
by metan 26 Nov '11
26 Nov '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, master has been updated
via 268e020540d7c79ee472d75c1f959228f419b82b (commit)
from cac343079cd56a28eac9e54ca3ab4aeee3fba683 (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/268e020540d7c79ee472d75c1f959228f419…
commit 268e020540d7c79ee472d75c1f959228f419b82b
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Nov 26 21:10:09 2011 +0100
filters: Fixed and edhanced bicubic interpolation.
* Fixed the filter so it's stable
(the image looks same after number of 1:1 interpolations)
* Added integer version of the filter
- slightly faster on PC, expected to rock on ARM
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index 27af5e3..8c1a2e7 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -155,9 +155,9 @@ static void *image_loader(void *ptr)
GP_Context *ret;
- //callback.priv = "Blurring Image";
- //if (GP_FilterGaussianBlur(img, img, 0.25/rat, 0.25/rat, &callback) == NULL)
- // return NULL;
+ callback.priv = "Blurring Image";
+ if (GP_FilterGaussianBlur(img, img, 0.3/rat, 0.3/rat, &callback) == NULL)
+ return NULL;
callback.priv = "Resampling Image";
ret = GP_FilterResize(img, NULL, GP_INTERP_CUBIC, img->w * rat, img->h * rat, &callback);
diff --git a/demos/grinder/grinder.c b/demos/grinder/grinder.c
index 2a9ec43..09081c7 100644
--- a/demos/grinder/grinder.c
+++ b/demos/grinder/grinder.c
@@ -81,6 +81,7 @@ static void print_error(const char *error)
static const char *resize_algs[] = {
"nn",
"cubic",
+ "cubic-int",
NULL
};
@@ -135,6 +136,7 @@ static GP_RetCode resize(GP_Context **c, const char *params)
static const char *scale_algs[] = {
"nn",
"cubic",
+ "cubic-int",
NULL
};
diff --git a/include/filters/GP_Resize.h b/include/filters/GP_Resize.h
index 692339c..fcae054 100644
--- a/include/filters/GP_Resize.h
+++ b/include/filters/GP_Resize.h
@@ -47,8 +47,9 @@
#include "GP_Filter.h"
typedef enum GP_InterpolationType {
- GP_INTERP_NN, /* Nearest Neighbour */
- GP_INTERP_CUBIC, /* Bicubic */
+ GP_INTERP_NN, /* Nearest Neighbour */
+ GP_INTERP_CUBIC, /* Bicubic */
+ GP_INTERP_CUBIC_INT, /* Bicubic - integer arithmetics */
} GP_InterpolationType;
/*
diff --git a/libs/filters/GP_Resize.c b/libs/filters/GP_Resize.c
index baf7db5..ac5ea0d 100644
--- a/libs/filters/GP_Resize.c
+++ b/libs/filters/GP_Resize.c
@@ -103,21 +103,21 @@ int GP_FilterInterpolate_Cubic(const GP_Context *src, GP_Context *dst,
1.00 * dst->w / src->w, 1.00 * dst->h / src->h);
for (i = 0; i < dst->w; i++) {
- float x = (1.00 * i / dst->w) * (src->w - 4.5) + 2.5;
+ float x = (1.00 * i / dst->w) * src->w;
v4f cvx;
int xi = x - 1;
-
- cvx.f[0] = cubic(x - xi);
- cvx.f[1] = cubic(x - xi - 1);
- cvx.f[2] = cubic(x - xi - 2);
- cvx.f[3] = cubic(x - xi - 3);
if (xi < 0)
xi = 0;
if (xi > (int)src->w - 4)
xi = src->w - 4;
-
+
+ cvx.f[0] = cubic(x - xi);
+ cvx.f[1] = cubic(x - xi - 1);
+ cvx.f[2] = cubic(x - xi - 2);
+ cvx.f[3] = cubic(x - xi - 3);
+
/* Generate interpolated column */
for (j = 0; j < src->h; j++) {
v4f rv, gv, bv;
@@ -154,22 +154,22 @@ int GP_FilterInterpolate_Cubic(const GP_Context *src, GP_Context *dst,
/* now interpolate column for new image */
for (j = 0; j < dst->h; j++) {
- float y = (1.00 * j / dst->h) * (src->h - 4.5) + 2.5;
+ float y = (1.00 * j / dst->h) * src->h;
v4f cvy, rv, gv, bv;
float r, g, b;
- int yi = y - 1;
+ int yi = y;
- cvy.f[0] = cubic(y - yi);
- cvy.f[1] = cubic(y - yi - 1);
- cvy.f[2] = cubic(y - yi - 2);
- cvy.f[3] = cubic(y - yi - 3);
-
if (yi < 0)
yi = 0;
if (yi > (int)src->h - 4)
yi = src->h - 4;
+ cvy.f[0] = cubic(y - yi);
+ cvy.f[1] = cubic(y - yi - 1);
+ cvy.f[2] = cubic(y - yi - 2);
+ cvy.f[3] = cubic(y - yi - 3);
+
rv.f[0] = col_r[yi];
rv.f[1] = col_r[yi + 1];
rv.f[2] = col_r[yi + 2];
@@ -223,6 +223,150 @@ int GP_FilterInterpolate_Cubic(const GP_Context *src, GP_Context *dst,
return 0;
}
+#define MUL 2048
+
+#define MUL_I(a, b) ({ + a[0] *= b[0]; + a[1] *= b[1]; + a[2] *= b[2]; + a[3] *= b[3]; +})
+
+#define SUM_I(a) + ((a)[0] + (a)[1] + (a)[2] + (a)[3])
+
+int GP_FilterInterpolate_CubicInt(const GP_Context *src, GP_Context *dst,
+ GP_ProgressCallback *callback)
+{
+ int32_t col_r[src->h], col_g[src->h], col_b[src->h];
+ uint32_t i, j;
+
+ GP_DEBUG(1, "Scaling image %ux%u -> %ux%u %2.2f %2.2f",
+ src->w, src->h, dst->w, dst->h,
+ 1.00 * dst->w / src->w, 1.00 * dst->h / src->h);
+
+ for (i = 0; i < dst->w; i++) {
+ float x = (1.00 * i / dst->w) * src->w;
+ int32_t cvx[4];
+ int xi = x - 1;
+
+ if (xi < 0)
+ xi = 0;
+
+ if (xi > (int)src->w - 4)
+ xi = src->w - 4;
+
+ cvx[0] = cubic(x - xi) * MUL + 0.5;
+ cvx[1] = cubic(x - xi - 1) * MUL + 0.5;
+ cvx[2] = cubic(x - xi - 2) * MUL + 0.5;
+ cvx[3] = cubic(x - xi - 3) * MUL + 0.5;
+
+ /* Generate interpolated column */
+ for (j = 0; j < src->h; j++) {
+ int32_t rv[4], gv[4], bv[4];
+ GP_Pixel pix[4];
+
+ pix[0] = GP_GetPixel_Raw_24BPP(src, xi, j);
+ pix[1] = GP_GetPixel_Raw_24BPP(src, xi + 1, j);
+ pix[2] = GP_GetPixel_Raw_24BPP(src, xi + 2, j);
+ pix[3] = GP_GetPixel_Raw_24BPP(src, xi + 3, j);
+
+ rv[0] = GP_Pixel_GET_R_RGB888(pix[0]);
+ rv[1] = GP_Pixel_GET_R_RGB888(pix[1]);
+ rv[2] = GP_Pixel_GET_R_RGB888(pix[2]);
+ rv[3] = GP_Pixel_GET_R_RGB888(pix[3]);
+
+ gv[0] = GP_Pixel_GET_G_RGB888(pix[0]);
+ gv[1] = GP_Pixel_GET_G_RGB888(pix[1]);
+ gv[2] = GP_Pixel_GET_G_RGB888(pix[2]);
+ gv[3] = GP_Pixel_GET_G_RGB888(pix[3]);
+
+ bv[0] = GP_Pixel_GET_B_RGB888(pix[0]);
+ bv[1] = GP_Pixel_GET_B_RGB888(pix[1]);
+ bv[2] = GP_Pixel_GET_B_RGB888(pix[2]);
+ bv[3] = GP_Pixel_GET_B_RGB888(pix[3]);
+
+ MUL_I(rv, cvx);
+ MUL_I(gv, cvx);
+ MUL_I(bv, cvx);
+
+ col_r[j] = SUM_I(rv);
+ col_g[j] = SUM_I(gv);
+ col_b[j] = SUM_I(bv);
+ }
+
+ /* now interpolate column for new image */
+ for (j = 0; j < dst->h; j++) {
+ float y = (1.00 * j / dst->h) * src->h;
+ int32_t cvy[4], rv[4], gv[4], bv[4];
+ int32_t r, g, b;
+ int yi = y - 1;
+
+ if (yi < 0)
+ yi = 0;
+
+ if (yi > (int)src->h - 4)
+ yi = src->h - 4;
+
+ cvy[0] = cubic(y - yi) * MUL + 0.5;
+ cvy[1] = cubic(y - yi - 1) * MUL + 0.5;
+ cvy[2] = cubic(y - yi - 2) * MUL + 0.5;
+ cvy[3] = cubic(y - yi - 3) * MUL + 0.5;
+
+ rv[0] = col_r[yi];
+ rv[1] = col_r[yi + 1];
+ rv[2] = col_r[yi + 2];
+ rv[3] = col_r[yi + 3];
+
+ gv[0] = col_g[yi];
+ gv[1] = col_g[yi + 1];
+ gv[2] = col_g[yi + 2];
+ gv[3] = col_g[yi + 3];
+
+ bv[0] = col_b[yi];
+ bv[1] = col_b[yi + 1];
+ bv[2] = col_b[yi + 2];
+ bv[3] = col_b[yi + 3];
+
+ MUL_I(rv, cvy);
+ MUL_I(gv, cvy);
+ MUL_I(bv, cvy);
+
+ r = (SUM_I(rv) + MUL*MUL/2) / MUL / MUL;
+ g = (SUM_I(gv) + MUL*MUL/2) / MUL / MUL;
+ b = (SUM_I(bv) + MUL*MUL/2) / MUL / MUL;
+
+ if (r > 255)
+ r = 255;
+
+ if (r < 0)
+ r = 0;
+
+ if (g > 255)
+ g = 255;
+
+ if (g < 0)
+ g = 0;
+
+ if (b > 255)
+ b = 255;
+
+ if (b < 0)
+ b = 0;
+
+ GP_Pixel pix = GP_Pixel_CREATE_RGB888((uint8_t)r, (uint8_t)g, (uint8_t)b);
+ GP_PutPixel_Raw_24BPP(dst, i, j, pix);
+ }
+
+ if (GP_ProgressCallbackReport(callback, i, dst->w, dst->h))
+ return 1;
+ }
+
+ GP_ProgressCallbackDone(callback);
+ return 0;
+}
+
+
int GP_FilterResize_Raw(const GP_Context *src, GP_Context *dst,
GP_InterpolationType type,
GP_ProgressCallback *callback)
@@ -232,6 +376,8 @@ int GP_FilterResize_Raw(const GP_Context *src, GP_Context *dst,
return GP_FilterInterpolate_NN(src, dst, callback);
case GP_INTERP_CUBIC:
return GP_FilterInterpolate_Cubic(src, dst, callback);
+ case GP_INTERP_CUBIC_INT:
+ return GP_FilterInterpolate_CubicInt(src, dst, callback);
}
return 1;
-----------------------------------------------------------------------
Summary of changes:
demos/fbshow/fbshow.c | 6 +-
demos/grinder/grinder.c | 2 +
include/filters/GP_Resize.h | 5 +-
libs/filters/GP_Resize.c | 174 +++++++++++++++++++++++++++++++++++++++----
4 files changed, 168 insertions(+), 19 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 pywrap updated: d028c5b88bfbe818f650dac41671b7dc74fab584
by gavento 26 Nov '11
by gavento 26 Nov '11
26 Nov '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, pywrap has been updated
via d028c5b88bfbe818f650dac41671b7dc74fab584 (commit)
via 133b310ce8ca4adc61f14648dee634a00d5cf077 (commit)
via 75272ddef49127d165aa2e041fcb49f5bdf437dd (commit)
via 3428c6433249fc771dc355438cd47d7d3abfd70d (commit)
via 116c09aa2a1efd689e4c2a66ad11d55988374983 (commit)
from 9fb8ec2881f24724d6fe71bbfecb7524e95053a7 (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/d028c5b88bfbe818f650dac41671b7dc74fa…
commit d028c5b88bfbe818f650dac41671b7dc74fab584
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Nov 26 20:28:53 2011 +0100
Update and move GP_Context wrapper docstring
diff --git a/include/core/gfxprim_core.swig b/include/core/gfxprim_core.swig
index 366067c..4cdb160 100644
--- a/include/core/gfxprim_core.swig
+++ b/include/core/gfxprim_core.swig
@@ -44,12 +44,10 @@
/*
- * Context manipulation
+ * GP_Context wrapping
*/
-/* Rename accestors to GP_Context attributes to _attribute */
-/* would work in swig 2.0:
- * %rename("_%s", regexmatch$name="^GP_Context::") ""; */
+/* Rename accesors to GP_Context attributes to "_attribute" */
%rename("_%s") "GP_Context::pixels";
%rename("_%s") "GP_Context::bpp";
%rename("_%s") "GP_Context::bytes_per_row";
@@ -62,8 +60,26 @@
%rename("_%s") "GP_Context::y_swap";
%rename("_%s") "GP_Context::bit_endian";
%rename("_%s") "GP_Context::free_pixels";
+/* This nice batch would work in swig 2.0, sigh:
+ * %rename("_%s", regexmatch$name="^GP_Context::") ""; */
+
%rename("Context") "GP_Context";
+%feature("autodoc", "Proxy of C GP_Context struct
+
+You can pass this class to wrapped GP_DrawSomething(...) as GP_Context.
+All attributes of GP_Context are accessible directly as _attribute
+(self._w etc.), but it is reccomended to use redefined properties:
+
+self.w: Context width (transformed)
+self.h: Context width (transformed)
+
+Some context-related methods are provided as class members for convenience.
+
+GP_Context memory allocation is handled by gfxprim, deallocation by GP_ContextFree().
+The wrapper can be used without owning the GP_Context struct by setting self.this
+and self.thisown.") GP_Context;
+
%include "GP_Context.h"
%extend GP_Context {
@@ -74,6 +90,11 @@
}
};
+
+/*
+ * Context manipulation
+ */
+
%include "GP_GetPutPixel.h"
%import "GP_GetPutPixel.gen.h"
%include "GP_WritePixel.h"
diff --git a/pylib/context.py b/pylib/context.py
index 32ed123..1837b23 100644
--- a/pylib/context.py
+++ b/pylib/context.py
@@ -33,23 +33,7 @@ def extend_context_class(_context_class = core.Context):
Called on module inicialization.
"""
- type.__setattr__(_context_class, "__doc_2__",
- """Proxy of C GP_Context struct
-
- You can pass this class to wrapped GP_DrawSomething(...) as GP_Context.
- All attributes of GP_Context are accessible directly as "_attribute"
- (self._w etc.), but it is reccomended to use redefined properties:
-
- self.w: Context width (transformed)
- self.h: Context width (transformed)
-
- Some context methods are provided as class members for convenience.
-
- GP_Context memory allocation is handled completely by gfxprim.
- You shoud NEVER even think about self.this - this pointer will point to
- free memory after self.__del__ is called (in case of owned GP_Context).
- """)
-
+ # Add "parent" attribute
extend(_context_class, name='parent')(None)
@extend(_context_class, name='__str__')
http://repo.or.cz/w/gfxprim.git/commit/133b310ce8ca4adc61f14648dee634a00d5c…
commit 133b310ce8ca4adc61f14648dee634a00d5cf077
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Nov 26 20:04:12 2011 +0100
Complete rewrite of the wrapper class
Now extending the SWIG wrapper instead of delegation
Decorating tools
TODO: set docstring correctly
diff --git a/pylib/context.py b/pylib/context.py
index 1551c5c..32ed123 100644
--- a/pylib/context.py
+++ b/pylib/context.py
@@ -1,58 +1,84 @@
import gfxprim_core_c as core
import gfxprim_loaders_c as loaders
-class Context(object):
- def __init__(self, context, owns_GP_Context, parent=None):
- """Create new GP_Context wrapper.
+def extend(cls, name=None):
+ def decf(method):
+ funname = name
+ if not funname:
+ funname = method.__name__
+ type.__setattr__(cls, funname, method)
+ return method
+ return decf
- The wrapper is just a (read-only) proxy with
- some conveniently mapped context methods.
- Direct access is possible through self.context.
- """
- # GP_Context struct (pre-wrapped by SWIG)
- self.context = context
- # call GP_ContextFree on del?
- self.owns_GP_Context = owns_GP_Context
- # Parent Context of a subcontext (if any)
- # It is important to hold a ref to parent because of GC
- self.parent = parent
-
- def __del__(self):
- print "Deleting %s (owns_GP_Context: %s)" % (self, self.owns_GP_Context)
- if self.owns_GP_Context:
- core.GP_ContextFree(self.context)
-
- @property
- def w(self):
- "Context width (transformed)"
- return core.GP_ContextW(self.context)
+def add_swig_getmethod(cls, name=None):
+ def decf(method):
+ propname = name
+ if not propname:
+ propname = method.__name__
+ cls.__swig_getmethods__[propname] = method
+ return decf
- @property
- def h(self):
- "Context height (transformed)"
- return core.GP_ContextH(self.context)
+def add_swig_setmethod(cls, name=None):
+ def decf(method):
+ propname = name
+ if not propname:
+ propname = method.__name__
+ cls.__swig_setmethods__[propname] = method
+ return decf
+
+
+def extend_context_class(_context_class = core.Context):
+ """
+ Extends _context_class class with convenience methods.
+ Called on module inicialization.
+ """
+
+ type.__setattr__(_context_class, "__doc_2__",
+ """Proxy of C GP_Context struct
+
+ You can pass this class to wrapped GP_DrawSomething(...) as GP_Context.
+ All attributes of GP_Context are accessible directly as "_attribute"
+ (self._w etc.), but it is reccomended to use redefined properties:
+
+ self.w: Context width (transformed)
+ self.h: Context width (transformed)
+
+ Some context methods are provided as class members for convenience.
- @property
- def bpp(self):
- "Context bpp"
- return self.context.bpp
+ GP_Context memory allocation is handled completely by gfxprim.
+ You shoud NEVER even think about self.this - this pointer will point to
+ free memory after self.__del__ is called (in case of owned GP_Context).
+ """)
- def __str__(self):
+ extend(_context_class, name='parent')(None)
+
+ @extend(_context_class, name='__str__')
+ @extend(_context_class, name='__repr__')
+ def context_str(self):
return "<Context %dx%d, %dbpp, GP_Context %sowned, %s parent>" % (
- self.w, self.h, self.bpp,
- "" if self.owns_GP_Context else "not ",
- "with" if self.parent else "no")
- __repr__ = __str__
+ self.w, self.h, self._bpp,
+ "" if self.thisown else "not ",
+ "with" if self.parent else "no")
+
+ @add_swig_getmethod(_context_class)
+ def w(self):
+ return core.GP_ContextW(self)
+
+ @add_swig_getmethod(_context_class)
+ def h(self):
+ return core.GP_ContextH(self)
+ @extend(_context_class)
def subcontext(self, x, y, w, h):
"Create a subcontext (rectangular view)."
- c = core.GP_ContextSubContext(self.context, None, x, y, w, h)
- if not c:
- raise Exception("Error creating subcontext")
- return type(self)(c, owns_GP_Context=True, parent=self)
+ c = core.GP_ContextSubContext(self, None, x, y, w, h)
+ c.thisown = True # GP_Context IS owned (but not the pixel data)
+ c.parent = self
+ return c
+ @extend(_context_class)
def save(self, filename, format=None):
- """Save the image in given format (or guess by the extension)
+ """Save the image in given format (or guess it from the extension)
Currently, JPG, PNG and P[BGP]M are supported, but not for all
context pixel types.
@@ -61,34 +87,40 @@ class Context(object):
format = filename.rsplit('.', 1)[-1]
format = format.lower()
if format == 'jpg':
- res = loaders.GP_SaveJPG(filename, self.context, None)
+ res = loaders.GP_SaveJPG(filename, self, None)
elif format == 'png':
- res = loaders.GP_SavePNG(filename, self.context, None)
+ res = loaders.GP_SavePNG(filename, self, None)
elif format == 'pbm':
- res = loaders.GP_SavePBM(filename, self.context, None)
+ res = loaders.GP_SavePBM(filename, self, None)
elif format == 'pgm':
- res = loaders.GP_SavePGM(filename, self.context, None)
+ res = loaders.GP_SavePGM(filename, self, None)
elif format == 'ppm':
- res = loaders.GP_SavePPM(filename, self.context, None)
+ res = loaders.GP_SavePPM(filename, self, None)
else:
raise Exception("Format %r not supported.", format)
if res != 0:
raise Exception("Error saving %r (code %d)", filename, res)
- @classmethod
- def create(cls, w, h, pixeltype):
+ @extend(_context_class, name='create')
+ @staticmethod
+ def create(w, h, pixeltype):
"Allocate a new w*h bitmap of given type."
pixeltype_no = pixeltype if isinstance(pixeltype, int) else 0 # !!!
# TODO: actually accept a PixelType
c = core.GP_ContextAlloc(w, h, pixeltype_no)
- return cls(c, owns_GP_Context=True)
+ c.thisown = True
+ return c
- @classmethod
- def load(cls, filename):
+ @extend(_context_class, name='load')
+ @staticmethod
+ def load(filename):
"Load image from given file, guess type."
c = loaders.GP_LoadImage_SWIG(filename)
- if not c:
- raise Exception("Error loading %r", filename)
- return cls(c, owns_GP_Context=True)
+ c.thisown = True
+ return c
+
+
+
+extend_context_class()
http://repo.or.cz/w/gfxprim.git/commit/75272ddef49127d165aa2e041fcb49f5bdf4…
commit 75272ddef49127d165aa2e041fcb49f5bdf437dd
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Nov 26 20:02:11 2011 +0100
Prepare for (more) direct wrapping of GP_Context
Add autodoc feature
Rename attributes to "_*"
Set GP_Context destructor
diff --git a/include/core/gfxprim_core.swig b/include/core/gfxprim_core.swig
index e9d68d1..366067c 100644
--- a/include/core/gfxprim_core.swig
+++ b/include/core/gfxprim_core.swig
@@ -8,6 +8,8 @@
%include <stdint.i>
+%feature("autodoc");
+
%nodefaultctor;
/*
@@ -45,8 +47,33 @@
* Context manipulation
*/
+/* Rename accestors to GP_Context attributes to _attribute */
+/* would work in swig 2.0:
+ * %rename("_%s", regexmatch$name="^GP_Context::") ""; */
+%rename("_%s") "GP_Context::pixels";
+%rename("_%s") "GP_Context::bpp";
+%rename("_%s") "GP_Context::bytes_per_row";
+%rename("_%s") "GP_Context::w";
+%rename("_%s") "GP_Context::h";
+%rename("_%s") "GP_Context::offset";
+%rename("_%s") "GP_Context::pixel_type";
+%rename("_%s") "GP_Context::axes_swap";
+%rename("_%s") "GP_Context::x_swap";
+%rename("_%s") "GP_Context::y_swap";
+%rename("_%s") "GP_Context::bit_endian";
+%rename("_%s") "GP_Context::free_pixels";
+%rename("Context") "GP_Context";
+
%include "GP_Context.h"
+%extend GP_Context {
+ ~GP_Context() {
+ GP_DEBUG(2, "[wrapper] GP_ContextFree (%dx%d raw, %dbpp, free_pixels:%d)",
+ $self->w, $self->h, $self->bpp, $self->free_pixels);
+ GP_ContextFree($self);
+ }
+};
+
%include "GP_GetPutPixel.h"
%import "GP_GetPutPixel.gen.h"
%include "GP_WritePixel.h"
http://repo.or.cz/w/gfxprim.git/commit/3428c6433249fc771dc355438cd47d7d3abf…
commit 3428c6433249fc771dc355438cd47d7d3abfd70d
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Nov 26 10:39:00 2011 +0100
core SWIG cleanup, removed some internals
diff --git a/include/core/gfxprim_core.swig b/include/core/gfxprim_core.swig
index 2a96a71..e9d68d1 100644
--- a/include/core/gfxprim_core.swig
+++ b/include/core/gfxprim_core.swig
@@ -10,7 +10,9 @@
%nodefaultctor;
-/* Basic types and common methods */
+/*
+ * Basic types and common methods
+ */
%include "GP_Common.h"
%include "GP_Core.h"
@@ -23,23 +25,31 @@
%include "GP_ProgressCallback.h"
%include "GP_RetCode.h"
-/* Color and pixel types */
+
+/*
+ * Color and pixel types
+ */
%include "GP_Color.h"
-%include "GP_Context.h"
%include "GP_Pixel.h"
-%include "GP_Pixel.gen.h"
+%include "GP_Pixel.gen.h" /* Includes enum GP_PixelType definition */
%include "GP_Convert.h"
-%include "GP_Convert.gen.h"
-%include "GP_Convert_Scale.gen.h"
-%include "GP_Blit.gen.h"
+%import "GP_Convert.gen.h"
+%import "GP_Convert_Scale.gen.h"
+
+%import "GP_FnPerBpp.h"
+%import "GP_FnPerBpp.gen.h"
+
-/* Context manipulation */
+/*
+ * Context manipulation
+ */
%include "GP_Context.h"
-%include "GP_Blit.h"
-%include "GP_Blit.gen.h"
-%include "GP_FnPerBpp.h"
+
%include "GP_GetPutPixel.h"
+%import "GP_GetPutPixel.gen.h"
%include "GP_WritePixel.h"
+%include "GP_Blit.h"
+%import "GP_Blit.gen.h"
http://repo.or.cz/w/gfxprim.git/commit/116c09aa2a1efd689e4c2a66ad11d5598837…
commit 116c09aa2a1efd689e4c2a66ad11d55988374983
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Sat Nov 26 10:37:44 2011 +0100
Add GP_WritePixels.h to GP_Core.h
diff --git a/include/core/GP_Core.h b/include/core/GP_Core.h
index 70c2c3f..93ce52b 100644
--- a/include/core/GP_Core.h
+++ b/include/core/GP_Core.h
@@ -50,7 +50,10 @@
/* Individual pixel access */
#include "core/GP_GetPutPixel.h"
-/* blitting */
+/* Writing pixel blocks */
+#include "GP_WritePixel.h"
+
+/* Blitting */
#include "core/GP_Blit.h"
/* Debug and debug level */
-----------------------------------------------------------------------
Summary of changes:
include/core/GP_Core.h | 5 +-
include/core/gfxprim_core.swig | 80 ++++++++++++++++++++++----
pylib/context.py | 126 ++++++++++++++++++++++-----------------
3 files changed, 144 insertions(+), 67 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 master updated: cac343079cd56a28eac9e54ca3ab4aeee3fba683
by metan 26 Nov '11
by metan 26 Nov '11
26 Nov '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, master has been updated
via cac343079cd56a28eac9e54ca3ab4aeee3fba683 (commit)
from 5e645909989e30e94ffe9eacf2177f441d44c2d6 (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/cac343079cd56a28eac9e54ca3ab4aeee3fb…
commit cac343079cd56a28eac9e54ca3ab4aeee3fba683
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Sat Nov 26 01:04:42 2011 +0100
fbshow: Some more work on fbshow.
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index 082c888..27af5e3 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -43,18 +43,43 @@ static GP_Framebuffer *fb = NULL;
/* image loader thread */
static int abort_flag = 0;
static int rotate = 0;
+static int show_progress = 0;
static int image_loader_callback(GP_ProgressCallback *self)
{
+ static GP_Size size = 0;
+
if (abort_flag)
return 1;
-
+
+ if (!show_progress)
+ return 0;
+
+ char buf[100];
+
+ snprintf(buf, sizeof(buf), "%s ... %-3.1f%%",
+ (const char*)self->priv, self->percentage);
+
+ GP_Context *c = &fb->context;
+
+ int align = GP_ALIGN_CENTER|GP_VALIGN_ABOVE;
+
+ GP_TextClear(c, NULL, c->w/2, c->h - 4, align,
+ black_pixel, GP_MAX(size, GP_TextWidth(NULL, buf)));
+
+ GP_Text(c, NULL, c->w/2, c->h - 4, align,
+ white_pixel, black_pixel, buf);
+
+ size = GP_TextWidth(NULL, buf);
+
return 0;
}
struct loader_params {
const char *img_path;
- int clear;
+ int show_progress;
+ int show_progress_once;
+ int show_info;
};
static float calc_img_size(uint32_t img_w, uint32_t img_h,
@@ -66,31 +91,40 @@ static float calc_img_size(uint32_t img_w, uint32_t img_h,
return GP_MIN(w_rat, h_rat);
}
+static const char *img_name(const char *img_path)
+{
+ int i, len = strlen(img_path);
+
+ for (i = len - 1; i > 0; i--) {
+ if (img_path[i] == '/')
+ return &img_path[i+1];
+ }
+
+ return NULL;
+}
+
static void *image_loader(void *ptr)
{
struct loader_params *params = ptr;
GP_ProgressCallback callback = {.callback = image_loader_callback};
- fprintf(stderr, "Loading '%s'n", params->img_path);
+ show_progress = params->show_progress || params->show_progress_once;
+ params->show_progress_once = 0;
- if (params->clear) {
- char buf[100];
- snprintf(buf, sizeof(buf), "Loading '%s'", params->img_path);
- GP_Fill(&fb->context, black_pixel);
- //GP_BoxCenteredText(&fb->context, NULL, 0, 0,
- // fb->context.w, fb->context.h,
- // buf, white_pixel);
- }
+ fprintf(stderr, "Loading '%s'n", params->img_path);
GP_Context *img = NULL;
+ callback.priv = "Loading image";
+
if (GP_LoadImage(params->img_path, &img, &callback) != 0) {
- // GP_BoxCenteredText(&fb->context, NULL, 0, 0,
- // fb->context.w, fb->context.h,
- // "Failed to load image", white_pixel);
+ GP_Fill(&fb->context, black_pixel);
+ GP_Text(&fb->context, NULL, fb->context.w/2, fb->context.h/2,
+ GP_ALIGN_CENTER|GP_VALIGN_CENTER, black_pixel, white_pixel,
+ "Failed to load image :(");
return NULL;
}
-
+
GP_Size w, h;
switch (rotate) {
@@ -109,6 +143,9 @@ static void *image_loader(void *ptr)
float rat = calc_img_size(img->w, img->h, w, h);
+ w = img->w;
+ h = img->h;
+
/* Workaround */
if (img->pixel_type != GP_PIXEL_RGB888) {
GP_Context *tmp = GP_ContextConvert(img, NULL, GP_PIXEL_RGB888);
@@ -116,11 +153,13 @@ static void *image_loader(void *ptr)
img = tmp;
}
-
GP_Context *ret;
-// if (GP_FilterGaussianBlur(img, img, 0.7, 0.7, &callback))
-// return NULL;
+ //callback.priv = "Blurring Image";
+ //if (GP_FilterGaussianBlur(img, img, 0.25/rat, 0.25/rat, &callback) == NULL)
+ // return NULL;
+
+ callback.priv = "Resampling Image";
ret = GP_FilterResize(img, NULL, GP_INTERP_CUBIC, img->w * rat, img->h * rat, &callback);
GP_ContextFree(img);
@@ -131,12 +170,15 @@ static void *image_loader(void *ptr)
case 0:
break;
case 90:
+ callback.priv = "Rotating image (90)";
img = GP_FilterRotate90(ret, NULL, &callback);
break;
case 180:
+ callback.priv = "Rotating image (180)";
img = GP_FilterRotate180(ret, NULL, &callback);
break;
case 270:
+ callback.priv = "Rotating image (270)";
img = GP_FilterRotate270(ret, NULL, &callback);
break;
}
@@ -161,19 +203,38 @@ static void *image_loader(void *ptr)
GP_FillRectXYWH(&fb->context, ret->w+cx, 0, cx, fb->context.h, black_pixel);
GP_FillRectXYWH(&fb->context, 0, ret->h+cy, fb->context.w, cy, black_pixel);
+ if (!params->show_info)
+ return NULL;
+
+ GP_Size th = GP_TextHeight(NULL);
+
+ GP_Print(&fb->context, NULL, 11, 11, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
+ black_pixel, white_pixel, "%ux%u", w, h);
+
+ GP_Print(&fb->context, NULL, 10, 10, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
+ white_pixel, black_pixel, "%ux%u", w, h);
+
+ GP_Print(&fb->context, NULL, 11, 13 + th, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
+ black_pixel, white_pixel, "1:%3.3f", rat);
+
+ GP_Print(&fb->context, NULL, 10, 12 + th, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
+ white_pixel, black_pixel, "1:%3.3f", rat);
+
+ GP_Print(&fb->context, NULL, 11, 15 + 2 * th, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
+ black_pixel, white_pixel, "%s", img_name(params->img_path));
+
+ GP_Print(&fb->context, NULL, 10, 14 + 2 * th, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
+ white_pixel, black_pixel, "%s", img_name(params->img_path));
+
return NULL;
}
static pthread_t loader_thread = (pthread_t)0;
-static struct loader_params params;
-static void show_image(const char *img_path, int clear)
+static void show_image(struct loader_params *params)
{
int ret;
- params.img_path = img_path;
- params.clear = clear;
-
/* stop previous loader thread */
if (loader_thread) {
abort_flag = 1;
@@ -182,7 +243,7 @@ static void show_image(const char *img_path, int clear)
abort_flag = 0;
}
- ret = pthread_create(&loader_thread, NULL, image_loader, (void*)¶ms);
+ ret = pthread_create(&loader_thread, NULL, image_loader, (void*)params);
if (ret) {
fprintf(stderr, "Failed to start thread: %sn", strerror(ret));
@@ -204,11 +265,17 @@ int main(int argc, char *argv[])
GP_InputDriverLinux *drv = NULL;
char *input_dev = NULL;
int sleep_sec = -1;
-
+ struct loader_params params = {NULL, 0, 0, 0};
int opt;
- while ((opt = getopt(argc, argv, "i:s:r:")) != -1) {
+ while ((opt = getopt(argc, argv, "Ii:Ps:r:")) != -1) {
switch (opt) {
+ case 'I':
+ params.show_info = 1;
+ break;
+ case 'P':
+ params.show_progress = 1;
+ break;
case 'i':
input_dev = optarg;
break;
@@ -258,10 +325,14 @@ int main(int argc, char *argv[])
black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, &fb->context);
white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, &fb->context);
+ GP_Fill(&fb->context, black_pixel);
+
int argf = optind;
int argn = argf;
- show_image(argv[argf], 1);
+ params.show_progress_once = 1;
+ params.img_path = argv[argf];
+ show_image(¶ms);
/* Initalize select */
fd_set rfds;
@@ -288,7 +359,8 @@ int main(int argc, char *argv[])
if (argn >= argc)
argn = argf;
- show_image(argv[argn], 0);
+ params.img_path = argv[argn];
+ show_image(¶ms);
break;
default:
while (GP_InputDriverLinuxRead(drv));
@@ -302,7 +374,8 @@ int main(int argc, char *argv[])
if (argn >= argc)
argn = argf;
- show_image(argv[argn], 0);
+ params.img_path = argv[argn];
+ show_image(¶ms);
}
/* Read and parse events */
@@ -318,11 +391,22 @@ int main(int argc, char *argv[])
continue;
switch (ev.val.key.key) {
+ case GP_KEY_I:
+ params.show_info = !params.show_info;
+
+ params.show_progress_once = 1;
+ show_image(¶ms);
+ break;
+ case GP_KEY_P:
+ params.show_progress = !params.show_progress;
+ break;
case GP_KEY_R:
rotate += 90;
if (rotate > 270)
rotate = 0;
- show_image(argv[argn], 1);
+
+ params.show_progress_once = 1;
+ show_image(¶ms);
break;
case GP_KEY_ESC:
case GP_KEY_ENTER:
@@ -330,20 +414,28 @@ int main(int argc, char *argv[])
GP_FramebufferExit(fb);
return 0;
break;
+ case GP_KEY_RIGHT:
case GP_KEY_UP:
case GP_KEY_SPACE:
argn++;
if (argn >= argc)
argn = argf;
- show_image(argv[argn], 1);
+
+ params.show_progress_once = 1;
+ params.img_path = argv[argn];
+ show_image(¶ms);
break;
+ case GP_KEY_BACKSPACE:
+ case GP_KEY_LEFT:
case GP_KEY_DOWN:
argn--;
if (argn < argf)
argn = argc - 1;
- show_image(argv[argn], 1);
+ params.show_progress_once = 1;
+ params.img_path = argv[argn];
+ show_image(¶ms);
break;
}
break;
-----------------------------------------------------------------------
Summary of changes:
demos/fbshow/fbshow.c | 156 +++++++++++++++++++++++++++++++++++++++----------
1 files changed, 124 insertions(+), 32 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 master updated: 5e645909989e30e94ffe9eacf2177f441d44c2d6
by metan 25 Nov '11
by metan 25 Nov '11
25 Nov '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, master has been updated
via 5e645909989e30e94ffe9eacf2177f441d44c2d6 (commit)
via 9655adbc1de7cf63dd3510bb57f6fec95248c010 (commit)
via 761929b143cb585ace1dd3c97cbe2f6be2952b80 (commit)
via a21a7b420ab39c6c833aa878898295f61978c909 (commit)
from 31c18f79b0e5a2b49f3ad6315ab7605935b2fc56 (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/5e645909989e30e94ffe9eacf2177f441d44…
commit 5e645909989e30e94ffe9eacf2177f441d44c2d6
Merge: 9655adb 31c18f7
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 25 23:52:18 2011 +0100
Merge ssh://repo.or.cz/srv/git/gfxprim
http://repo.or.cz/w/gfxprim.git/commit/9655adbc1de7cf63dd3510bb57f6fec95248…
commit 9655adbc1de7cf63dd3510bb57f6fec95248c010
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 25 19:17:49 2011 +0100
text: Starting on redoing the text interface.
diff --git a/demos/fbshow/fbshow.c b/demos/fbshow/fbshow.c
index bf18f3f..082c888 100644
--- a/demos/fbshow/fbshow.c
+++ b/demos/fbshow/fbshow.c
@@ -77,17 +77,17 @@ static void *image_loader(void *ptr)
char buf[100];
snprintf(buf, sizeof(buf), "Loading '%s'", params->img_path);
GP_Fill(&fb->context, black_pixel);
- GP_BoxCenteredText(&fb->context, NULL, 0, 0,
- fb->context.w, fb->context.h,
- buf, white_pixel);
+ //GP_BoxCenteredText(&fb->context, NULL, 0, 0,
+ // fb->context.w, fb->context.h,
+ // buf, white_pixel);
}
GP_Context *img = NULL;
if (GP_LoadImage(params->img_path, &img, &callback) != 0) {
- GP_BoxCenteredText(&fb->context, NULL, 0, 0,
- fb->context.w, fb->context.h,
- "Failed to load image", white_pixel);
+ // GP_BoxCenteredText(&fb->context, NULL, 0, 0,
+ // fb->context.w, fb->context.h,
+ // "Failed to load image", white_pixel);
return NULL;
}
diff --git a/include/text/GP_Font.h b/include/text/GP_Font.h
index e84d459..a3cd434 100644
--- a/include/text/GP_Font.h
+++ b/include/text/GP_Font.h
@@ -19,12 +19,12 @@
* 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_FONT_H
-#define GP_FONT_H
+#ifndef TEXT_GP_FONT_H
+#define TEXT_GP_FONT_H
#include <stdint.h>
@@ -159,4 +159,4 @@ unsigned int GP_GetFontDataSize(const GP_Font *font);
GP_RetCode GP_FontLoad(GP_Font **font, const char *filename);
GP_RetCode GP_FontSave(const GP_Font *font, const char *filename);
-#endif /* GP_FONT_H */
+#endif /* TEXT_GP_FONT_H */
diff --git a/include/text/GP_Text.h b/include/text/GP_Text.h
index 2c0177e..9cfdb7d 100644
--- a/include/text/GP_Text.h
+++ b/include/text/GP_Text.h
@@ -23,8 +23,8 @@
* *
*****************************************************************************/
-#ifndef GP_TEXT_H
-#define GP_TEXT_H
+#ifndef TEXT_GP_TEXT_H
+#define TEXT_GP_TEXT_H
#include "core/GP_Context.h"
@@ -42,7 +42,7 @@
* - GP_VALIGN_BASELINE places the text baseline at the point
* - GP_VALIGN_BELOW (or BOTTOM) draws the text below the point
*/
-typedef enum GP_TextAlign {
+typedef enum GP_TextAttr {
GP_ALIGN_LEFT = 0x01,
GP_ALIGN_CENTER = 0x02,
GP_ALIGN_RIGHT = 0x03,
@@ -52,22 +52,44 @@ typedef enum GP_TextAlign {
GP_VALIGN_BASELINE = 0x30,
GP_VALIGN_BELOW = 0x40,
GP_VALIGN_BOTTOM = GP_VALIGN_BELOW,
-} GP_TextAlign;
+} GP_TextAttr;
-GP_RetCode GP_Text_Raw(GP_Context *context, const GP_TextStyle *style,
- GP_Coord x, GP_Coord y, int align,
- const char *str, GP_Pixel pixel);
+void GP_Text_Raw(GP_Context *context, const GP_TextStyle *style,
+ GP_Coord x, GP_Coord y, int align,
+ GP_Pixel fg_color, GP_Pixel bg_color, const char *str);
-GP_RetCode GP_Text(GP_Context *context, const GP_TextStyle *style,
- GP_Coord x, GP_Coord y, int align,
- const char *str, GP_Pixel pixel);
+/*
+ * Draws a string.
+ *
+ * The string is rendered to context (horizontally) with defined text style.
+ * The x and y coordinates determines point defined by aligment flags.
+ *
+ * The background color is ignored for 1bpp font formats.
+ */
+void GP_Text(GP_Context *context, const GP_TextStyle *style,
+ GP_Coord x, GP_Coord y, int align,
+ GP_Pixel fg_color, GP_Pixel bg_color, const char *str);
+
+/*
+ * Same as above, but printf like and returns text width in pixels.
+ */
+GP_Size GP_Print(GP_Context *context, const GP_TextStyle *style,
+ GP_Coord x, GP_Coord y, int align,
+ GP_Pixel fg_color, GP_Pixel bg_color, const char *fmt, ...)
+ __attribute__ ((format (printf, 8, 9)));
-GP_RetCode GP_BoxCenteredText_Raw(GP_Context *context, const GP_TextStyle *style,
- GP_Coord x, GP_Coord y, GP_Size w, GP_Size h,
- const char *str, GP_Pixel pixel);
+/*
+ * Clears rectangle that would be used to draw text of size pixels.
+ */
+void GP_TextClear(GP_Context *context, const GP_TextStyle *style,
+ GP_Coord x, GP_Coord y, int align,
+ GP_Pixel bg_color, GP_Size size);
-GP_RetCode GP_BoxCenteredText(GP_Context *context, const GP_TextStyle *style,
- GP_Coord x, GP_Coord y, GP_Size w, GP_Size h,
- const char *str, GP_Pixel pixel);
+/*
+ * Dtto, but with string.
+ */
+void GP_TextClearStr(GP_Context *context, const GP_TextStyle *style,
+ GP_Coord x, GP_Coord y, int align,
+ GP_Pixel bg_color, const char *str);
-#endif /* GP_TEXT_H */
+#endif /* TEXT_GP_TEXT_H */
diff --git a/include/text/GP_TextMetric.h b/include/text/GP_TextMetric.h
index d9f4ffb..16d44bc 100644
--- a/include/text/GP_TextMetric.h
+++ b/include/text/GP_TextMetric.h
@@ -19,44 +19,47 @@
* 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_TEXT_METRIC_H
-#define GP_TEXT_METRIC_H
+#ifndef TEXT_GP_TEXT_METRIC_H
+#define TEXT_GP_TEXT_METRIC_H
+#include "core/GP_Types.h"
#include "GP_TextStyle.h"
/*
* Calculates the width of the string drawn in the given style, in pixels.
*/
-unsigned int GP_TextWidth(const GP_TextStyle *style, const char *str);
+GP_Size GP_TextWidth(const GP_TextStyle *style, const char *str);
/*
* Maximal text width for string with len characters.
*/
-unsigned int GP_TextMaxWidth(const GP_TextStyle *style, unsigned int len);
+GP_Size GP_TextMaxWidth(const GP_TextStyle *style, unsigned int len);
/*
* Returns maximal width for text written with len characters from str.
*/
-unsigned int GP_TextMaxStrWidth(const GP_TextStyle *style, const char *str,
- unsigned int len);
+GP_Size GP_TextMaxStrWidth(const GP_TextStyle *style, const char *str,
+ unsigned int len);
/*
* Returns maximal text height, in pixels.
*/
-unsigned int GP_TextHeight(const GP_TextStyle *style);
+GP_Size GP_TextHeight(const GP_TextStyle *style);
-/* Returns the ascent (height from the baseline to the top of characters),
+/*
+ * Returns the ascent (height from the baseline to the top of characters),
* for the given text style. (Result is in pixels.)
*/
-unsigned int GP_TextAscent(const GP_TextStyle *style);
+GP_Size GP_TextAscent(const GP_TextStyle *style);
-/* Returns the descent (height from the baseline to the bottom of characters),
+/*
+ * Returns the descent (height from the baseline to the bottom of characters),
* for the given text style. (Result is in pixels.)
*/
-unsigned int GP_TextDescent(const GP_TextStyle *style);
+GP_Size GP_TextDescent(const GP_TextStyle *style);
-#endif /* GP_TEXT_METRIC_H */
+#endif /* TEXT_GP_TEXT_METRIC_H */
diff --git a/include/text/GP_TextStyle.h b/include/text/GP_TextStyle.h
index d57e678..58b6886 100644
--- a/include/text/GP_TextStyle.h
+++ b/include/text/GP_TextStyle.h
@@ -23,8 +23,8 @@
* *
*****************************************************************************/
-#ifndef GP_TEXTSTYLE_H
-#define GP_TEXTSTYLE_H
+#ifndef TEXT_GP_TEXTSTYLE_H
+#define TEXT_GP_TEXTSTYLE_H
#include "GP_Font.h"
#include "core/GP_RetCode.h"
@@ -68,4 +68,4 @@ void GP_DefaultTextStyle(GP_TextStyle *style);
GP_CHECK_FONT(style->font); } while(0)
-#endif /* GP_TEXTSTYLE_H */
+#endif /* TEXT_GP_TEXTSTYLE_H */
diff --git a/libs/text/GP_Text.c b/libs/text/GP_Text.c
index c6fce34..56033d2 100644
--- a/libs/text/GP_Text.c
+++ b/libs/text/GP_Text.c
@@ -23,168 +23,153 @@
* *
*****************************************************************************/
+#include <stdarg.h>
#include "algo/Text.algo.h"
#include "gfx/GP_Gfx.h"
#include "core/GP_FnPerBpp.h"
+#include "core/GP_Debug.h"
#include "GP_Text.h"
GP_TextStyle GP_DefaultStyle = GP_DEFAULT_TEXT_STYLE;
+static int do_align(GP_Coord *topleft_x, GP_Coord *topleft_y, int align,
+ GP_Coord x, GP_Coord y, const GP_TextStyle *style,
+ GP_Size width)
+{
+ int height = GP_TextHeight(style);
+
+ switch (align & 0x0f) {
+ case GP_ALIGN_LEFT:
+ *topleft_x = x - width + 1;
+ break;
+ case GP_ALIGN_RIGHT:
+ *topleft_x = x;
+ break;
+ case GP_ALIGN_CENTER:
+ *topleft_x = x - width/2;
+ break;
+ default:
+ GP_DEBUG(1, "ALIGN 0x%0xn", align);
+ return 1;
+ }
+
+ switch (align & 0xf0) {
+ case GP_VALIGN_ABOVE:
+ *topleft_y = y - height + 1;
+ break;
+ case GP_VALIGN_CENTER:
+ *topleft_y = y - height/2;
+ break;
+ case GP_VALIGN_BASELINE:
+ *topleft_y = y - height + style->font->baseline;
+ break;
+ case GP_VALIGN_BELOW:
+ *topleft_y = y;
+ break;
+ default:
+ GP_DEBUG(1, "VALIGN 0x%0xn", align);
+ return 1;
+ }
+
+ return 0;
+}
+
/* Generate drawing functions for various bit depths. */
GP_DEF_FILL_FN_PER_BPP(GP_Text_Raw, DEF_TEXT_FN)
-GP_RetCode GP_Text_Raw(GP_Context *context, const GP_TextStyle *style,
- GP_Coord x, GP_Coord y, int align,
- const char *str, GP_Pixel pixel)
+void GP_Text_Raw(GP_Context *context, const GP_TextStyle *style,
+ GP_Coord x, GP_Coord y, int align,
+ GP_Pixel fg_color, GP_Pixel bg_color, const char *str)
{
+ (void) bg_color;
+
GP_CHECK_CONTEXT(context);
if (str == NULL)
- return GP_ENULLPTR;
+ return;
if (style == NULL)
style = &GP_DefaultStyle;
GP_CHECK_TEXT_STYLE(style);
- int width = GP_TextWidth(style, str);
- int height = GP_TextHeight(style);
+ GP_Coord topleft_x, topleft_y;
+ GP_Size w = GP_TextWidth(style, str);
- int topleft_x, topleft_y;
- switch (align & 0x0f) {
- case GP_ALIGN_LEFT:
- topleft_x = x - width + 1;
- break;
- case GP_ALIGN_RIGHT:
- topleft_x = x;
- break;
- case GP_ALIGN_CENTER:
- topleft_x = x - width/2;
- break;
- default:
- return GP_EINVAL;
- }
- switch (align & 0xf0) {
- case GP_VALIGN_ABOVE:
- topleft_y = y - height + 1;
- break;
- case GP_VALIGN_CENTER:
- topleft_y = y - height/2;
- break;
- case GP_VALIGN_BASELINE:
- topleft_y = y - height + style->font->baseline;
- break;
- case GP_VALIGN_BELOW:
- topleft_y = y;
- break;
- default:
- return GP_EINVAL;
- }
+ GP_ASSERT(do_align(&topleft_x, &topleft_y, align, x, y, style, w) == 0,
+ "Invalid aligment flags");
GP_FN_PER_BPP_CONTEXT(GP_Text_Raw, context, context, style,
- topleft_x, topleft_y, str, pixel);
-
- return GP_ESUCCESS;
+ topleft_x, topleft_y, str, fg_color);
}
DEF_TEXT_FN(GP_Text_internal, GP_Context *, GP_Pixel, GP_HLine)
-GP_RetCode GP_Text(GP_Context *context, const GP_TextStyle *style,
- GP_Coord x, GP_Coord y, int align,
- const char *str, GP_Pixel pixel)
+void GP_Text(GP_Context *context, const GP_TextStyle *style,
+ GP_Coord x, GP_Coord y, int align,
+ GP_Pixel fg_color, GP_Pixel bg_color,
+ const char *str)
{
+ (void) bg_color;
+
GP_CHECK_CONTEXT(context);
-
+
if (str == NULL)
- return GP_ENULLPTR;
+ return;
if (style == NULL)
style = &GP_DefaultStyle;
GP_CHECK_TEXT_STYLE(style);
+
+ GP_Coord topleft_x, topleft_y;
+ GP_Size w = GP_TextWidth(style, str);
- int width = GP_TextWidth(style, str);
- int height = GP_TextHeight(style);
-
- int topleft_x, topleft_y;
- switch (align & 0x0f) {
- case GP_ALIGN_LEFT:
- topleft_x = x - width;
- break;
- case GP_ALIGN_RIGHT:
- topleft_x = x;
- break;
- case GP_ALIGN_CENTER:
- topleft_x = x - width/2;
- break;
- default:
- return GP_EINVAL;
- }
- switch (align & 0xf0) {
- case GP_VALIGN_ABOVE:
- topleft_y = y - height;
- break;
- case GP_VALIGN_CENTER:
- topleft_y = y - height/2;
- break;
- case GP_VALIGN_BASELINE:
- topleft_y = y - height + style->font->baseline;
- break;
- case GP_VALIGN_BELOW:
- topleft_y = y;
- break;
- default:
- return GP_EINVAL;
- }
+ GP_ASSERT(do_align(&topleft_x, &topleft_y, align, x, y, style, w) == 0,
+ "Invalid aligment flags");
- GP_Text_internal(context, style, topleft_x, topleft_y, str, pixel);
- return GP_ESUCCESS;
+ GP_Text_internal(context, style, topleft_x, topleft_y, str, fg_color);
}
-GP_RetCode GP_BoxCenteredText_Raw(GP_Context *context, const GP_TextStyle *style,
- GP_Coord x, GP_Coord y, GP_Size w, GP_Size h,
- const char *str, GP_Pixel pixel)
-{
- GP_CHECK_CONTEXT(context);
- if (str == NULL)
- return GP_ENULLPTR;
+GP_Size GP_Print(GP_Context *context, const GP_TextStyle *style,
+ GP_Coord x, GP_Coord y, int align,
+ GP_Pixel fg_color, GP_Pixel bg_color, const char *fmt, ...)
+{
+ va_list va, vac;
+ int size;
- if (style == NULL)
- style = &GP_DefaultStyle;
-
- GP_CHECK_TEXT_STYLE(style);
+ va_start(va, fmt);
+ va_copy(vac, va);
+ size = vsnprintf(NULL, 0, fmt, va);
+ va_end(va);
+ char buf[size+1];
+ vsnprintf(buf, sizeof(buf), fmt, vac);
+ va_end(vac);
- const int mid_x = x + w/2;
- const int mid_y = y + h/2;
- const int font_ascent = GP_TextAscent(style);
+ GP_Text(context, style, x, y, align, fg_color, bg_color, buf);
- return GP_Text_Raw(context, style, mid_x,
- mid_y + font_ascent/2,
- GP_ALIGN_CENTER | GP_VALIGN_BASELINE,
- str, pixel);
+ return GP_TextWidth(style, buf);
}
-GP_RetCode GP_BoxCenteredText(GP_Context *context, const GP_TextStyle *style,
- GP_Coord x, GP_Coord y, GP_Size w, GP_Size h,
- const char *str, GP_Pixel pixel)
-{
- GP_CHECK_CONTEXT(context);
- if (str == NULL)
- return GP_ENULLPTR;
+void GP_TextClear(GP_Context *context, const GP_TextStyle *style,
+ GP_Coord x, GP_Coord y, int align,
+ GP_Pixel bg_color, GP_Size size)
+{
+ GP_Coord topleft_x, topleft_y;
- if (style == NULL)
- style = &GP_DefaultStyle;
-
- GP_CHECK_TEXT_STYLE(style);
+ GP_ASSERT(do_align(&topleft_x, &topleft_y, align, x, y, style, size) == 0,
+ "Invalid aligment flags");
- const int mid_x = x + w/2;
- const int mid_y = y + h/2;
- const int font_ascent = GP_TextAscent(style);
+ GP_FillRectXYWH(context, topleft_x, topleft_y,
+ size, GP_TextHeight(style), bg_color);
+}
- return GP_Text(context, style, mid_x,
- mid_y + font_ascent/2,
- GP_ALIGN_CENTER | GP_VALIGN_BASELINE,
- str, pixel);
+void GP_TextClearStr(GP_Context *context, const GP_TextStyle *style,
+ GP_Coord x, GP_Coord y, int align,
+ GP_Pixel bg_color, const char *str)
+{
+ GP_TextClear(context, style, x, y, align,
+ bg_color, GP_TextWidth(style, str));
}
diff --git a/tests/SDL/blittest.c b/tests/SDL/blittest.c
index 1a4ed83..bfedaa7 100644
--- a/tests/SDL/blittest.c
+++ b/tests/SDL/blittest.c
@@ -85,7 +85,8 @@ void redraw_screen(void)
SDL_LockSurface(display);
- GP_Text(&context, NULL, 20, 20, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM, text_buf, white);
+ GP_Text(&context, NULL, 20, 20, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
+ white, black, text_buf);
GP_Blit(bitmap, 0, 0, bitmap->w, bitmap->h, &context, bitmap_x, bitmap_y);
SDL_UpdateRect(display, bitmap_x, bitmap_y, bitmap->w, bitmap->h);
diff --git a/tests/SDL/fileview.c b/tests/SDL/fileview.c
index c01a7fc..1899da9 100644
--- a/tests/SDL/fileview.c
+++ b/tests/SDL/fileview.c
@@ -92,7 +92,8 @@ void redraw_screen(void)
for (i = 0; i < 30; i++) {
if (line == NULL)
break;
- GP_Text(&context, &style, 16, 16*i + 16, align, line->text, black_pixel);
+ GP_Text(&context, &style, 16, 16*i + 16, align,
+ black_pixel, black_pixel, line->text);
line = line->next;
}
diff --git a/tests/SDL/fonttest.c b/tests/SDL/fonttest.c
index 602c526..4bfa945 100644
--- a/tests/SDL/fonttest.c
+++ b/tests/SDL/fonttest.c
@@ -98,20 +98,23 @@ void redraw_screen(void)
style.font->height + 1,
blue_pixel);
- GP_Text(&context, &style, 16, 100*i + 16, align, test_string, white_pixel);
+ GP_Text(&context, &style, 16, 100*i + 16, align,
+ white_pixel, black_pixel, test_string);
style.pixel_xmul = 2;
style.pixel_ymul = 2;
style.pixel_yspace = 1;
- GP_Text(&context, &style, 34, 100*i + 38, align, test_string, gray_pixel);
+ GP_Text(&context, &style, 34, 100*i + 38, align,
+ white_pixel, black_pixel, test_string);
style.pixel_xmul = 4;
style.pixel_ymul = 2;
style.pixel_xspace = 1;
style.pixel_yspace = 1;
- GP_Text(&context, &style, 64, 100*i + 72, align, test_string, dark_gray_pixel);
+ GP_Text(&context, &style, 64, 100*i + 72, align,
+ dark_gray_pixel, black_pixel, test_string);
}
SDL_UnlockSurface(display);
@@ -188,7 +191,9 @@ void print_character_metadata(const GP_Font *font, int c)
int main(int argc, char *argv[])
{
print_instructions();
-
+
+ GP_SetDebugLevel(10);
+
if (argc > 1) {
GP_RetCode err;
fprintf(stderr, "nLoading font '%s'n", argv[1]);
diff --git a/tests/SDL/input.c b/tests/SDL/input.c
index c420b09..c2b1cde 100644
--- a/tests/SDL/input.c
+++ b/tests/SDL/input.c
@@ -48,12 +48,17 @@ Uint32 timer_callback(__attribute__((unused)) Uint32 interval,
static void draw_event(GP_Event *ev)
{
+ static GP_Size size = 0;
+
if (ev->type != GP_EV_KEY)
return;
+
+ int align = GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM;
- GP_FillRect(&context, 0, 0, 150, 35, black_pixel);
- GP_Text(&context, NULL, 20, 20, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM,
- GP_EventKeyName(ev->val.key.key), white_pixel);
+ GP_TextClear(&context, NULL, 20, 20, align, black_pixel, size);
+ size = GP_Print(&context, NULL, 20, 20, align,
+ white_pixel, black_pixel, "Key=%s",
+ GP_EventKeyName(ev->val.key.key));
SDL_Flip(display);
}
@@ -94,12 +99,21 @@ static void event_loop(void)
break;
case GP_EV_REL:
switch (ev.code) {
+ static int size = 0;
case GP_EV_REL_POS:
if (GP_EventGetKey(&ev, GP_BTN_LEFT)) {
GP_PutPixel(&context, ev.cursor_x,
ev.cursor_y, green_pixel);
SDL_Flip(display);
}
+ int align = GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM;
+
+ GP_TextClear(&context, NULL, 20, 40, align,
+ black_pixel, size);
+ size = GP_Print(&context, NULL, 20, 40, align,
+ white_pixel, black_pixel, "X=%3u Y=%3u",
+ ev.cursor_x, ev.cursor_y);
+ SDL_Flip(display);
break;
}
break;
diff --git a/tests/SDL/shapetest.c b/tests/SDL/shapetest.c
index d270528..8435e10 100644
--- a/tests/SDL/shapetest.c
+++ b/tests/SDL/shapetest.c
@@ -273,7 +273,7 @@ void redraw_screen(void)
}
GP_Text(&context, &style, 16, 16, GP_ALIGN_RIGHT|GP_VALIGN_BELOW,
- title, white);
+ white, black, title);
SDL_UnlockSurface(display);
}
diff --git a/tests/SDL/subcontext.c b/tests/SDL/subcontext.c
index 25db7fb..5147ddf 100644
--- a/tests/SDL/subcontext.c
+++ b/tests/SDL/subcontext.c
@@ -128,7 +128,7 @@ static void draw_text(GP_Context *dest, GP_Coord x, GP_Coord y,
x1 = random() % (w - tw) + x;
y1 = random() % (h - th) + y;
- GP_Text(dest, NULL, x1, y1, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM, TEXT, col);
+ GP_Text(dest, NULL, x1, y1, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM, col, black, TEXT);
}
void redraw_screen(void)
diff --git a/tests/SDL/textaligntest.c b/tests/SDL/textaligntest.c
index 507b560..b6ac351 100644
--- a/tests/SDL/textaligntest.c
+++ b/tests/SDL/textaligntest.c
@@ -65,20 +65,20 @@ void redraw_screen(void)
style.pixel_xspace = 4;
style.pixel_yspace = 4;
- GP_BoxCenteredText(&context, &style, 0, 0, X, Y,
- "Hello world!", darkgray_pixel);
+ //GP_BoxCenteredText(&context, &style, 0, 0, X, Y,
+ // "Hello world!", darkgray_pixel);
style.pixel_xspace = 0;
style.pixel_yspace = 0;
GP_Text(&context, &style, X/2, Y/2, GP_ALIGN_LEFT|GP_VALIGN_BELOW,
- "bottom left", yellow_pixel);
+ yellow_pixel, black_pixel, "bottom left");
GP_Text(&context, &style, X/2, Y/2, GP_ALIGN_RIGHT|GP_VALIGN_BELOW,
- "bottom right", red_pixel);
+ red_pixel, black_pixel, "bottom right");
GP_Text(&context, &style, X/2, Y/2, GP_ALIGN_RIGHT|GP_VALIGN_ABOVE,
- "top right", blue_pixel);
+ blue_pixel, black_pixel, "top right");
GP_Text(&context, &style, X/2, Y/2, GP_ALIGN_LEFT|GP_VALIGN_ABOVE,
- "top left", green_pixel);
+ green_pixel, black_pixel, "top left");
SDL_UnlockSurface(display);
}
diff --git a/tests/drivers/framebuffer_test.c b/tests/drivers/framebuffer_test.c
index c5aceb9..c2595d2 100644
--- a/tests/drivers/framebuffer_test.c
+++ b/tests/drivers/framebuffer_test.c
@@ -77,7 +77,7 @@ int main(void)
GP_Pixel gray, black;
gray = GP_RGBToContextPixel(200, 200, 200, &fb->context);
- black = GP_RGBToContextPixel( 0, 0, 0, &fb->context);
+ black = GP_RGBToContextPixel(0, 0, 0, &fb->context);
const char *text = "Framebuffer test";
@@ -86,7 +86,7 @@ int main(void)
GP_Line(&fb->context, 0, fb->context.h, fb->context.w, 0, black);
GP_Text(&fb->context, &style,
(fb->context.w - GP_TextWidth(&style, text))/2,
- 16, GP_ALIGN_RIGHT|GP_VALIGN_BELOW, text, black);
+ 16, GP_ALIGN_RIGHT|GP_VALIGN_BELOW, black, gray, text);
draw(&fb->context, fb->context.w / 2, 2.00 * fb->context.h / 3, 60);
http://repo.or.cz/w/gfxprim.git/commit/761929b143cb585ace1dd3c97cbe2f6be295…
commit 761929b143cb585ace1dd3c97cbe2f6be2952b80
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 25 18:36:20 2011 +0100
filters: Complete filter param & fix tests.
diff --git a/include/filters/GP_FilterParam.h b/include/filters/GP_FilterParam.h
index d073305..f997ed5 100644
--- a/include/filters/GP_FilterParam.h
+++ b/include/filters/GP_FilterParam.h
@@ -84,6 +84,23 @@ int GP_FilterParamCheckChannels(GP_FilterParam params[],
#define GP_FILTER_PARAMS(pixel_type, name) GP_FilterParam name[GP_PixelTypes[pixel_type].numchannels + 1]; GP_FilterParamInitChannels(name, pixel_type);
+
+#define GP_FILTER_PARAMS_INT(pixel_type, name, val) + GP_FILTER_PARAMS(pixel_type, name) + GP_FilterParamSetIntAll(name, val);
+
+#define GP_FILTER_PARAMS_UINT(pixel_type, name, val) + GP_FILTER_PARAMS(pixel_type, name) + GP_FilterParamSetUIntAll(name, val);
+
+#define GP_FILTER_PARAMS_FLOAT(pixel_type, name, val) + GP_FILTER_PARAMS(pixel_type, name) + GP_FilterParamSetFloatAll(name, val);
+
+#define GP_FILTER_PARAMS_PTR(pixel_type, name, ptr) + GP_FILTER_PARAMS(pixel_type, name) + GP_FilterParamSetPtrAll(name, ptr);
+
/*
* Initalize param names and terminator.
*
@@ -116,4 +133,12 @@ void GP_FilterParamSetUIntAll(GP_FilterParam params[],
void GP_FilterParamSetPtrAll(GP_FilterParam params[],
void *ptr);
+/*
+ * Functions to print the array.
+ */
+void GP_FilterParamPrintInt(GP_FilterParam params[]);
+void GP_FilterParamPrintUInt(GP_FilterParam params[]);
+void GP_FilterParamPrintFloat(GP_FilterParam params[]);
+void GP_FilterParamPrintPtr(GP_FilterParam params[]);
+
#endif /* FILTERS_GP_FILTER_PARAM_H */
diff --git a/libs/filters/GP_FilterParam.c b/libs/filters/GP_FilterParam.c
index c5ef345..a07b3de 100644
--- a/libs/filters/GP_FilterParam.c
+++ b/libs/filters/GP_FilterParam.c
@@ -141,3 +141,35 @@ void GP_FilterParamSetPtrAll(GP_FilterParam params[],
for (i = 0; params[i].channel_name[0] != '0'; i++)
params[i].val.ptr = ptr;
}
+
+void GP_FilterParamPrintInt(GP_FilterParam params[])
+{
+ unsigned int i;
+
+ for (i = 0; params[i].channel_name[0] != '0'; i++)
+ printf("Chann '%s' = %in", params[i].channel_name, params[i].val.i);
+}
+
+void GP_FilterParamPrintUInt(GP_FilterParam params[])
+{
+ unsigned int i;
+
+ for (i = 0; params[i].channel_name[0] != '0'; i++)
+ printf("Chann '%s' = %un", params[i].channel_name, params[i].val.ui);
+}
+
+void GP_FilterParamPrintFloat(GP_FilterParam params[])
+{
+ unsigned int i;
+
+ for (i = 0; params[i].channel_name[0] != '0'; i++)
+ printf("Chann '%s' = %fn", params[i].channel_name, params[i].val.f);
+}
+
+void GP_FilterParamPrintPtr(GP_FilterParam params[])
+{
+ unsigned int i;
+
+ for (i = 0; params[i].channel_name[0] != '0'; i++)
+ printf("Chann '%s' = %pn", params[i].channel_name, params[i].val.ptr);
+}
diff --git a/tests/SDL/showimage.c b/tests/SDL/showimage.c
index 9df416d..b0f0839 100644
--- a/tests/SDL/showimage.c
+++ b/tests/SDL/showimage.c
@@ -47,17 +47,18 @@ void event_loop(void)
return;
case SDLK_UP:
brightness+=2;
- case SDLK_DOWN:
+ case SDLK_DOWN: {
brightness-=1;
- res = GP_FilterBrightness(bitmap, NULL, brightness, NULL);
+ GP_FILTER_PARAMS_INT(bitmap->pixel_type, param, brightness);
+ res = GP_FilterBrightness(bitmap, NULL, param, NULL);
printf("brightness = %i %ux%un", brightness, res->w, res->h);
GP_Blit(res, 0, 0, res->w, res->h, &context, 0, 0);
SDL_Flip(display);
GP_ContextFree(res);
- break;
+ } break;
default:
break;
}
http://repo.or.cz/w/gfxprim.git/commit/a21a7b420ab39c6c833aa878898295f61978…
commit a21a7b420ab39c6c833aa878898295f61978c909
Author: Cyril Hrubis <metan(a)ucw.cz>
Date: Fri Nov 25 18:32:09 2011 +0100
filters: Fix point filter template.
diff --git a/pylib/templates/filter.point.c.t b/pylib/templates/filter.point.c.t
index 750c448..88bd6c8 100644
--- a/pylib/templates/filter.point.c.t
+++ b/pylib/templates/filter.point.c.t
@@ -178,7 +178,7 @@ GP_Context *GP_Filter{{ name }}(const GP_Context *src, GP_Context *dst{{ maybe_o
"Destination is not big enough");
}
- if (GP_Filter{{ name }}_Raw(src, dst{{ maybe_opts(params) }}, callback)) {
+ if (GP_Filter{{ name }}_Raw(src, res{{ maybe_opts(params) }}, callback)) {
GP_DEBUG(1, "Operation aborted");
if (dst == NULL)
-----------------------------------------------------------------------
Summary of changes:
demos/fbshow/fbshow.c | 12 +-
include/filters/GP_FilterParam.h | 25 +++++
include/text/GP_Font.h | 8 +-
include/text/GP_Text.h | 56 +++++++---
include/text/GP_TextMetric.h | 29 +++---
include/text/GP_TextStyle.h | 6 +-
libs/filters/GP_FilterParam.c | 32 ++++++
libs/text/GP_Text.c | 215 ++++++++++++++++++--------------------
pylib/templates/filter.point.c.t | 2 +-
tests/SDL/blittest.c | 3 +-
tests/SDL/fileview.c | 3 +-
tests/SDL/fonttest.c | 13 ++-
tests/SDL/input.c | 20 +++-
tests/SDL/shapetest.c | 2 +-
tests/SDL/showimage.c | 7 +-
tests/SDL/subcontext.c | 2 +-
tests/SDL/textaligntest.c | 12 +-
tests/drivers/framebuffer_test.c | 4 +-
18 files changed, 270 insertions(+), 181 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 pywrap updated: 9fb8ec2881f24724d6fe71bbfecb7524e95053a7
by gavento 24 Nov '11
by gavento 24 Nov '11
24 Nov '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, pywrap has been updated
via 9fb8ec2881f24724d6fe71bbfecb7524e95053a7 (commit)
via 22d47ec8e304affafa567d890965992088bd08a6 (commit)
via 64ec17d6274119e321accf352b452b0a4d664097 (commit)
via 040d6abf67aeacd29d59f99b9c991ae60e1f664c (commit)
from 3cca227bd9d97802da766c2feca0bb537c038b16 (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/9fb8ec2881f24724d6fe71bbfecb7524e950…
commit 9fb8ec2881f24724d6fe71bbfecb7524e95053a7
Merge: 22d47ec 3cca227
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Thu Nov 24 23:26:08 2011 +0100
Merge branch 'pywrap' of git://repo.or.cz/gfxprim into pywrap
Conflicts:
include/core/swigify.sh
include/loaders/swigify.sh
http://repo.or.cz/w/gfxprim.git/commit/22d47ec8e304affafa567d890965992088bd…
commit 22d47ec8e304affafa567d890965992088bd08a6
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Thu Nov 24 23:20:32 2011 +0100
Minimalistic "pythonic" GP_Context wrapper
Placement is temporary
Loads gfxprim_core_c and gfxprim_loaders_c as core, loaders
Naive (but correct) error handling
Supports both owned and non-owned GP_Contexts (could be screen, etc.)
Supports subcontexts (with keeping ref. to parent to prevent GC)
diff --git a/pylib/context.py b/pylib/context.py
new file mode 100644
index 0000000..1551c5c
--- /dev/null
+++ b/pylib/context.py
@@ -0,0 +1,94 @@
+import gfxprim_core_c as core
+import gfxprim_loaders_c as loaders
+
+class Context(object):
+ def __init__(self, context, owns_GP_Context, parent=None):
+ """Create new GP_Context wrapper.
+
+ The wrapper is just a (read-only) proxy with
+ some conveniently mapped context methods.
+ Direct access is possible through self.context.
+ """
+ # GP_Context struct (pre-wrapped by SWIG)
+ self.context = context
+ # call GP_ContextFree on del?
+ self.owns_GP_Context = owns_GP_Context
+ # Parent Context of a subcontext (if any)
+ # It is important to hold a ref to parent because of GC
+ self.parent = parent
+
+ def __del__(self):
+ print "Deleting %s (owns_GP_Context: %s)" % (self, self.owns_GP_Context)
+ if self.owns_GP_Context:
+ core.GP_ContextFree(self.context)
+
+ @property
+ def w(self):
+ "Context width (transformed)"
+ return core.GP_ContextW(self.context)
+
+ @property
+ def h(self):
+ "Context height (transformed)"
+ return core.GP_ContextH(self.context)
+
+ @property
+ def bpp(self):
+ "Context bpp"
+ return self.context.bpp
+
+ def __str__(self):
+ return "<Context %dx%d, %dbpp, GP_Context %sowned, %s parent>" % (
+ self.w, self.h, self.bpp,
+ "" if self.owns_GP_Context else "not ",
+ "with" if self.parent else "no")
+ __repr__ = __str__
+
+ def subcontext(self, x, y, w, h):
+ "Create a subcontext (rectangular view)."
+ c = core.GP_ContextSubContext(self.context, None, x, y, w, h)
+ if not c:
+ raise Exception("Error creating subcontext")
+ return type(self)(c, owns_GP_Context=True, parent=self)
+
+ def save(self, filename, format=None):
+ """Save the image in given format (or guess by the extension)
+
+ Currently, JPG, PNG and P[BGP]M are supported, but not for all
+ context pixel types.
+ """
+ if not format:
+ format = filename.rsplit('.', 1)[-1]
+ format = format.lower()
+ if format == 'jpg':
+ res = loaders.GP_SaveJPG(filename, self.context, None)
+ elif format == 'png':
+ res = loaders.GP_SavePNG(filename, self.context, None)
+ elif format == 'pbm':
+ res = loaders.GP_SavePBM(filename, self.context, None)
+ elif format == 'pgm':
+ res = loaders.GP_SavePGM(filename, self.context, None)
+ elif format == 'ppm':
+ res = loaders.GP_SavePPM(filename, self.context, None)
+ else:
+ raise Exception("Format %r not supported.", format)
+ if res != 0:
+ raise Exception("Error saving %r (code %d)", filename, res)
+
+ @classmethod
+ def create(cls, w, h, pixeltype):
+ "Allocate a new w*h bitmap of given type."
+
+ pixeltype_no = pixeltype if isinstance(pixeltype, int) else 0 # !!!
+ # TODO: actually accept a PixelType
+ c = core.GP_ContextAlloc(w, h, pixeltype_no)
+ return cls(c, owns_GP_Context=True)
+
+ @classmethod
+ def load(cls, filename):
+ "Load image from given file, guess type."
+ c = loaders.GP_LoadImage_SWIG(filename)
+ if not c:
+ raise Exception("Error loading %r", filename)
+ return cls(c, owns_GP_Context=True)
+
http://repo.or.cz/w/gfxprim.git/commit/64ec17d6274119e321accf352b452b0a4d66…
commit 64ec17d6274119e321accf352b452b0a4d664097
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Thu Nov 24 23:20:06 2011 +0100
C wrapper for GP_LoadImage
diff --git a/include/loaders/gfxprim_loaders.swig b/include/loaders/gfxprim_loaders.swig
index 6ac382c..5eb10e1 100644
--- a/include/loaders/gfxprim_loaders.swig
+++ b/include/loaders/gfxprim_loaders.swig
@@ -14,6 +14,19 @@
%nodefaultctor;
%include "GP_Loaders.h"
+
+%{
+GP_Context *GP_LoadImage_SWIG(const char *src_path)
+{
+ GP_Context *c = NULL;
+ if (GP_LoadImage(src_path, &c, NULL) != 0)
+ return NULL;
+ return c;
+}
+%}
+
+GP_Context *GP_LoadImage_SWIG(const char *src_path);
+
%include "GP_JPG.h"
%include "GP_PBM.h"
%include "GP_PGM.h"
http://repo.or.cz/w/gfxprim.git/commit/040d6abf67aeacd29d59f99b9c991ae60e1f…
commit 040d6abf67aeacd29d59f99b9c991ae60e1f664c
Author: Tomas Gavenciak <gavento(a)ucw.cz>
Date: Thu Nov 24 23:19:37 2011 +0100
Renaming wrappers around
diff --git a/include/core/gfxprim_core.swig b/include/core/gfxprim_core.swig
index d09d94f..2a96a71 100644
--- a/include/core/gfxprim_core.swig
+++ b/include/core/gfxprim_core.swig
@@ -1,4 +1,4 @@
-%module gfxprim_core
+%module gfxprim_core_c
%{
#include "core/GP_Core.h"
@@ -8,6 +8,8 @@
%include <stdint.i>
+%nodefaultctor;
+
/* Basic types and common methods */
%include "GP_Common.h"
diff --git a/include/core/swigify.sh b/include/core/swigify.sh
index a82e16e..d275dc4 100755
--- a/include/core/swigify.sh
+++ b/include/core/swigify.sh
@@ -2,8 +2,8 @@ set -e
swig -python -Wall -I/usr/include/ gfxprim_core.swig
gcc -shared gfxprim_core_wrap.c -L ../../build/ -I /usr/include/python2.6/ -I.. - -lGP -lpng -ljpeg -lm -ldl -o ../../build/_gfxprim_core.so
-mv gfxprim_core.py ../../build/
+ -fPIC -Wall -lGP -lpng -ljpeg -lm -ldl -o ../../build/_gfxprim_core_c.so
+mv gfxprim_core_c.py ../../pylib/
rm gfxprim_core_wrap.c
echo Swigified!
diff --git a/include/loaders/gfxprim_loaders.swig b/include/loaders/gfxprim_loaders.swig
index 28e57b4..6ac382c 100644
--- a/include/loaders/gfxprim_loaders.swig
+++ b/include/loaders/gfxprim_loaders.swig
@@ -1,4 +1,4 @@
-%module gfxprim_loaders
+%module gfxprim_loaders_c
%{
#include "core/GP_Core.h"
@@ -11,6 +11,8 @@
%include <stdint.i>
+%nodefaultctor;
+
%include "GP_Loaders.h"
%include "GP_JPG.h"
%include "GP_PBM.h"
diff --git a/include/loaders/swigify.sh b/include/loaders/swigify.sh
index 3308274..e0514ec 100755
--- a/include/loaders/swigify.sh
+++ b/include/loaders/swigify.sh
@@ -2,8 +2,8 @@ set -e
swig -python -Wall -I/usr/include/ gfxprim_loaders.swig
gcc -shared gfxprim_loaders_wrap.c -L ../../build/ -I /usr/include/python2.6/ -I.. - -lGP -lpng -ljpeg -lm -ldl -o ../../build/_gfxprim_loaders.so
-mv gfxprim_loaders.py ../../build/
+ -fPIC -Wall -lGP -lpng -ljpeg -lm -ldl -o ../../build/_gfxprim_loaders_c.so
+mv gfxprim_loaders_c.py ../../pylib/
rm gfxprim_loaders_wrap.c
echo Swigified!
diff --git a/pylib/_gfxprim_core_c.so b/pylib/_gfxprim_core_c.so
new file mode 120000
index 0000000..b0aff10
--- /dev/null
+++ b/pylib/_gfxprim_core_c.so
@@ -0,0 +1 @@
+../build/_gfxprim_core_c.so
No newline at end of file
diff --git a/pylib/_gfxprim_loaders_c.so b/pylib/_gfxprim_loaders_c.so
new file mode 120000
index 0000000..41a41f9
--- /dev/null
+++ b/pylib/_gfxprim_loaders_c.so
@@ -0,0 +1 @@
+../build/_gfxprim_loaders_c.so
No newline at end of file
-----------------------------------------------------------------------
Summary of changes:
include/core/gfxprim_core.swig | 4 +-
include/core/swigify.sh | 4 +-
include/loaders/gfxprim_loaders.swig | 17 ++++++-
include/loaders/swigify.sh | 4 +-
pylib/_gfxprim_core_c.so | 1 +
pylib/_gfxprim_loaders_c.so | 1 +
pylib/context.py | 94 ++++++++++++++++++++++++++++++++++
7 files changed, 119 insertions(+), 6 deletions(-)
create mode 120000 pylib/_gfxprim_core_c.so
create mode 120000 pylib/_gfxprim_loaders_c.so
create mode 100644 pylib/context.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