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 ed8672e72135a52839ca300b6e1253ae9cecad1a (commit) via 3fb898da008ec9e178806abe426fe79a28caa294 (commit) via 2255767fb838329bd6c40f7b813763f652ac400f (commit) from 3088a1c77b7ad67a580c40f65d8e9d84d218ba3d (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/ed8672e72135a52839ca300b6e1253ae9ceca...
commit ed8672e72135a52839ca300b6e1253ae9cecad1a Author: Tomas Gavenciak gavento@ucw.cz Date: Fri Feb 24 01:00:50 2012 +0100
Finish importing from *_c, rename gfxprim_core_c to core_c
diff --git a/pylib/gfxprim/core/__init__.py b/pylib/gfxprim/core/__init__.py index 7764673..cce62d2 100644 --- a/pylib/gfxprim/core/__init__.py +++ b/pylib/gfxprim/core/__init__.py @@ -1,4 +1,4 @@ -from . import gfxprim_core_c as core_c +from . import core_c
Context = core_c.Context
@@ -7,14 +7,14 @@ from . import extend_context extend_context.extend_context_class(Context) del extend_context
+# Import some members from the SWIG module def import_helper(module): from ..utils import import_members
+ # Constants (TODO consider a separate module) const_regexes = [ '^GP_[A-Z0-9_]*$', '^GP_PIXEL_x[A-Z0-9_]*$'] - - # Constants, consider a separate module C = {} module['C'] = C import_members(core_c, C, include=const_regexes) @@ -29,6 +29,5 @@ def import_helper(module): '^w+_swigregister$', '^cvar$', '^_w+$']) - import_helper(locals()) del import_helper diff --git a/pylib/gfxprim/core/gfxprim_core.swig b/pylib/gfxprim/core/core.swig similarity index 99% rename from pylib/gfxprim/core/gfxprim_core.swig rename to pylib/gfxprim/core/core.swig index 0208cec..481ab1b 100644 --- a/pylib/gfxprim/core/gfxprim_core.swig +++ b/pylib/gfxprim/core/core.swig @@ -1,4 +1,4 @@ -%module gfxprim_core_c +%module core_c
%{ #include "core/GP_Core.h" diff --git a/pylib/gfxprim/core/extend_context.py b/pylib/gfxprim/core/extend_context.py index ecae2af..b72b5d2 100644 --- a/pylib/gfxprim/core/extend_context.py +++ b/pylib/gfxprim/core/extend_context.py @@ -1,5 +1,5 @@ from ..utils import extend, add_swig_getmethod, add_swig_setmethod -from . import gfxprim_core_c as core_c +from . import core_c
def extend_context_class(_context_class): """ diff --git a/pylib/gfxprim/loaders/__init__.py b/pylib/gfxprim/loaders/__init__.py index b1fd630..5f9de96 100644 --- a/pylib/gfxprim/loaders/__init__.py +++ b/pylib/gfxprim/loaders/__init__.py @@ -1,17 +1,33 @@ -from .. import core
-# HACK to allow gfxprim_loaders_c find gfxprim_core_c -def import_gfxprim_loaders_c_helper(): +# HACK to allow loaders_c to find core_c +def import_loaders_c_helper(): from os.path import dirname import sys oldpath = sys.path[:] sys.path.append(dirname(__file__) + '/../core') - from . import gfxprim_loaders_c as loaders_c + from . import loaders_c sys.path = oldpath return loaders_c -loaders_c = import_gfxprim_loaders_c_helper() +loaders_c = import_loaders_c_helper() +del import_loaders_c_helper
# Extend Context with convenience methods from . import extend_context -extend_context.extend_context_class(core.Context) +from ..core import Context +extend_context.extend_context_class(Context) +del Context del extend_context + +# Import some members from the SWIG module +def import_helper(module): + from ..utils import import_members + + # Functions + import_members(loaders_c, module, + exclude=[ + '^w+_swigregister$', + '^core_c$', + '^_w+$']) +import_helper(locals()) +del import_helper + diff --git a/pylib/gfxprim/loaders/gfxprim_loaders.swig b/pylib/gfxprim/loaders/gfxprim_loaders.swig deleted file mode 100644 index 5eb10e1..0000000 --- a/pylib/gfxprim/loaders/gfxprim_loaders.swig +++ /dev/null @@ -1,35 +0,0 @@ -%module gfxprim_loaders_c - -%{ -#include "core/GP_Core.h" -#include "loaders/GP_Loaders.h" -%} - -#define __attribute__(X) - -%import ../core/gfxprim_core.swig - -%include <stdint.i> - -%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" -%include "GP_PPM.h" -%include "GP_PNG.h" - diff --git a/pywrap.mk b/pywrap.mk index c99293d..3376c78 100644 --- a/pywrap.mk +++ b/pywrap.mk @@ -2,15 +2,20 @@ ifndef LIBNAME $(error LIBNAME not defined, fix your library Makefile) endif
+SWIG_SRC=$(LIBNAME).swig +SWIG_PY=$(LIBNAME)_c.py +SWIG_C=$(LIBNAME)_wrap.c +SWIG_LIB=_$(LIBNAME)_c.so + include $(TOPDIR)/config.gen.mk
ifneq ($(SWIG),)
INCLUDES+=$(addprefix -I$(TOPDIR)/include/, $(INCLUDE))
-all: _gfxprim_$(LIBNAME)_c.so gfxprim_$(LIBNAME)_c.py +all: $(SWIG_LIB) $(SWIG_PY)
-gfxprim_$(LIBNAME)_wrap.c gfxprim_$(LIBNAME)_c.py: gfxprim_$(LIBNAME).swig +$(SWIG_C) $(SWIG_PY): $(SWIG_SRC) ifdef VERBOSE $(SWIG) $(SWIGOPTS) -python $(INCLUDES) $< else # VERBOSE @@ -18,14 +23,14 @@ else # VERBOSE @$(SWIG) $(SWIGOPTS) -python $(INCLUDES) $< endif # VERBOSE
-_gfxprim_$(LIBNAME)_c.so: gfxprim_$(LIBNAME)_wrap.c +$(SWIG_LIB): $(SWIG_C) ifdef VERBOSE - $(CC) gfxprim_$(LIBNAME)_wrap.c $(CFLAGS) $(LDFLAGS) -I$(PYTHON_INCLUDE) --shared -lGP -L$(TOPDIR)/build/ -o _gfxprim_$(LIBNAME)_c.so + $(CC) $< $(CFLAGS) $(LDFLAGS) -I$(PYTHON_INCLUDE) --shared -lGP -L$(TOPDIR)/build/ -o $@ else # VERBOSE @echo "LD $@" - @$(CC) gfxprim_$(LIBNAME)_wrap.c $(CFLAGS) $(LDFLAGS) -I$(PYTHON_INCLUDE) --shared -lGP -L$(TOPDIR)/build/ -o _gfxprim_$(LIBNAME)_c.so + @$(CC) $< $(CFLAGS) $(LDFLAGS) -I$(PYTHON_INCLUDE) --shared -lGP -L$(TOPDIR)/build/ -o $@ endif # VERBOSE
endif # ifneq ($(SWIG),)
-CLEAN+=gfxprim_$(LIBNAME)_wrap.c gfxprim_$(LIBNAME)_c.py _gfxprim_$(LIBNAME)_c.so +CLEAN+=$(SWIG_C) $(SWIG_PY) $(SWIG_LIB)
http://repo.or.cz/w/gfxprim.git/commit/3fb898da008ec9e178806abe426fe79a28caa...
commit 3fb898da008ec9e178806abe426fe79a28caa294 Author: Tomas Gavenciak gavento@ucw.cz Date: Fri Feb 24 00:58:19 2012 +0100
Rename GP_LoadImage_SWIG to GP_LoadImage_Wrap
diff --git a/pylib/gfxprim/loaders/extend_context.py b/pylib/gfxprim/loaders/extend_context.py index 1ea7aeb..a7df590 100644 --- a/pylib/gfxprim/loaders/extend_context.py +++ b/pylib/gfxprim/loaders/extend_context.py @@ -1,5 +1,5 @@ from ..utils import extend, add_swig_getmethod, add_swig_setmethod -from . import gfxprim_loaders_c as loaders_c +from . import loaders_c
def extend_context_class(_context_class): """ @@ -11,7 +11,7 @@ def extend_context_class(_context_class): @staticmethod def load(filename): "Load image from given file, guess type." - c = loaders_c.GP_LoadImage_SWIG(filename) + c = loaders_c.GP_LoadImage_Wrap(filename) return c
@extend(_context_class) diff --git a/pylib/gfxprim/loaders/loaders.swig b/pylib/gfxprim/loaders/loaders.swig new file mode 100644 index 0000000..1f171a3 --- /dev/null +++ b/pylib/gfxprim/loaders/loaders.swig @@ -0,0 +1,35 @@ +%module loaders_c + +%{ +#include "core/GP_Core.h" +#include "loaders/GP_Loaders.h" +%} + +#define __attribute__(X) + +%import ../core/core.swig + +%include <stdint.i> + +%nodefaultctor; + +%include "GP_Loaders.h" + +%{ +GP_Context *GP_LoadImage_Wrap(const char *src_path) +{ + GP_Context *c = NULL; + if (GP_LoadImage(src_path, &c, NULL) != 0) + return NULL; + return c; +} +%} + +GP_Context *GP_LoadImage_Wrap(const char *src_path); + +%include "GP_JPG.h" +%include "GP_PBM.h" +%include "GP_PGM.h" +%include "GP_PPM.h" +%include "GP_PNG.h" +
http://repo.or.cz/w/gfxprim.git/commit/2255767fb838329bd6c40f7b813763f652ac4...
commit 2255767fb838329bd6c40f7b813763f652ac400f Author: Tomas Gavenciak gavento@ucw.cz Date: Fri Feb 24 00:30:41 2012 +0100
Basic context extending and improting SWIG functions
diff --git a/pylib/gfxprim/core/__init__.py b/pylib/gfxprim/core/__init__.py index e69de29..7764673 100644 --- a/pylib/gfxprim/core/__init__.py +++ b/pylib/gfxprim/core/__init__.py @@ -0,0 +1,34 @@ +from . import gfxprim_core_c as core_c + +Context = core_c.Context + +# Extend Context with convenience methods +from . import extend_context +extend_context.extend_context_class(Context) +del extend_context + +def import_helper(module): + from ..utils import import_members + + const_regexes = [ + '^GP_[A-Z0-9_]*$', + '^GP_PIXEL_x[A-Z0-9_]*$'] + + # Constants, consider a separate module + C = {} + module['C'] = C + import_members(core_c, C, include=const_regexes) + + # Functions + import_members(core_c, module, + exclude=const_regexes + [ + '^GP_Blitw+$', + '^GP_Contextw+$', + '^GP_PixelSNPrintw+$', + '^GP_WritePixelsw+$', + '^w+_swigregister$', + '^cvar$', + '^_w+$']) + +import_helper(locals()) +del import_helper diff --git a/pylib/gfxprim/core/context.py b/pylib/gfxprim/core/context.py deleted file mode 100644 index d65008a..0000000 --- a/pylib/gfxprim/core/context.py +++ /dev/null @@ -1,121 +0,0 @@ -import gfxprim_core_c as core -import gfxprim_loaders_c as loaders - -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 - -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 - -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. - """ - - # Add "parent" attribute - 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.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, None, x, y, w, h) - c.parent = self - 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 - return core.GP_ContextConvert(self, pixeltype_no) - - - @extend(_context_class) - def save(self, filename, format=None): - """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. - """ - if not format: - format = filename.rsplit('.', 1)[-1] - format = format.lower() - if format == 'jpg': - res = loaders.GP_SaveJPG(filename, self, None) - elif format == 'png': - res = loaders.GP_SavePNG(filename, self, None) - elif format == 'pbm': - res = loaders.GP_SavePBM(filename, self, None) - elif format == 'pgm': - res = loaders.GP_SavePGM(filename, self, None) - elif format == 'ppm': - 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) - - @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 c - - @extend(_context_class, name='load') - @staticmethod - def load(filename): - "Load image from given file, guess type." - c = loaders.GP_LoadImage_SWIG(filename) - return c - - - -extend_context_class() - diff --git a/pylib/gfxprim/core/extend_context.py b/pylib/gfxprim/core/extend_context.py new file mode 100644 index 0000000..ecae2af --- /dev/null +++ b/pylib/gfxprim/core/extend_context.py @@ -0,0 +1,59 @@ +from ..utils import extend, add_swig_getmethod, add_swig_setmethod +from . import gfxprim_core_c as core_c + +def extend_context_class(_context_class): + """ + Extends _context_class class with core module methods and properties + for object-oriented usage. + Called once on module inicialization. + """ + + # Add "parent" attribute + 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.thisown else "not ", + "with" if self.parent else "no") + + @add_swig_getmethod(_context_class) + def w(self): + return core_c.GP_ContextW(self) + + @add_swig_getmethod(_context_class) + def h(self): + return core_c.GP_ContextH(self) + + @extend(_context_class) + def subcontext(self, x, y, w, h): + "Create a subcontext (rectangular view)." + c = core_c.GP_ContextSubContext(self, None, x, y, w, h) + c.parent = self + return c + + @extend(_context_class) + def copy(self, withdata): + "Copy the context to a new context. Pixel data are copie optionally." + flags = core_c.GP_COPY_WITH_PIXELS if withdata else 0 + return core_c.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 + return core_c.GP_ContextConvert(self, pixeltype_no) + + @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_c.GP_ContextAlloc(w, h, pixeltype_no) + return c + diff --git a/pylib/gfxprim/loaders/__init__.py b/pylib/gfxprim/loaders/__init__.py index e69de29..b1fd630 100644 --- a/pylib/gfxprim/loaders/__init__.py +++ b/pylib/gfxprim/loaders/__init__.py @@ -0,0 +1,17 @@ +from .. import core + +# HACK to allow gfxprim_loaders_c find gfxprim_core_c +def import_gfxprim_loaders_c_helper(): + from os.path import dirname + import sys + oldpath = sys.path[:] + sys.path.append(dirname(__file__) + '/../core') + from . import gfxprim_loaders_c as loaders_c + sys.path = oldpath + return loaders_c +loaders_c = import_gfxprim_loaders_c_helper() + +# Extend Context with convenience methods +from . import extend_context +extend_context.extend_context_class(core.Context) +del extend_context diff --git a/pylib/gfxprim/loaders/extend_context.py b/pylib/gfxprim/loaders/extend_context.py new file mode 100644 index 0000000..1ea7aeb --- /dev/null +++ b/pylib/gfxprim/loaders/extend_context.py @@ -0,0 +1,41 @@ +from ..utils import extend, add_swig_getmethod, add_swig_setmethod +from . import gfxprim_loaders_c as loaders_c + +def extend_context_class(_context_class): + """ + Extends _context_class class with loader module methods for calling convenience. + Called once on loaders module inicialization. + """ + + @extend(_context_class, name='load') + @staticmethod + def load(filename): + "Load image from given file, guess type." + c = loaders_c.GP_LoadImage_SWIG(filename) + return c + + @extend(_context_class) + def save(self, filename, format=None): + """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. + """ + if not format: + format = filename.rsplit('.', 1)[-1] + format = format.lower() + if format == 'jpg': + res = loaders_c.GP_SaveJPG(filename, self, None) + elif format == 'png': + res = loaders_c.GP_SavePNG(filename, self, None) + elif format == 'pbm': + res = loaders_c.GP_SavePBM(filename, self, None) + elif format == 'pgm': + res = loaders_c.GP_SavePGM(filename, self, None) + elif format == 'ppm': + res = loaders_c.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) + diff --git a/pylib/gfxprim/utils.py b/pylib/gfxprim/utils.py new file mode 100644 index 0000000..d48aa0e --- /dev/null +++ b/pylib/gfxprim/utils.py @@ -0,0 +1,63 @@ +""" +Utility methods for polishing SWIGified gfxprim. +""" + +def extend(cls, name=None): + "Decorator extending a class with a function" + def decf(method): + funname = name + if not funname: + funname = method.__name__ + type.__setattr__(cls, funname, method) + return method + return decf + +def add_swig_getmethod(cls, name=None): + "Decorator to add a property get method to a SWIG-defined class" + def decf(method): + propname = name + if not propname: + propname = method.__name__ + cls.__swig_getmethods__[propname] = method + return decf + +def add_swig_setmethod(cls, name=None): + "Decorator to add a property set method to a SWIG-defined class" + def decf(method): + propname = name + if not propname: + propname = method.__name__ + cls.__swig_setmethods__[propname] = method + return decf + +def import_members(from_, to, include=[], exclude=[]): + """Import members of `from_` to `to`. By default take all. If `exclude` is provided, + use as a filter. If `include` is provided, ONLY include those. + `include` and `exclude` are lists of regexes to match (include ^ and $).""" + assert not (include and exclude) + import re + il = map(re.compile, include) + el = map(re.compile, exclude) + for name in dir(from_): + try: + o = from_[name] + except TypeError: + o = from_.__getattribute__(name) + + ok = True + if il: + ok = False + for x in il: + if x.match(name): + ok = True + if el: + for x in el: + if x.match(name): + ok = False + + if ok: + try: + to[name] = o + except TypeError: + to.__setattribute__(name, o) +
-----------------------------------------------------------------------
Summary of changes: pylib/gfxprim/core/__init__.py | 33 ++++++ pylib/gfxprim/core/context.py | 121 -------------------- .../gfxprim/core/{gfxprim_core.swig => core.swig} | 2 +- pylib/gfxprim/core/extend_context.py | 59 ++++++++++ pylib/gfxprim/loaders/__init__.py | 33 ++++++ pylib/gfxprim/loaders/extend_context.py | 41 +++++++ .../loaders/{gfxprim_loaders.swig => loaders.swig} | 8 +- pylib/gfxprim/utils.py | 63 ++++++++++ pywrap.mk | 17 ++- 9 files changed, 245 insertions(+), 132 deletions(-) delete mode 100644 pylib/gfxprim/core/context.py rename pylib/gfxprim/core/{gfxprim_core.swig => core.swig} (99%) create mode 100644 pylib/gfxprim/core/extend_context.py create mode 100644 pylib/gfxprim/loaders/extend_context.py rename pylib/gfxprim/loaders/{gfxprim_loaders.swig => loaders.swig} (68%) create mode 100644 pylib/gfxprim/utils.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.