Showing posts with label C. Show all posts
Showing posts with label C. Show all posts

30.12.09

aggdraw patches/fixes/updates

So i have been slowly overhauling bits of aggdraw and now have come to a point where i thought i'd explain what all i have done. Originally agg was packaged with aggdraw and it was an older version of the 2.x series, 2.3 if im not mistaken. I've now updated this older code to the current version of 2.5, updated many of the interfaces. Everything seems to be much faster now. I will have more to post later.

revision change of the update.

26.12.09

fluid dynamics update.

The fluid dynamics is working now! albeit at a slow frame rate but it is actually working.

12.12.09

Python fluid dynamics library.

I'm currently working on a fluid dynamics library for my graphics library but have a very broad implementation up here. This is currently a work in progress. so it may or may not work. It requires fftw. I plan to use it to show the flow between nodes on a graph.

Original paper [JGT01]

Code here.

11.12.09

Python drawing library.

I've been working on a python drawing library for about a month and a half now, and i'm ready to share some details about it. Originally i was just going to take nodebox and re implement the backend to support aggdraw and PIL. But i ran acrossed design problems and supporting their API would make the library feel more like a standalone program than a real library. This is due to the fact that nodebox is really a standalone application and i wanted something that i could easily call from other programs. So far the requirements for the library are aggdraw, PIL and numpy. I have worked up several patches for aggdraw so all of the current problems with aggdraw should be worked out.

22.7.09

Cython an introduction.

One of the most useful things that i've come acrossed in Python is Cython a C extension for python, this tool was derived from Pyrex which is developed by Greg Ewing.

cdef extern from "xine_internal.h"
ctypedef extern struct xine_t
The above is an example from cython, it shares the same general syntax as python but has added many keywords that are specific to it. cdef is the keyword that is pretty much the same as def but it is declaring that the function is a C function.

In the example above cdef extern from "...", it is telling the interpreter to include the specified file as an extern.

The next thing that is going on is ctypedef extern struct xine_t, this is declaring the C struct xine_t as an extern.

As soon as you have declared all the necessary datatypes in Cython, you can create a class and call those external functions from that class.

# forward declaration of the external function
cdef extern const_char_ptr xine_get_version_string()


cdef class libxine:
.....
def xineGetVersionString(self):
return xine_get_version_string()


You can combine datatypes into the Cython code and use it like the code below. The code is a cast which is the same a C cast. You can also set class objects that are structs or external objects or types and them pass those through functions.

def xineGetMetaInfo(self,int Info):
MetaTable = {
0: "Title",
1: "Comment",
2: "Artist",
3: "Genre",
4: "Album",
5: "Year"
}

cdef char *GetMeta
GetMeta = <char *>xine_get_meta_info(self.xineStream, Info)
if GetMeta == NULL:
raise Exception('MetaFail')
return MetaTable[Info], GetMeta

Original source (pyxine-ng)