image tags now have an "image" attribute
[swftools.git] / lib / python / tags.c
index ee86831..f28f1b6 100644 (file)
@@ -83,8 +83,7 @@ static tag_internals_t font_tag =
 typedef struct _placeobject_internal
 {
     SWFPLACEOBJECT* po;
-
-    //PyObject*character //TODO
+    PyObject*character;
 } placeobject_internal_t;
 staticforward tag_internals_t placeobject_tag;
 
@@ -98,10 +97,25 @@ static void po_dealloc(tag_internals_t*self)
 }
 static int po_parse(tag_internals_t*self)
 {
-    placeobject_internal_t*pi = (placeobject_internal_t*)self->data;
-    /* TODO */
-    PyErr_SetString(PyExc_Exception, setError("Placeobject parsing not implemented yet"));
-    return 0;
+    placeobject_internal_t*i = (placeobject_internal_t*)self->data;
+    if(i->po)
+       return 1;
+    if(!self->tag)
+       return 0;
+    SWFPLACEOBJECT* swfpo = malloc(sizeof(SWFPLACEOBJECT));
+    swf_GetPlaceObject(self->tag, swfpo);
+    i->po = swfpo;
+    swf_DeleteTag(self->tag);self->tag = 0;
+       
+    if(i->po->id) {
+       i->character = tagmap_id2obj(self->tagmap, i->po->id);
+       if(i->character) {
+           Py_INCREF(i->character);
+       } else {
+           //PyErr_Clear(); //?
+       }
+    }
+    return 1;
 }
 static int po_fillTAG(tag_internals_t*self)
 {
@@ -112,8 +126,17 @@ static int po_fillTAG(tag_internals_t*self)
 }
 static PyObject* po_getattr(tag_internals_t*self,char*a)
 {
-    placeobject_internal_t*si = (placeobject_internal_t*)self->data;
-    if(!strcmp(a, "cxform")) {
+    placeobject_internal_t*i = (placeobject_internal_t*)self->data;
+    if(!po_parse(self))
+       return PY_ERROR("Couldn't parse placeobject");
+    if(!strcmp(a, "character")) {
+       if(!i->character)
+           return PY_NONE;
+       Py_INCREF(i->character); //TODO: ??
+       return i->character;
+    } else if(!strcmp(a, "matrix")) {
+       return f_Matrix2(&i->po->matrix);
+    } else if(!strcmp(a, "cxform")) {
        /* TODO */
        return 0;
     }
@@ -536,6 +559,22 @@ static void image_dealloc(tag_internals_t*self)
        free(pi->rgba);pi->rgba = 0;
     }
 }
+static int image_parse(tag_internals_t*self)
+{
+    image_internal_t*i= (image_internal_t*)self->data;
+    if(i->rgba)
+       return 1;
+    if(!self->tag)
+       return 0;
+   
+    i->rgba = swf_ExtractImage(self->tag, &i->width, &i->height);
+    i->bpp = 32;
+    i->isindexed = 0;
+    i->islossless = 1;
+
+    swf_DeleteTag(self->tag);self->tag = 0;
+    return 1;
+}
 static int imagetag_getWidth(PyObject* self)
 {
     tag_internals_t*itag = tag_getinternals(self);
@@ -573,12 +612,24 @@ static PyObject* f_DefineImage(PyObject* self, PyObject* args, PyObject* kwargs)
 
     return (PyObject*)tag;
 }
+static PyObject* image_getattr(tag_internals_t*self,char*a)
+{
+    image_internal_t*i = (image_internal_t*)self->data;
+    if(!strcmp(a, "image")) {
+       if(!i->rgba) {
+           image_parse(self);
+       }
+       PyObject* image = rgba_to_image(i->rgba, i->width, i->height);
+       return image;
+    }
+    return 0;
+}
 static tag_internals_t image_tag =
 {
-    parse: 0,
+    parse: image_parse,
     fillTAG: image_fillTAG,
     dealloc: image_dealloc,
-    getattr: 0, 
+    getattr: image_getattr, 
     setattr: 0,
     tagfunctions: 0,
     datasize: sizeof(image_internal_t),