Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Area.py90
-rw-r--r--fill/COMPILE.txt2
-rw-r--r--fill/Makefile12
-rw-r--r--fill/__init__.py4
-rw-r--r--fill/armv7l_27/__init__.py0
-rw-r--r--fill/armv7l_27/_fill.sobin7280 -> 0 bytes
-rw-r--r--fill/eggfill.c63
-rw-r--r--fill/eggfill.h3
-rw-r--r--fill/fill.c79
-rw-r--r--fill/fill.defs3
-rw-r--r--fill/fill.override5
-rw-r--r--fill/fillmodule.c59
-rw-r--r--fill/linux32_25/__init__.py0
-rw-r--r--fill/linux32_25/_fill.sobin7820 -> 0 bytes
-rw-r--r--fill/linux32_26/__init__.py0
-rw-r--r--fill/linux32_26/_fill.sobin7884 -> 0 bytes
-rw-r--r--fill/linux32_27/__init__.py0
-rw-r--r--fill/linux32_27/_fill.sobin8036 -> 0 bytes
-rw-r--r--fill/linux64_25/__init__.py0
-rw-r--r--fill/linux64_25/_fill.sobin14112 -> 0 bytes
-rw-r--r--fill/linux64_26/__init__.py0
-rw-r--r--fill/linux64_26/_fill.sobin14136 -> 0 bytes
-rwxr-xr-xfill/linux64_27/_fill.sobin10648 -> 6112 bytes
23 files changed, 120 insertions, 200 deletions
diff --git a/Area.py b/Area.py
index da55e36..c998837 100644
--- a/Area.py
+++ b/Area.py
@@ -82,13 +82,13 @@ from urlparse import urlparse
from sugar3.graphics import style
FALLBACK_FILL = True
-
-#try:
-# from fill import fill
-# FALLBACK_FILL = False
-#except:
-# logging.debug('No valid fill binaries. Using slower python code')
-# pass
+try:
+ from fill import fill
+ FALLBACK_FILL = False
+ logging.error('Found fill binaries.')
+except:
+ logging.error('No valid fill binaries. Using slower python code')
+ pass
##Tools and events manipulation are handle with this class.
@@ -737,16 +737,9 @@ class Area(Gtk.DrawingArea):
private_undo = True
elif self.tool['name'] == 'bucket':
- if FALLBACK_FILL:
- self.get_window().set_cursor(Gdk.Cursor.new(
- Gdk.CursorType.WATCH))
- GObject.idle_add(self.flood_fill, coords[0], coords[1])
- else:
- width, height = self.get_size()
- self.get_window().set_cursor(Gdk.Cursor.new(
- Gdk.CursorType.WATCH))
- GObject.idle_add(self.fast_flood_fill, self, coords[0],
- coords[1], width, height)
+ self.get_window().set_cursor(Gdk.Cursor.new(
+ Gdk.CursorType.WATCH))
+ GObject.idle_add(self.flood_fill, coords[0], coords[1])
elif self.tool['name'] == 'triangle':
self.d.triangle(self, coords, False, self.tool['fill'])
@@ -793,15 +786,6 @@ class Area(Gtk.DrawingArea):
self.queue_draw()
self.d.clear_control_points()
- def fast_flood_fill(self, widget, x, y, width, height):
- fill(self.pixmap, self.gc, x, y, width,
- height, self.gc_line.foreground.pixel)
- widget.queue_draw()
- self.enable_undo()
- display = Gdk.Display.get_default()
- cursor = Gdk.Cursor.new_from_name(display, 'paint-bucket')
- self.get_window().set_cursor(cursor)
-
def flood_fill(self, x, y):
stroke_color = self.tool['cairo_stroke_color']
r, g, b = stroke_color[0], stroke_color[1], stroke_color[2]
@@ -817,6 +801,7 @@ class Area(Gtk.DrawingArea):
for array_type in ['H', 'I', 'L']:
pixels = array.array(array_type)
if pixels.itemsize == 4:
+ _array_type_used = array_type
break
else:
raise AssertionError()
@@ -834,33 +819,42 @@ class Area(Gtk.DrawingArea):
width = self.drawing_canvas.get_width()
height = self.drawing_canvas.get_height()
- def within(x, y):
- if x < 0 or x >= width:
- return False
- if y < 0 or y >= height:
- return False
- return True
-
- if not within(x, y):
- return
- edge = [(x, y)]
-
old_color = pixels[x + y * width]
if old_color == fill_color:
logging.debug('Already filled')
return
- pixels[x + y * width] = fill_color
-
- while len(edge) > 0:
- newedge = []
- for (x, y) in edge:
- for (s, t) in ((x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)):
- if within(s, t) and \
- pixels[s + t * width] == old_color:
- pixels[s + t * width] = fill_color
- newedge.append((s, t))
- edge = newedge
+ if FALLBACK_FILL:
+ logging.debug('using python flood_fill')
+ def within(x, y):
+ if x < 0 or x >= width:
+ return False
+ if y < 0 or y >= height:
+ return False
+ return True
+
+ if not within(x, y):
+ return
+ edge = [(x, y)]
+
+ pixels[x + y * width] = fill_color
+
+ while len(edge) > 0:
+ newedge = []
+ for (x, y) in edge:
+ for (s, t) in ((x + 1, y), (x - 1, y), (x, y + 1),
+ (x, y - 1)):
+ if within(s, t) and \
+ pixels[s + t * width] == old_color:
+ pixels[s + t * width] = fill_color
+ newedge.append((s, t))
+ edge = newedge
+
+ else:
+ logging.debug('using c flood_fill')
+ pixels2 = fill(pixels, x, y, width, height, fill_color)
+ # the c implementation returns a list instead of array.array
+ pixels = array.array(_array_type_used, pixels2)
# create a updated drawing_canvas
self.drawing_canvas_data = cairo.ImageSurface.create_for_data(pixels,
diff --git a/fill/COMPILE.txt b/fill/COMPILE.txt
index 06117d2..77b383d 100644
--- a/fill/COMPILE.txt
+++ b/fill/COMPILE.txt
@@ -1,6 +1,6 @@
To compile
-yum install make gcc python-devel pygtk2-devel gtk2-devel
+yum install make gcc python-devel
make
diff --git a/fill/Makefile b/fill/Makefile
index 584f92a..1b61e14 100644
--- a/fill/Makefile
+++ b/fill/Makefile
@@ -34,12 +34,10 @@
#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 | sed 's/-pthread//') \
- $(shell python-config --cflags) \
+CFLAGS = $(shell python-config --cflags) \
-fPIC
-LDFLAGS = $(shell pkg-config --libs gtk+-2.0 pygtk-2.0 | sed 's/-pthread//') \
- $(shell python-config --libs)
+LDFLAGS = $(shell python-config --libs)
ARCH_OUT = $(shell arch)
@@ -62,13 +60,9 @@ all: _fill.so
_fill.so: fill.o eggfill.o fillmodule.o
$(LD) $(LDFLAGS) -shared $^ -o $@
-DEFS=`pkg-config --variable=defsdir pygtk-2.0`
+#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 > $@
diff --git a/fill/__init__.py b/fill/__init__.py
index 34b4d37..92b2eaf 100644
--- a/fill/__init__.py
+++ b/fill/__init__.py
@@ -11,11 +11,11 @@ for i in os.listdir(_root_path):
sys.path = _sys_path + [os.path.join('.', path)]
try:
from _fill import *
- logging.debug('use %s blobs' % path)
+ logging.error('use %s blobs' % path)
_sys_path = None
break
except Exception, e:
- logging.debug('skip %s blobs: %s' % (path, e))
+ logging.error('skip %s blobs: %s' % (path, e))
if _sys_path:
raise('cannot find proper binary blobs')
diff --git a/fill/armv7l_27/__init__.py b/fill/armv7l_27/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/fill/armv7l_27/__init__.py
+++ /dev/null
diff --git a/fill/armv7l_27/_fill.so b/fill/armv7l_27/_fill.so
deleted file mode 100644
index a68d5a8..0000000
--- a/fill/armv7l_27/_fill.so
+++ /dev/null
Binary files differ
diff --git a/fill/eggfill.c b/fill/eggfill.c
index 5de388d..318879c 100644
--- a/fill/eggfill.c
+++ b/fill/eggfill.c
@@ -51,7 +51,6 @@ Roseli de Deus Lopes (roseli@lsi.usp.br)
*/
-#include <gtk/gtk.h>
#include "eggfill.h"
#define front(q) ( (q)->front )
@@ -60,9 +59,9 @@ Roseli de Deus Lopes (roseli@lsi.usp.br)
/* 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 */
+/* check if queue q is empty */
int queue_is_empty(queue *q){
- return ((front(q)==NULL) && (rear(q)==NULL));
+ return ((front(q)==NULL) && (rear(q)==NULL));
}
queue *queue_init(void){
@@ -90,7 +89,6 @@ void queue_make_empty(queue *q){
queue_dequeue(q);
}
-
void queue_enqueue(int element, queue *q){
no *tmp;
tmp = (no*)malloc(sizeof(no));
@@ -123,50 +121,50 @@ void queue_dequeue(queue *q){
}
}/* end of queue*/
-void fill(GdkDrawable *drawable, GdkGC *gc, int x, int y, int width, int height, int color){
+void
+floodfill(unsigned int* pixels, int x, int y, int width, int height, unsigned int color) {
- printf("Entrando no fill\n");
- int color_start;
+ printf("\nEntrando to floodfill\n");
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);
+ int color_start = pixels[x + y * width];
- if (color!=color_start) {
+ if (color != color_start) {
queue_enqueue(x, lista_xy);
- queue_enqueue(y, lista_xy);
- gdk_image_put_pixel(image, x, y, color);
+ queue_enqueue(y, lista_xy);
+
+ pixels[x + y * width] = 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);
+ if (x + 1 < width) {
+ if (pixels[(x + 1) + y * width] == color_start) {
+ pixels[(x + 1) + y * width] = 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);
+ }
+
+ if (x - 1 >= 0){
+ if (pixels[(x - 1) + y * width] == color_start) {
+ pixels[(x - 1) + y * width] = 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);
+
+ if (y + 1 < height){
+ if (pixels[x + (y + 1) * width] == color_start) {
+ pixels[x + (y + 1) * width] = 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);
+
+ if (y - 1 >= 0){
+ if (pixels[x + (y - 1) * width] == color_start){
+ pixels[x + (y - 1) * width] = color;
queue_enqueue(x, lista_xy);
queue_enqueue(y-1, lista_xy);
}
@@ -177,13 +175,6 @@ void fill(GdkDrawable *drawable, GdkGC *gc, int x, int y, int width, int height,
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
index 1836043..6cba20d 100644
--- a/fill/eggfill.h
+++ b/fill/eggfill.h
@@ -52,7 +52,6 @@ Roseli de Deus Lopes (roseli@lsi.usp.br)
*/
#include <stdio.h>
#include <stdlib.h>
-#include <gtk/gtk.h>
/*to implement a queue */
typedef struct _tno {
@@ -74,4 +73,4 @@ 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);
+void floodfill(unsigned int * pixels, int x, int y, int width, int height, unsigned int color);
diff --git a/fill/fill.c b/fill/fill.c
index 39c4e34..e69de29 100644
--- a/fill/fill.c
+++ b/fill/fill.c
@@ -1,79 +0,0 @@
-/* -- THIS FILE IS GENERATED - DO NOT EDIT *//* -*- Mode: C; c-basic-offset: 4 -*- */
-
-#include <Python.h>
-
-
-
-#line 3 "fill.override"
-#include <Python.h>
-#include <gtk/gtk.h>
-#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
index d2ebadf..9135c15 100644
--- a/fill/fill.defs
+++ b/fill/fill.defs
@@ -9,8 +9,7 @@
(c-name "fill")
(return-type "none")
(parameters
- '("GdkDrawable*" "drawable")
- '("GdkGC*" "gc")
+ '("int []" "pixels")
'("int" "x")
'("int" "y")
'("int" "width")
diff --git a/fill/fill.override b/fill/fill.override
index 3de606c..0598cd6 100644
--- a/fill/fill.override
+++ b/fill/fill.override
@@ -1,15 +1,10 @@
%%
headers
#include <Python.h>
-#include <gtk/gtk.h>
-#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
index b23bfd7..9a1c0e1 100644
--- a/fill/fillmodule.c
+++ b/fill/fillmodule.c
@@ -46,26 +46,53 @@ Cientific Coordinator:
Roseli de Deus Lopes (roseli@lsi.usp.br)
*/
-#include <pygobject.h>
+#include <Python.h>
+#include "eggfill.h"
-void fill_register_classes (PyObject *d);
-
-extern PyMethodDef fill_functions[];
-
-DL_EXPORT(void)
-init_fill(void)
+static PyObject* fill(PyObject* self, PyObject* args)
{
- PyObject *m, *d;
-
- init_pygobject ();
+ PyObject *mylist;
+ unsigned int x, y, width, height, color;
+
+ if (!PyArg_ParseTuple(args, "OIIIII", &mylist, &x, &y, &width, &height, &color))
+ return NULL;
+
+ /* from http://mail.python.org/pipermail/tutor/1999-November/000758.html */
+ unsigned int *intarr, arrsize, index;
+ PyObject *item;
+ PyObject *pylist;
+
+ /* how many elements are in the Python object */
+ arrsize = PyObject_Length(mylist);
+ /* create a dynamic C array of integers */
+ intarr = (int *)malloc(sizeof(int)*arrsize);
+ for (index = 0; index < arrsize; index++) {
+ /* get the element from the list/tuple */
+ item = PySequence_GetItem(mylist, index);
+ /* assign to the C array */
+ intarr[index] = PyInt_AsUnsignedLongMask(item);
+ }
- m = Py_InitModule ("_fill", fill_functions);
- d = PyModule_GetDict (m);
-
- fill_register_classes (d);
+ /* now use intarr and arrsize in you extension */
+ //printf("x %u y %u width %u height %u color %u", x, y, width, height, color);
+ floodfill(intarr, x, y, width, height, color);
- if (PyErr_Occurred ()) {
- Py_FatalError ("can't initialise module fill");
+ pylist = PyTuple_New(arrsize);
+ for (index = 0; index < arrsize; index++) {
+ PyTuple_SetItem(pylist, index, PyInt_FromLong(intarr[index]));
}
+ return Py_BuildValue("O", pylist);
+}
+
+
+static PyMethodDef FillMethods[] = {
+ {"fill", fill, METH_VARARGS, "do fill flood in a array with the image data"},
+ {NULL, NULL, 0, NULL}
+};
+
+PyMODINIT_FUNC
+init_fill(void)
+{
+ (void) Py_InitModule("_fill", FillMethods);
}
diff --git a/fill/linux32_25/__init__.py b/fill/linux32_25/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/fill/linux32_25/__init__.py
+++ /dev/null
diff --git a/fill/linux32_25/_fill.so b/fill/linux32_25/_fill.so
deleted file mode 100644
index 84d4a2e..0000000
--- a/fill/linux32_25/_fill.so
+++ /dev/null
Binary files differ
diff --git a/fill/linux32_26/__init__.py b/fill/linux32_26/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/fill/linux32_26/__init__.py
+++ /dev/null
diff --git a/fill/linux32_26/_fill.so b/fill/linux32_26/_fill.so
deleted file mode 100644
index ee3a09c..0000000
--- a/fill/linux32_26/_fill.so
+++ /dev/null
Binary files differ
diff --git a/fill/linux32_27/__init__.py b/fill/linux32_27/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/fill/linux32_27/__init__.py
+++ /dev/null
diff --git a/fill/linux32_27/_fill.so b/fill/linux32_27/_fill.so
deleted file mode 100644
index e6e7d1a..0000000
--- a/fill/linux32_27/_fill.so
+++ /dev/null
Binary files differ
diff --git a/fill/linux64_25/__init__.py b/fill/linux64_25/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/fill/linux64_25/__init__.py
+++ /dev/null
diff --git a/fill/linux64_25/_fill.so b/fill/linux64_25/_fill.so
deleted file mode 100644
index 2a7a7ea..0000000
--- a/fill/linux64_25/_fill.so
+++ /dev/null
Binary files differ
diff --git a/fill/linux64_26/__init__.py b/fill/linux64_26/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/fill/linux64_26/__init__.py
+++ /dev/null
diff --git a/fill/linux64_26/_fill.so b/fill/linux64_26/_fill.so
deleted file mode 100644
index 533df67..0000000
--- a/fill/linux64_26/_fill.so
+++ /dev/null
Binary files differ
diff --git a/fill/linux64_27/_fill.so b/fill/linux64_27/_fill.so
index 2b2975f..824387c 100755
--- a/fill/linux64_27/_fill.so
+++ b/fill/linux64_27/_fill.so
Binary files differ