Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2010-04-03 21:59:04 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2010-04-03 21:59:04 (GMT)
commit9a77b10363f14231b39a9a7e0893f9e8921aae3b (patch)
tree9232faf638f4c2ca945cbaa1de3ab5e25cf8f0ab
parent55c3a14a63c3a659b2e01d3a657aff0226fe8130 (diff)
Use hippo.cairo_surface_from_gdk_pixbuf instead of bundling blobs
-rw-r--r--camerac/Makefile40
-rw-r--r--camerac/__init__.py21
-rw-r--r--camerac/camera.c276
-rw-r--r--constants.py4
-rw-r--r--ui.py7
-rw-r--r--utils.py4
6 files changed, 7 insertions, 345 deletions
diff --git a/camerac/Makefile b/camerac/Makefile
deleted file mode 100644
index 0fb6f76..0000000
--- a/camerac/Makefile
+++ /dev/null
@@ -1,40 +0,0 @@
-PYVER=`python -c "import sys; print '%s.%s' % (sys.version_info[0], sys.version_info[1])"`
-PYTHON=python$(PYVER)
-PYTHON_LIBS=`python-config --libs`
-
-GLIB_INCLUDES=`pkg-config --cflags glib-2.0`
-GLIB_LIBS=`pkg-config --libs glib-2.0`
-
-GTK_INCLUDES=`pkg-config --cflags gtk+-2.0`
-GTK_LIBS=`pkg-config --libs gtk+-2.0`
-
-PYGTK_INCLUDES=`pkg-config --cflags pygtk-2.0`
-PYGTK_LIBS=`pkg-config --libs pygtk-2.0`
-
-CAIRO_INCLUDES=`pkg-config --cflags cairo`
-CAIRO_LIBS=`pkg-config --libs cairo`
-
-PYCAIRO_INCLUDES=`pkg-config --cflags pycairo`
-PYCAIRO_LIBS=`pkg-config --libs pycairo`
-
-INCLUDES=-I. -I/usr/include/${PYTHON} ${GLIB_INCLUDES} ${PYGTK_INCLUDES} ${CAIRO_INCLUDES} ${PYCAIRO_INCLUDES} ${GTK_INCLUDES}
-OPTFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables
-CFLAGS=-g -fPIC -DPIC $(OPTFLAGS) $(INCLUDES)
-LDFLAGS=-shared -nostdlib -Wl,--export-dynamic -pthread ${GLIB_LIBS} ${PYGTK_LIBS} ${CAIRO_LIBS} ${PYCAIRO_LIBS} ${GTK_LIBS} $(PYTHON_LIBS)
-
-ARCH = $(shell arch | grep 64 >/dev/null && echo linux64 || echo linux32)
-LIB_DIR = $(ARCH)_$(PYVER)
-
-all: camera.so
- rm -rf $(LIB_DIR)
- mkdir $(LIB_DIR)
- strip -s $^
- mv $^ $(LIB_DIR)/
- touch $(LIB_DIR)/__init__.py
-
-camera.so: camera.o
- $(CXX) $(LDFLAGS) -o $@ $^
-
-clean:
- rm -f *.o
- rm -f *.so
diff --git a/camerac/__init__.py b/camerac/__init__.py
deleted file mode 100644
index dba55ae..0000000
--- a/camerac/__init__.py
+++ /dev/null
@@ -1,21 +0,0 @@
-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 camera 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/camerac/camera.c b/camerac/camera.c
deleted file mode 100644
index cf4795d..0000000
--- a/camerac/camera.c
+++ /dev/null
@@ -1,276 +0,0 @@
-#include <Python.h>
-
-#include "pycairo.h"
-#include <glib.h>
-
-#include <pygobject.h>
-
-static PyTypeObject *_PyGObject_Type;
-#define PyGObject_Type (*_PyGObject_Type)
-Pycairo_CAPI_t *Pycairo_CAPI;
-static PyTypeObject *_PyGdkPixbuf_Type;
-#define PyGdkPixbuf_Type (*_PyGdkPixbuf_Type)
-
-#include <cairo.h>
-#include <gdk/gdkpixbuf.h>
-#include <gdk/gdkpixmap.h>
-#include <cairo-xlib.h>
-#include <gdk/gdkcairo.h>
-
-static cairo_surface_t *
-_cairo_surface_from_pixbuf (GdkPixbuf *pixbuf)
-{
-/* Ripped from GooCanvas */
- gint width = gdk_pixbuf_get_width (pixbuf);
- gint height = gdk_pixbuf_get_height (pixbuf);
- guchar *gdk_pixels = gdk_pixbuf_get_pixels (pixbuf);
- int gdk_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
- int n_channels = gdk_pixbuf_get_n_channels (pixbuf);
- guchar *cairo_pixels;
- cairo_format_t format;
- cairo_surface_t *surface;
- static const cairo_user_data_key_t key;
- int j;
-
- if (n_channels == 3)
- format = CAIRO_FORMAT_RGB24;
- else
- format = CAIRO_FORMAT_ARGB32;
-
- cairo_pixels = g_malloc (4 * width * height);
- surface = cairo_image_surface_create_for_data ((unsigned char *)cairo_pixels,
- format,
- width, height, 4 * width);
- cairo_surface_set_user_data (surface, &key,
- cairo_pixels, (cairo_destroy_func_t)g_free);
-
- for (j = height; j; j--)
- {
- guchar *p = gdk_pixels;
- guchar *q = cairo_pixels;
-
- if (n_channels == 3)
- {
- guchar *end = p + 3 * width;
-
- while (p < end)
- {
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
- q[0] = p[2];
- q[1] = p[1];
- q[2] = p[0];
-#else
- q[1] = p[0];
- q[2] = p[1];
- q[3] = p[2];
-#endif
- p += 3;
- q += 4;
- }
- }
- else
- {
- guchar *end = p + 4 * width;
- guint t1,t2,t3;
-
-#define MULT(d,c,a,t) G_STMT_START { t = c * a; d = ((t >> 8) + t) >> 8; } G_STMT_END
-
- while (p < end)
- {
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
- MULT(q[0], p[2], p[3], t1);
- MULT(q[1], p[1], p[3], t2);
- MULT(q[2], p[0], p[3], t3);
- q[3] = p[3];
-#else
- q[0] = p[3];
- MULT(q[1], p[0], p[3], t1);
- MULT(q[2], p[1], p[3], t2);
- MULT(q[3], p[2], p[3], t3);
-#endif
-
- p += 4;
- q += 4;
- }
-
-#undef MULT
- }
-
- gdk_pixels += gdk_rowstride;
- cairo_pixels += 4 * width;
- }
-
- return surface;
-}
-
-static PyObject*
-_wrap_camera_cairo_surface_from_gdk_pixbuf(PyGObject *self, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "pixbuf", NULL };
- PyGObject *child;
- cairo_surface_t *surface;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!:camera.cairo_surface_from_gdk_pixbuf", kwlist, &PyGdkPixbuf_Type, &child))
- return NULL;
-
- surface = _cairo_surface_from_pixbuf(GDK_PIXBUF (child->obj));
- if (surface == NULL) {
- PyErr_SetString(PyExc_RuntimeError, "surface could not be converted");
- return NULL;
- }
-
- return PycairoSurface_FromSurface(surface, NULL);
-}
-
-static GdkPixbuf *
-_pixbuf_from_cairo_surface (cairo_surface_t * sf)
-{
- GdkPixmap * pixmap;
- GdkPixbuf * pixbuf = NULL;
- cairo_surface_type_t type;
- gint width = 0, height = 0, depth = 0;
- int format;
- cairo_t * cr;
- GdkColormap * cm;
-
- type = cairo_surface_get_type (sf);
- switch (type) {
- case CAIRO_SURFACE_TYPE_IMAGE:
- width = cairo_image_surface_get_width (sf);
- height = cairo_image_surface_get_height (sf);
- format = cairo_image_surface_get_format (sf);
- if (format == CAIRO_FORMAT_ARGB32)
- depth = 32;
- else if (format == CAIRO_FORMAT_RGB24)
- depth = 24;
- else if (format == CAIRO_FORMAT_A8)
- depth = 8;
- else if (format == CAIRO_FORMAT_A1)
- depth = 1;
- else if (format == CAIRO_FORMAT_RGB16_565)
- depth = 16;
- break;
- case CAIRO_SURFACE_TYPE_XLIB:
- width = cairo_xlib_surface_get_width (sf);
- height = cairo_xlib_surface_get_height (sf);
- depth = cairo_xlib_surface_get_depth (sf);
- break;
- default:
- break;
- }
- if (!depth)
- return NULL;
-
- pixmap = gdk_pixmap_new (NULL, width, height, depth);
- if (!pixmap)
- return NULL;
-
- cr = gdk_cairo_create (pixmap);
- if (!cr)
- goto release_pixmap;
-
- cairo_set_source_surface (cr, sf, 0, 0);
- cairo_paint (cr);
- cairo_destroy (cr);
-
- cm = gdk_colormap_get_system ();
- pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, cm, 0, 0, 0, 0, -1, -1);
-
-release_pixmap:
- gdk_pixmap_unref (pixmap);
-
- return pixbuf;
-}
-
-
-static PyObject*
-_wrap_camera_gdk_pixbuf_from_cairo_surface(PyGObject *self, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist[] = { "surface", NULL };
- PyGObject *child;
- GdkPixbuf * pixbuf;
- PyTypeObject *type = &PycairoSurface_Type;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!:camera.gdk_pixbuf_from_cairo_surface", kwlist, type, &child))
- return NULL;
-
- pixbuf = _pixbuf_from_cairo_surface((cairo_surface_t *)(child->obj));
- if (pixbuf == NULL) {
- PyErr_SetString(PyExc_RuntimeError, "pixbuf could not be converted");
- return NULL;
- }
-
- return pygobject_new ((GObject *) pixbuf);
-}
-
-const PyMethodDef py_camera_functions[] = {
- { "cairo_surface_from_gdk_pixbuf", (PyCFunction)_wrap_camera_cairo_surface_from_gdk_pixbuf,
- METH_VARARGS|METH_KEYWORDS, NULL },
- { "gdk_pixbuf_from_cairo_surface", (PyCFunction)_wrap_camera_gdk_pixbuf_from_cairo_surface,
- METH_VARARGS|METH_KEYWORDS, NULL },
- { NULL, NULL, 0, NULL }
-};
-
-
-/* ----------- enums and flags ----------- */
-
-void
-py_sugar_add_constants(PyObject *module, const gchar *strip_prefix)
-{
-}
-
-/* initialise stuff extension classes */
-void
-py_camera_register_classes(PyObject *d)
-{
- PyObject *module;
-
- if ((module = PyImport_ImportModule("gobject")) != NULL) {
- _PyGObject_Type = (PyTypeObject *)PyObject_GetAttrString(module, "GObject");
- if (_PyGObject_Type == NULL) {
- PyErr_SetString(PyExc_ImportError,
- "cannot import name GObject from gobject");
- return ;
- }
- _PyGObject_Type = (PyTypeObject *)PyObject_GetAttrString(module, "GObject");
- if (_PyGObject_Type == NULL) {
- PyErr_SetString(PyExc_ImportError,
- "cannot import name GObject from gobject");
- return ;
- }
- } else {
- PyErr_SetString(PyExc_ImportError,
- "could not import gobject");
- return ;
- }
- if ((module = PyImport_ImportModule("gtk.gdk")) != NULL) {
- _PyGdkPixbuf_Type = (PyTypeObject *)PyObject_GetAttrString(module, "Pixbuf");
- if (_PyGdkPixbuf_Type == NULL) {
- PyErr_SetString(PyExc_ImportError,
- "cannot import name Pixbuf from gtk.gdk");
- return ;
- }
- } else {
- PyErr_SetString(PyExc_ImportError,
- "could not import gtk.gdk");
- return ;
- }
-
- Pycairo_IMPORT;
-}
-
-DL_EXPORT(void)
-initcamera(void)
-{
- PyObject *m, *d;
-
- Pycairo_IMPORT;
-
- m = Py_InitModule ("camera", py_camera_functions);
- d = PyModule_GetDict (m);
-
- py_camera_register_classes (d);
- if (PyErr_Occurred ()) {
- Py_FatalError ("can't initialise module camera");
- }
-}
diff --git a/constants.py b/constants.py
index 0da125a..0e131aa 100644
--- a/constants.py
+++ b/constants.py
@@ -2,6 +2,7 @@
import os
import gtk
from gettext import gettext as gt
+import hippo
import sugar.graphics.style
from sugar.activity import activity
@@ -10,7 +11,6 @@ from instance import Instance
from sugar import profile
from color import Color
import utils
-import camerac
import cairo
import pango
import pangocairo
@@ -269,7 +269,7 @@ class Constants:
recCircleFile = os.path.join(self.__class__.gfxPath, 'media-circle.png')
recCirclePixbuf = gtk.gdk.pixbuf_new_from_file(recCircleFile)
- self.__class__.recCircleCairo = camerac.cairo_surface_from_gdk_pixbuf(recCirclePixbuf)
+ self.__class__.recCircleCairo = hippo.cairo_surface_from_gdk_pixbuf(recCirclePixbuf)
recInsFile = os.path.join(self.__class__.gfxPath, 'media-insensitive.png')
recInsPixbuf = gtk.gdk.pixbuf_new_from_file(recInsFile)
diff --git a/ui.py b/ui.py
index 215cc58..10d16cd 100644
--- a/ui.py
+++ b/ui.py
@@ -59,7 +59,6 @@ from recorded import Recorded
from button import RecdButton
import utils
import record
-import camerac
import aplay
from tray import HTray
from toolbarcombobox import ToolComboBox
@@ -786,7 +785,7 @@ class UI:
if (pixbuf != None):
#self.shownRecd = recd
- img = camerac.cairo_surface_from_gdk_pixbuf(pixbuf)
+ img = hippo.cairo_surface_from_gdk_pixbuf(pixbuf)
self.livePhotoCanvas.setImage( img )
self.ca.glive.thumb_play()
@@ -1655,7 +1654,7 @@ class UI:
#if (recd != self.shownRecd):
pixbuf = recd.getAudioImagePixbuf()
- img = camerac.cairo_surface_from_gdk_pixbuf(pixbuf)
+ img = hippo.cairo_surface_from_gdk_pixbuf(pixbuf)
self.livePhotoCanvas.setImage( img )
#self.shownRecd = recd
self.showRecdMeta(recd)
@@ -1768,7 +1767,7 @@ class UI:
pixbuf = pixbuf.scale_simple(self.__class__.dim_THUMB_WIDTH, self.__class__.dim_THUMB_HEIGHT, gtk.gdk.INTERP_NEAREST)
pixbuf = utils.grayScalePixBuf(pixbuf, True)
- img = camerac.cairo_surface_from_gdk_pixbuf(pixbuf)
+ img = hippo.cairo_surface_from_gdk_pixbuf(pixbuf)
self.backgdCanvas.setImage(img)
diff --git a/utils.py b/utils.py
index e9aa6cf..c98c831 100644
--- a/utils.py
+++ b/utils.py
@@ -8,9 +8,9 @@ import gc
import gtk
import time
from time import strftime
+import hippo
from sugar import util
-import camerac
def getStringFromPixbuf(pixbuf):
data = [""]
@@ -58,7 +58,7 @@ def generateThumbnail( pixbuf, scale, thumbw, thumbh ):
#need to generate thumbnail version here
thumbImg = cairo.ImageSurface(cairo.FORMAT_ARGB32, thumbw, thumbh)
tctx = cairo.Context(thumbImg)
- img = camerac.cairo_surface_from_gdk_pixbuf(pixbuf)
+ img = hippo.cairo_surface_from_gdk_pixbuf(pixbuf)
tctx.scale(scale, scale)
tctx.set_source_surface(img, 0, 0)
tctx.paint()