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/9fb8ec2881f24724d6fe71bbfecb7524e9505...
commit 9fb8ec2881f24724d6fe71bbfecb7524e95053a7 Merge: 22d47ec 3cca227 Author: Tomas Gavenciak gavento@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/22d47ec8e304affafa567d890965992088bd0...
commit 22d47ec8e304affafa567d890965992088bd08a6 Author: Tomas Gavenciak gavento@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/64ec17d6274119e321accf352b452b0a4d664...
commit 64ec17d6274119e321accf352b452b0a4d664097 Author: Tomas Gavenciak gavento@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/040d6abf67aeacd29d59f99b9c991ae60e1f6...
commit 040d6abf67aeacd29d59f99b9c991ae60e1f664c Author: Tomas Gavenciak gavento@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@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.