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
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);
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;
}
//----------------------------------------------------------------------------
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)
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;i<num;i++) {
+ int id = GET16(&t->data[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;
}
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);
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;
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);
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;
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;
}
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();