From e0fa9a44126148264e3c1028f90aefc8e7679d1f Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Fri, 20 Feb 2009 05:27:52 +0000 Subject: Support 24/32 screen depths; add Makefiles --- diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..37415bc --- /dev/null +++ b/INSTALL @@ -0,0 +1,14 @@ +To build C library: +$ make +you need: +- swig +- gtk-devel +- python-devel +- gstreamer-devel +- pygtk-devel + +To make regular sugar procedures: +$ ./setup.py + +To install binaries: +$ make DESTDIR= install diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9110bc0 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +pythondir = $(shell python -c "from distutils import sysconfig; print sysconfig.get_python_lib()") + +all clean: + $(MAKE) -C pongc $@ + +install: all + ./setup.py fix_manifest + sed -i /^pongc/d MANIFEST + ./setup.py install --prefix=$(DESTDIR)/usr + for i in __init__.py _pongc.so pongc.py; do \ + install -m 644 -D pongc/$$i $(DESTDIR)/$(pythondir)/pongc/$$i; \ + done diff --git a/NEWS b/NEWS index 4b454eb..4b454eb 100755..100644 --- a/NEWS +++ b/NEWS diff --git a/_pongc.so b/_pongc.so deleted file mode 100755 index 1db5f88..0000000 --- a/_pongc.so +++ /dev/null Binary files differ diff --git a/activity/activity.info b/activity/activity.info index 277888f..277888f 100755..100644 --- a/activity/activity.info +++ b/activity/activity.info diff --git a/bounce.py b/bounce.py index 6ec7e2a..6ace3e3 100644 --- a/bounce.py +++ b/bounce.py @@ -14,7 +14,7 @@ default_stage_descs = [ import logging, os, time, math, threading, random, json, time -from pongc import * +from pongc.pongc import * # Import GTK. import gobject, pygtk, gtk, pango, cairo diff --git a/pongc.py b/pongc.py deleted file mode 100644 index c1c6002..0000000 --- a/pongc.py +++ /dev/null @@ -1,65 +0,0 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 1.3.33 -# -# Don't modify this file, modify the SWIG interface instead. -# This file is compatible with both classic and new-style classes. - -import _pongc -import new -new_instancemethod = new.instancemethod -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'PySwigObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError,name - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -import types -try: - _object = types.ObjectType - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 -del types - - -clear_image = _pongc.clear_image -draw_line_2x = _pongc.draw_line_2x -draw_ellipse_2x = _pongc.draw_ellipse_2x -fill_ellipse_2x = _pongc.fill_ellipse_2x -set_3d_params = _pongc.set_3d_params -to_fixed = _pongc.to_fixed -project_x = _pongc.project_x -project_y = _pongc.project_y -draw_line_3d = _pongc.draw_line_3d -draw_rect_3d = _pongc.draw_rect_3d -draw_circle_3d = _pongc.draw_circle_3d -fill_circle_3d = _pongc.fill_circle_3d -draw_ellipse_3d = _pongc.draw_ellipse_3d - - diff --git a/pongc/Makefile b/pongc/Makefile new file mode 100644 index 0000000..5e17124 --- /dev/null +++ b/pongc/Makefile @@ -0,0 +1,22 @@ +CXXFLAGS = $(shell pkg-config --cflags gdk-x11-2.0) \ + $(shell pkg-config --cflags gstreamer-0.10) \ + $(shell pkg-config --cflags pygtk-2.0) \ + $(shell python-config --cflags) \ + -fPIC -O2 +LDFLAGS = $(shell pkg-config --libs gdk-x11-2.0) \ + $(shell pkg-config --cflags gstreamer-0.10) \ + $(shell pkg-config --libs pygtk-2.0) \ + $(shell python-config --libs) + +all: _pongc.so + +clean: + rm -rf _pongc.so *_wrap.cxx pongc.py pongc.pyc *.o + +%_wrap.cpp: %.i + swig -c++ -python -o $*_wrap.cpp $< + +pongc.o: pongc.h + +_pongc.so: pongc.o pongc_wrap.o + $(CXX) -shared $(LDFLAGS) -o $@ $^ diff --git a/pongc/__init__.py b/pongc/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/pongc/__init__.py diff --git a/src/pongc.cpp b/pongc/pongc.cpp index 5d469b1..536285d 100644 --- a/src/pongc.cpp +++ b/pongc/pongc.cpp @@ -17,29 +17,65 @@ */ #include "pongc.h" -void clear_image(GdkImage* img) +typedef guint16 depth16_t; +typedef guint32 depth24_t; + +template inline +void _clear_image(GdkImage* img) { - unsigned short* pixels = (unsigned short*)img->mem; - int pitch = img->bpl/sizeof(unsigned short); + pixel_t* pixels = (pixel_t*)img->mem; + int pitch = img->bpl/sizeof(pixel_t); for (int y = 0; y < img->height; y++) memset(pixels + pitch*y, 0, img->bpl); } -void draw_point_2x(GdkImage* img, int x, int y, uint16_t c) +void clear_image(GdkImage* img) +{ + if (img->depth == 16) + _clear_image(img); + else + _clear_image(img); +} + +inline +void to_pixel(depth16_t *pixel, uint16_t c) +{ + *pixel = c | c<<6 | c<<11; +} + +inline +void to_pixel(depth24_t *pixel, uint16_t c) +{ + *pixel = c | c<<8 | c<<16; +} + +template inline +void _draw_point_2x(GdkImage* img, int x, int y, uint16_t c) { if (x < 0 || y < 0 || x >= img->width/2-1 || y >= img->height/2-1) return; c >>= 3; - unsigned short* pixels = (unsigned short*)img->mem; - int pitch = img->bpl/sizeof(unsigned short); + pixel_t* pixels = (pixel_t*)img->mem; + int pitch = img->bpl/sizeof(pixel_t); int ofs = pitch*y*2+x*2; - uint16_t pix = c | c<<6 | c<<11; + + uint16_t pix; + to_pixel(&pix, c); + pixels[ofs] = pix; pixels[ofs+1] = pix; pixels[ofs+pitch] = pix; pixels[ofs+pitch+1] = pix; } +void draw_point_2x(GdkImage* img, int x, int y, uint16_t c) +{ + if (img->depth == 16) + _draw_point_2x(img, x, y, c); + else + _draw_point_2x(img, x, y, c); +} + void draw_line_2x(GdkImage* img, int x0, int y0, int x1, int y1, int color) { // Make sure the line runs top to bottom. diff --git a/src/pongc.h b/pongc/pongc.h index 200e3c5..fd4346a 100644 --- a/src/pongc.h +++ b/pongc/pongc.h @@ -20,8 +20,8 @@ #include -// todo- Include the real GTK headers when installed. -#include "gtk_types.h" +#include +#include // 2D primitives void clear_image(GdkImage* img); diff --git a/src/pongc.i b/pongc/pongc.i index 1215910..99702ec 100644 --- a/src/pongc.i +++ b/pongc/pongc.i @@ -18,6 +18,7 @@ %module pongc %{ +#include #include "pongc.h" %} diff --git a/src/build.sh b/src/build.sh deleted file mode 100755 index 05f7cd7..0000000 --- a/src/build.sh +++ /dev/null @@ -1,5 +0,0 @@ -swig -c++ -python pongc.i -python setup.py build_ext --inplace -mv _pongc.so ../ -mv pongc.py ../ - diff --git a/src/gtk_types.h b/src/gtk_types.h deleted file mode 100644 index f3e26bd..0000000 --- a/src/gtk_types.h +++ /dev/null @@ -1,130 +0,0 @@ -// This file serves to allow access to a limited subset of GTK and GStreamer objects passed from PyGTK, without the full -// GLib + GTK + GST development environment. -// -// Obviously, it is limited to working with a specific version of GTK, PyGTK and GStreamer, but these structures appear -// to be fairly stable. -#ifndef GTK_TYPES_H -#define GTK_TYPES_H - -#include - -typedef uint8_t guint8; -typedef int32_t gint; -typedef uint32_t guint; -typedef uint16_t guint16; -typedef uint64_t guint64; -typedef void* gpointer; - -struct GTypeClass; -struct GData; - -struct _GTypeInstance -{ - /*< private >*/ - GTypeClass *g_class; -}; - -typedef struct _GTypeInstance GTypeInstance; - -struct _GObject -{ - GTypeInstance g_type_instance; - - /*< private >*/ - guint ref_count; - GData *qdata; -}; - -typedef struct _GObject GObject; - -typedef enum -{ - GDK_IMAGE_NORMAL, - GDK_IMAGE_SHARED, - GDK_IMAGE_FASTEST -} GdkImageType; - -typedef enum -{ - GDK_LSB_FIRST, - GDK_MSB_FIRST -} GdkByteOrder; - -struct GdkVisual; -struct GdkColormap; - -typedef struct { - GObject parent_instance; - - - GdkImageType type; /* read only. */ - GdkVisual *visual; /* read only. visual used to create the image */ - GdkByteOrder byte_order; /* read only. */ - gint width; /* read only. */ - gint height; /* read only. */ - guint16 depth; /* read only. */ - guint16 bpp; /* read only. bytes per pixel */ - guint16 bpl; /* read only. bytes per line */ - guint16 bits_per_pixel; /* read only. bits per pixel */ - gpointer mem; - - GdkColormap *colormap; /* read only. */ -} GdkImage; - -struct GSList; - -typedef struct { - PyObject_HEAD - GObject *obj; - PyObject *inst_dict; /* the instance dictionary -- must be last */ - PyObject *weakreflist; /* list of weak references */ - GSList *closures; -} PyGObject; - -struct _GstMiniObject { - GTypeInstance instance; - /*< public >*/ /* with COW */ - gint refcount; - guint flags; - - /*< private >*/ - gpointer _gst_reserved; -}; - -typedef struct _GstMiniObject GstMiniObject; - -struct GstCaps; - -typedef guint64 GstClockTime; - -#define GST_PADDING 4 - -struct _GstBuffer { - GstMiniObject mini_object; - - /*< public >*/ /* with COW */ - /* pointer to data and its size */ - guint8 *data; - guint size; - - /* timestamp */ - GstClockTime timestamp; - GstClockTime duration; - - /* the media type of this buffer */ - GstCaps *caps; - - /* media specific offset */ - guint64 offset; - guint64 offset_end; - - guint8 *malloc_data; - - /*< private >*/ - gpointer _gst_reserved[GST_PADDING]; -}; - -typedef struct _GstBuffer GstBuffer; - -#endif - diff --git a/src/setup.py b/src/setup.py deleted file mode 100644 index 7a31dc5..0000000 --- a/src/setup.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env python - -""" -setup.py file for 3dpong -""" - -from distutils.core import setup, Extension - -pongc_module = Extension('_pongc', sources=['pongc.cpp', 'pongc_wrap.cxx'] ) - -setup (name = 'pongc', version = '0.1', - author = "Wade Brainerd", - description = """3DPong C extension library.""", - ext_modules = [pongc_module], py_modules = ["pongc"]) - -- cgit v0.9.1