From: kramm Date: Mon, 29 Mar 2004 17:21:04 +0000 (+0000) Subject: several fixes X-Git-Tag: stable_core_1~36 X-Git-Url: http://git.asbjorn.it/?a=commitdiff_plain;h=3281edc9ef69c0ba876f0146f55540227aa6a7fb;p=swftools.git several fixes --- diff --git a/lib/python/Makefile b/lib/python/Makefile index 0ab8c4b..3b87a74 100644 --- a/lib/python/Makefile +++ b/lib/python/Makefile @@ -1,34 +1,35 @@ all: mypython SWF.so LIB=-L/usr/lib/python2.2/config/ -lpython2.2 +I=-I/usr/include/python2.2 primitives.o: primitives.c primitives.h - gcc -g -O2 -Wall -Wno-unused -fPIC -I/usr/include/python2.2 -c primitives.c -o primitives.o + gcc -g -O2 -Wall -Wno-unused -fPIC $(I) -c primitives.c -o primitives.o tagmap.o: tagmap.c tagmap.h - gcc -g -O2 -Wall -Wno-unused -fPIC -I/usr/include/python2.2 -c tagmap.c -o tagmap.o -taglist.o: taglist.c taglist.h tagmap.h - gcc -g -O2 -Wall -Wno-unused -fPIC -I/usr/include/python2.2 -c taglist.c -o taglist.o + gcc -g -O2 -Wall -Wno-unused -fPIC $(I) -c tagmap.c -o tagmap.o +taglist.o: taglist.c taglist.h tagmap.h tag.h + gcc -g -O2 -Wall -Wno-unused -fPIC $(I) -c taglist.c -o taglist.o tag.o: tag.c tag.h tagmap.h - gcc -g -O2 -Wall -Wno-unused -fPIC -I/usr/include/python2.2 -c tag.c -o tag.o + gcc -g -O2 -Wall -Wno-unused -fPIC $(I) -c tag.c -o tag.o action.o: action.c action.h - gcc -g -O2 -Wall -Wno-unused -fPIC -I/usr/include/python2.2 -c action.c -o action.o + gcc -g -O2 -Wall -Wno-unused -fPIC $(I) -c action.c -o action.o pyutils.o: pyutils.c pyutils.h - gcc -g -O2 -Wall -Wno-unused -fPIC -I/usr/include/python2.2 -c pyutils.c -o pyutils.o + gcc -g -O2 -Wall -Wno-unused -fPIC $(I) -c pyutils.c -o pyutils.o -SWF.o: SWF.c pyutils.h primitives.h - gcc -g -O2 -Wall -Wno-unused -fPIC -I/usr/include/python2.2 -c SWF.c -o SWF.o +SWF.o: SWF.c pyutils.h primitives.h taglist.h + gcc -g -O2 -Wall -Wno-unused -fPIC $(I) -c SWF.c -o SWF.o SWF.so: SWF.o taglist.o tag.o tagmap.o action.o primitives.o pyutils.o ../librfxswf.a - gcc -shared SWF.o tagmap.o taglist.o tag.o action.o primitives.o pyutils.o -o SWF.so $(LIB) ../librfxswf.a -ljpeg -lz -lt1 -lfreetype - cp SWF.so test + gcc -shared SWF.o tagmap.o taglist.o tag.o action.o primitives.o pyutils.o -o SWF.so ../librfxswf.a -ljpeg -lz -lt1 -lfreetype mypython: mypython.c gcc -g -I/usr/include/python2.2 mypython.c -o mypython $(LIB) -ldl -lm -lpthread -lutil test: SWF.so - cd test;./test_create.py - #python fonts.py - swfdump -p test/test.swf + #./test_create.py + #swfdump -p test/test.swf + ./test_combine.py + swfdump -p tmp/combined.swf clean: rm *.o *.so mypython diff --git a/lib/python/SWF.c b/lib/python/SWF.c index e011841..b191927 100644 --- a/lib/python/SWF.c +++ b/lib/python/SWF.c @@ -103,6 +103,8 @@ static PyObject* f_load(PyObject* self, PyObject* args) return NULL; swf = PyObject_New(SWFObject, &SWFClass); + mylog("+%08x(%d) f_load\n", (int)swf, swf->ob_refcnt); + memset(&swf->swf, 0, sizeof(SWF)); swf->filename = strdup(filename); @@ -121,11 +123,10 @@ static PyObject* f_load(PyObject* self, PyObject* args) return 0; } close(fi); - swf->swf.firstTag = 0; swf->taglist = taglist_new2(swf->swf.firstTag); + swf->swf.firstTag = 0; - mylog("+%08x(%d) load\n", (int)self, self->ob_refcnt); return (PyObject*)swf; } //---------------------------------------------------------------------------- @@ -148,6 +149,8 @@ static PyObject * swf_save(PyObject* self, PyObject* args, PyObject* kwargs) if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|si", kwlist, &filename, &compress)) return NULL; + + mylog(" %08x(%d) f_save filename=%s compress=%d\n", (int)self, self->ob_refcnt, filename, compress); // keyword arg compress (=1) forces compression if(compress) diff --git a/lib/python/tag.c b/lib/python/tag.c index a0139f6..22cc8f0 100644 --- a/lib/python/tag.c +++ b/lib/python/tag.c @@ -136,15 +136,29 @@ PyObject* tag_new() tag->tagmap = tagmap_new(); return (PyObject*)tag; } -PyObject* tag_new2(TAG*_tag) +PyObject* tag_new2(TAG*t, PyObject* tagmap) { TagObject*tag = PyObject_New(TagObject, &TagClass); mylog("+%08x(%d) tag_new\n", (int)tag, tag->ob_refcnt); tag->font = 0; tag->character = 0; tag->placeobject = 0; - tag->tag = _tag; + tag->tag = t; tag->tagmap = tagmap_new(); + + int num = swf_GetNumUsedIDs(t); + int * positions = malloc(num*sizeof(int)); + swf_GetUsedIDs(t, positions); + int i; + for(i=0;idata[positions[i]]); + PyObject*obj = tagmap_id2obj(tagmap, id); + if(obj==NULL) { + PyErr_SetString(PyExc_Exception, setError("TagID %d not defined", id)); + return NULL; + } + tagmap_addMapping(tag->tagmap, id, obj); + } return (PyObject*)tag; } diff --git a/lib/python/tag.h b/lib/python/tag.h index 48a303e..dcdbec1 100644 --- a/lib/python/tag.h +++ b/lib/python/tag.h @@ -29,8 +29,7 @@ extern PyTypeObject TagClass; -PyObject* tag_new(); -PyObject* tag_new2(TAG*tag); +PyObject* tag_new2(TAG*_tag, PyObject* tagmap); TAG* tag_getTAG(PyObject*self, TAG*prevTag, PyObject*tagmap); PyObject* tag_getDependencies(PyObject*self); diff --git a/lib/python/taglist.c b/lib/python/taglist.c index 27b3a66..9caf3b2 100644 --- a/lib/python/taglist.c +++ b/lib/python/taglist.c @@ -19,7 +19,7 @@ typedef struct { PyObject * taglist_new() { TagListObject* taglist = PyObject_New(TagListObject, &TagListClass); - mylog("+%08x(%d) taglist_new2", (int)taglist, taglist->ob_refcnt); + mylog("+%08x(%d) taglist_new", (int)taglist, taglist->ob_refcnt); taglist->tagmap = tagmap_new(); taglist->taglist = PyList_New(0); return (PyObject*)taglist; @@ -28,18 +28,20 @@ PyObject * taglist_new() PyObject * taglist_new2(TAG*tag) { TagListObject* taglist = PyObject_New(TagListObject, &TagListClass); - mylog("+%08x(%d) taglist_new2", (int)taglist, taglist->ob_refcnt); + mylog("+%08x(%d) taglist_new2 tag=%08x", (int)taglist, taglist->ob_refcnt, tag); taglist->tagmap = tagmap_new(); int nr=0; TAG*t = tag; while(t) {nr++;t=t->next;} taglist->taglist = PyList_New(nr); + + mylog("+%08x(%d) taglist_new2: %d items", (int)taglist, taglist->ob_refcnt, nr); nr = 0; t = tag; while(t) { - PyObject*newtag = tag_new(tag); + PyObject*newtag = tag_new2(tag, taglist->tagmap); PyList_SET_ITEM(taglist->taglist,nr,newtag);Py_INCREF(newtag); if(swf_isDefiningTag(t)) { tagmap_add(taglist->tagmap, newtag); diff --git a/lib/python/tagmap.c b/lib/python/tagmap.c index 055d035..317d817 100644 --- a/lib/python/tagmap.c +++ b/lib/python/tagmap.c @@ -90,6 +90,27 @@ int tagmap_getFreeID(PyObject*self) return -1; } //---------------------------------------------------------------------------- +static void tagmap_add_mapping(PyObject*self, int id, PyObject* obj) +{ + TagMapObject*tagmap = (TagMapObject*)self; + PyList_Append(tagmap->objlist, obj);//Py_INCREF(obj); done by PyList_Append + PyObject*id_obj = PyLong_FromLong(id); + PyDict_SetItem(tagmap->obj2id, obj, id_obj);//Py_INCREF(id_obj);Py_INCREF(obj); done by PyDict_SetItem + PyDict_SetItem(tagmap->id2obj, id_obj, obj);//Py_INCREF(id_obj);Py_INCREF(obj); done by PyDict_SetItem + Py_DECREF(id_obj); +} +//---------------------------------------------------------------------------- +void tagmap_addMapping(PyObject*self, int id, PyObject* obj) +{ + TagMapObject*tagmap = (TagMapObject*)self; + int id2 = tagmap_obj2id(self, obj); + if(id2>=0) { + assert(id==id2); + return; + } + tagmap_add_mapping(self, id, obj); +} +//---------------------------------------------------------------------------- int tagmap_add(PyObject* self, PyObject* obj) { TagMapObject*tagmap = (TagMapObject*)self; @@ -99,11 +120,9 @@ int tagmap_add(PyObject* self, PyObject* obj) return id; } id = tagmap_getFreeID(self); - PyList_Append(tagmap->objlist, obj);//Py_INCREF(obj); done by PyList_Append - PyObject*id_obj = PyLong_FromLong(id); - PyDict_SetItem(tagmap->obj2id, obj, id_obj);//Py_INCREF(id_obj);Py_INCREF(obj); done by PyDict_SetItem - PyDict_SetItem(tagmap->id2obj, id_obj, obj);//Py_INCREF(id_obj);Py_INCREF(obj); done by PyDict_SetItem - Py_DECREF(id_obj); + + tagmap_add_mapping(self, id, obj); + mylog(" %08x(%d) tagmap_add %08x->%d", (int)self, self->ob_refcnt, (int)obj, id); return id; } diff --git a/lib/python/tagmap.h b/lib/python/tagmap.h index ccaaf88..d35aa43 100644 --- a/lib/python/tagmap.h +++ b/lib/python/tagmap.h @@ -31,6 +31,7 @@ extern PyTypeObject TagMapClass; int tagmap_obj2id(PyObject* self, PyObject* obj); PyObject* tagmap_id2obj(PyObject* self, int _id); int tagmap_add(PyObject* self, PyObject* obj); +void tagmap_addMapping(PyObject*self, int id, PyObject*obj); PyObject* tagmap_getObjectList(PyObject* self); PyObject* tagmap_new();