From 36e023ad7af10181a8aa44b149fb25f003665198 Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Wed, 22 Apr 2009 17:28:37 +0000 Subject: Add binary blobs selector --- (limited to 'fill') diff --git a/fill/Makefile b/fill/Makefile new file mode 100644 index 0000000..e437f99 --- /dev/null +++ b/fill/Makefile @@ -0,0 +1,70 @@ +#Copyright 2007, NATE-LSI-EPUSP + +#Oficina is developed in Brazil at Escola Politécnica of +#Universidade de São Paulo. NATE is part of LSI (Integrable +#Systems Laboratory) and stands for Learning, Work and Entertainment +#Research Group. Visit our web page: +#www.nate.lsi.usp.br +#Suggestions, bugs and doubts, please email oficina@lsi.usp.br + +#Oficina is free software; you can redistribute it and/or +#modify it under the terms of the GNU General Public License +#as published by the Free Software Foundation version 2 of +#the License. + +#Oficina is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +#General Public License for more details. + +#You should have received a copy of the GNU General Public +#License along with Oficina; if not, write to the +#Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +#Boston, MA 02110-1301 USA. +#The copy of the GNU General Public License is found in the +#COPYING file included in the source distribution. + + +#Authors: + +#Joyce Alessandra Saul (joycealess@gmail.com) +#Andre Mossinato (andremossinato@gmail.com) +#Nathalia Sautchuk Patrício (nathalia.sautchuk@gmail.com) +#Pedro Kayatt (pekayatt@gmail.com) +#Rafael Barbolo Lopes (barbolo@gmail.com) +#Alexandre A. Gonçalves Martinazzo (alexandremartinazzo@gmail.com) + +CFLAGS = $(shell pkg-config --cflags gtk+-2.0 pygtk-2.0) \ + $(shell python-config --cflags) \ + -fPIC + +LDFLAGS = $(shell pkg-config --libs gtk+-2.0 pygtk-2.0) \ + $(shell python-config --libs) + +ARCH = $(shell arch | grep 64 >/dev/null && echo linux64 || echo linux32) +PYTHON_VERSION = $(shell python -c 'import sys; print "%d%d" % sys.version_info[0:2]') +LIB_DIR = $(ARCH)_$(PYTHON_VERSION) + +all: _fill.so + rm -rf $(LIB_DIR) + mkdir $(LIB_DIR) + strip -s _fill.so + mv _fill.so $(LIB_DIR)/ + touch $(LIB_DIR)/__init__.py + +_fill.so: fill.o eggfill.o fillmodule.o + $(LD) $(LDFLAGS) -shared $^ -o $@ + +DEFS=`pkg-config --variable=defsdir pygtk-2.0` +# Generate the C wrapper +fill.c: fill.defs fill.override + pygtk-codegen-2.0 --prefix fill \ + --register $(DEFS)/gdk-types.defs \ + --register $(DEFS)/gdk-base.defs \ + --register $(DEFS)/gtk-types.defs \ + --override fill.override \ + fill.defs > $@ + +clean: + rm -f *.so *.o fill.c *~ + diff --git a/fill/__init__.py b/fill/__init__.py new file mode 100644 index 0000000..34b4d37 --- /dev/null +++ b/fill/__init__.py @@ -0,0 +1,21 @@ +import os +import sys +import logging + +_sys_path = sys.path +_root_path = os.path.dirname(__file__) + +for i in os.listdir(_root_path): + path = os.path.join(_root_path, i) + if (os.path.isdir(path)): + sys.path = _sys_path + [os.path.join('.', path)] + try: + from _fill import * + logging.debug('use %s blobs' % path) + _sys_path = None + break + except Exception, e: + logging.debug('skip %s blobs: %s' % (path, e)) + +if _sys_path: + raise('cannot find proper binary blobs') diff --git a/fill/eggfill.c b/fill/eggfill.c new file mode 100644 index 0000000..5de388d --- /dev/null +++ b/fill/eggfill.c @@ -0,0 +1,189 @@ +/* +eggfill.c + +Fill function and queue list + + +Copyright 2007, NATE-LSI-EPUSP + +Oficina is developed in Brazil at Escola Politécnica of +Universidade de São Paulo. NATE is part of LSI (Integrable +Systems Laboratory) and stands for Learning, Work and Entertainment +Research Group. Visit our web page: +www.lsi.usp.br/nate +Suggestions, bugs and doubts, please email oficina@lsi.usp.br + +Oficina is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation version 2 of +the License. + +Oficina is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public +License along with Oficina; if not, write to the +Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +Boston, MA 02110-1301 USA. +The copy of the GNU General Public License is found in the +COPYING file included in the source distribution. + + +Authors: + +Joyce Alessandra Saul (joycealess@gmail.com) +Andre Mossinato (andremossinato@gmail.com) +Nathalia Sautchuk Patrício (nathalia.sautchuk@gmail.com) +Pedro Kayatt (pekayatt@gmail.com) +Rafael Barbolo Lopes (barbolo@gmail.com) +Alexandre A. Gonçalves Martinazzo (alexandremartinazzo@gmail.com) + +Colaborators: +Bruno Gola (brunogola@gmail.com) + +Group Manager: +Irene Karaguilla Ficheman (irene@lsi.usp.br) + +Cientific Coordinator: +Roseli de Deus Lopes (roseli@lsi.usp.br) + +*/ + +#include +#include "eggfill.h" + +#define front(q) ( (q)->front ) +#define rear(q) ( (q)->rear ) + +/* this queue has a Header that points to the Front and Rear elements */ +/* empty queue: q->front = NULL and q->rear = NULL */ + +/* check if queue q is empty */ +int queue_is_empty(queue *q){ + return ((front(q)==NULL) && (rear(q)==NULL)); +} + +queue *queue_init(void){ + queue *q; + q = (queue*)malloc(sizeof(queue)); + /* check if there is enough space */ + if( q == NULL ) + printf( "Out of space!!!" ); + q->front = NULL; + q->rear = NULL; + + return q; +} + +void queue_destroy(queue *q){ + queue_make_empty(q); + free(q); +} + +void queue_make_empty(queue *q){ + if( q == NULL ) + printf( "Must use CreateQueue first" ); + else + while( !queue_is_empty(q) ) + queue_dequeue(q); +} + + +void queue_enqueue(int element, queue *q){ + no *tmp; + tmp = (no*)malloc(sizeof(no)); + if(tmp == NULL) { + printf("Out of space!!!"); + return; + } else { + tmp->info = element; + tmp->next = NULL; + if (queue_is_empty(q)){ + q->front = tmp; + } else { + q->rear->next = tmp; + } + q->rear = tmp; + } +} + +void queue_dequeue(queue *q){ + if(queue_is_empty(q)) { + printf( "Empty queue" ); + } + else { + no *tmp = q->front; + q->front = q->front->next; + if (q->front==NULL) { + q->rear=NULL; + } + free(tmp); + } +}/* end of queue*/ + +void fill(GdkDrawable *drawable, GdkGC *gc, int x, int y, int width, int height, int color){ + + printf("Entrando no fill\n"); + int color_start; + queue *lista_xy; + + lista_xy = queue_init(); + + GdkImage *image; + image = gdk_drawable_get_image(drawable,0,0,width,height); + printf("0x%x\n", image); + + color_start = gdk_image_get_pixel(image, x, y); + + if (color!=color_start) { + queue_enqueue(x, lista_xy); + queue_enqueue(y, lista_xy); + gdk_image_put_pixel(image, x, y, color); + while (!queue_is_empty(lista_xy)) { + if (x+1 < width){ + if (gdk_image_get_pixel(image, x+1, y) == color_start){ + gdk_image_put_pixel(image, x+1, y, color); + queue_enqueue(x+1, lista_xy); + queue_enqueue(y, lista_xy); + } + } + + if (x-1 >= 0){ + if (gdk_image_get_pixel(image, x-1, y) == color_start){ + gdk_image_put_pixel(image, x-1, y, color); + queue_enqueue(x-1, lista_xy); + queue_enqueue(y, lista_xy); + } + } + if (y+1 < height){ + if (gdk_image_get_pixel(image, x, y+1) == color_start){ + gdk_image_put_pixel(image, x, y+1, color); + queue_enqueue(x, lista_xy); + queue_enqueue(y+1, lista_xy); + } + } + if (y-1 >= 0){ + if (gdk_image_get_pixel(image, x, y-1) == color_start){ + gdk_image_put_pixel(image, x, y-1, color); + queue_enqueue(x, lista_xy); + queue_enqueue(y-1, lista_xy); + } + } + x = lista_xy->front->info; + queue_dequeue(lista_xy); + y = lista_xy->front->info; + queue_dequeue(lista_xy); + } + } + gdk_draw_image(drawable, gc, image, 0,0,0,0,width,height); + if (image != NULL) { + g_object_unref(image); + printf("Imagem %x\n", image); + } else { + printf("Image = null\n"); + } + queue_destroy(lista_xy); +} + diff --git a/fill/eggfill.h b/fill/eggfill.h new file mode 100644 index 0000000..1836043 --- /dev/null +++ b/fill/eggfill.h @@ -0,0 +1,77 @@ +/* +eggfill.h + +Fill function and queue list + + +Copyright 2007, NATE-LSI-EPUSP + +Oficina is developed in Brazil at Escola Politécnica of +Universidade de São Paulo. NATE is part of LSI (Integrable +Systems Laboratory) and stands for Learning, Work and Entertainment +Research Group. Visit our web page: +www.lsi.usp.br/nate +Suggestions, bugs and doubts, please email oficina@lsi.usp.br + +Oficina is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation version 2 of +the License. + +Oficina is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public +License along with Oficina; if not, write to the +Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +Boston, MA 02110-1301 USA. +The copy of the GNU General Public License is found in the +COPYING file included in the source distribution. + + +Authors: + +Joyce Alessandra Saul (joycealess@gmail.com) +Andre Mossinato (andremossinato@gmail.com) +Nathalia Sautchuk Patrício (nathalia.sautchuk@gmail.com) +Pedro Kayatt (pekayatt@gmail.com) +Rafael Barbolo Lopes (barbolo@gmail.com) +Alexandre A. Gonçalves Martinazzo (alexandremartinazzo@gmail.com) + +Colaborators: +Bruno Gola (brunogola@gmail.com) + +Group Manager: +Irene Karaguilla Ficheman (irene@lsi.usp.br) + +Cientific Coordinator: +Roseli de Deus Lopes (roseli@lsi.usp.br) + +*/ +#include +#include +#include + +/*to implement a queue */ +typedef struct _tno { + int info; + struct _tno *next; +} no; + +typedef struct _tqueue{ + no *front; + no *rear; +} queue; + + +int queue_is_empty(queue *q); +queue *queue_init(void); +void disposequeue(queue *q); +void queue_make_empty(queue *q); +void queue_enqueue(int element, queue *q); +void queue_dequeue(queue *q); +/*end of queue*/ + +void fill(GdkDrawable *drawable, GdkGC *gc, int x, int y, int width, int height, int color); diff --git a/fill/fill.c b/fill/fill.c new file mode 100644 index 0000000..39c4e34 --- /dev/null +++ b/fill/fill.c @@ -0,0 +1,79 @@ +/* -- THIS FILE IS GENERATED - DO NOT EDIT *//* -*- Mode: C; c-basic-offset: 4 -*- */ + +#include + + + +#line 3 "fill.override" +#include +#include +#include "pygobject.h" +#include "eggfill.h" +#line 13 "fill.c" + + +/* ---------- types from other modules ---------- */ +static PyTypeObject *_PyGdkDrawable_Type; +#define PyGdkDrawable_Type (*_PyGdkDrawable_Type) +static PyTypeObject *_PyGdkGC_Type; +#define PyGdkGC_Type (*_PyGdkGC_Type) + + +/* ---------- forward type declarations ---------- */ + +#line 25 "fill.c" + + + +/* ----------- functions ----------- */ + +static PyObject * +_wrap_fill(PyObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "drawable", "gc", "x", "y", "width", "height", "color", NULL }; + PyGObject *drawable, *gc; + int x, y, width, height, color; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!O!iiiii:fill", kwlist, &PyGdkDrawable_Type, &drawable, &PyGdkGC_Type, &gc, &x, &y, &width, &height, &color)) + return NULL; + + fill(GDK_DRAWABLE(drawable->obj), GDK_GC(gc->obj), x, y, width, height, color); + + Py_INCREF(Py_None); + return Py_None; +} + +const PyMethodDef fill_functions[] = { + { "fill", (PyCFunction)_wrap_fill, METH_VARARGS|METH_KEYWORDS, + NULL }, + { NULL, NULL, 0, NULL } +}; + +/* initialise stuff extension classes */ +void +fill_register_classes(PyObject *d) +{ + PyObject *module; + + if ((module = PyImport_ImportModule("gtk.gdk")) != NULL) { + _PyGdkDrawable_Type = (PyTypeObject *)PyObject_GetAttrString(module, "Drawable"); + if (_PyGdkDrawable_Type == NULL) { + PyErr_SetString(PyExc_ImportError, + "cannot import name Drawable from gtk.gdk"); + return ; + } + _PyGdkGC_Type = (PyTypeObject *)PyObject_GetAttrString(module, "GC"); + if (_PyGdkGC_Type == NULL) { + PyErr_SetString(PyExc_ImportError, + "cannot import name GC from gtk.gdk"); + return ; + } + } else { + PyErr_SetString(PyExc_ImportError, + "could not import gtk.gdk"); + return ; + } + + +#line 79 "fill.c" +} diff --git a/fill/fill.defs b/fill/fill.defs new file mode 100644 index 0000000..d2ebadf --- /dev/null +++ b/fill/fill.defs @@ -0,0 +1,22 @@ +;; -*- scheme -*- +; object definitions ... +;; Enumerations and flags ... + + +;; From eggfill.h + +(define-function fill + (c-name "fill") + (return-type "none") + (parameters + '("GdkDrawable*" "drawable") + '("GdkGC*" "gc") + '("int" "x") + '("int" "y") + '("int" "width") + '("int" "height") + '("int" "color") + ) +) + + diff --git a/fill/fill.override b/fill/fill.override new file mode 100644 index 0000000..3de606c --- /dev/null +++ b/fill/fill.override @@ -0,0 +1,15 @@ +%% +headers +#include +#include +#include "pygobject.h" +#include "eggfill.h" +%% +modulename _fill +%% +import gtk.gdk.Drawable as PyGdkDrawable_Type +import gtk.gdk.GC as PyGdkGC_Type +%% +ignore-glob + *_get_type +%% diff --git a/fill/fillmodule.c b/fill/fillmodule.c new file mode 100644 index 0000000..b23bfd7 --- /dev/null +++ b/fill/fillmodule.c @@ -0,0 +1,71 @@ +/* +Fill wrapper + + +Copyright 2007, NATE-LSI-EPUSP + +Oficina is developed in Brazil at Escola Politécnica of +Universidade de São Paulo. NATE is part of LSI (Integrable +Systems Laboratory) and stands for Learning, Work and Entertainment +Research Group. Visit our web page: +www.lsi.usp.br/nate +Suggestions, bugs and doubts, please email oficina@lsi.usp.br + +Oficina is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation version 2 of +the License. + +Oficina is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public +License along with Oficina; if not, write to the +Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +Boston, MA 02110-1301 USA. +The copy of the GNU General Public License is found in the +COPYING file included in the source distribution. + + +Authors: + +Joyce Alessandra Saul (joycealess@gmail.com) +Andre Mossinato (andremossinato@gmail.com) +Nathalia Sautchuk Patrício (nathalia.sautchuk@gmail.com) +Pedro Kayatt (pekayatt@gmail.com) +Rafael Barbolo Lopes (barbolo@gmail.com) +Alexandre A. Gonçalves Martinazzo (alexandremartinazzo@gmail.com) +Bruno Gola (brunogola@gmail.com) + +Group Manager: +Irene Karaguilla Ficheman (irene@lsi.usp.br) + +Cientific Coordinator: +Roseli de Deus Lopes (roseli@lsi.usp.br) + +*/ +#include + +void fill_register_classes (PyObject *d); + +extern PyMethodDef fill_functions[]; + +DL_EXPORT(void) +init_fill(void) +{ + PyObject *m, *d; + + init_pygobject (); + + m = Py_InitModule ("_fill", fill_functions); + d = PyModule_GetDict (m); + + fill_register_classes (d); + + if (PyErr_Occurred ()) { + Py_FatalError ("can't initialise module fill"); + } + +} -- cgit v0.9.1