X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpython%2Ftags.c;h=2cd47c951a190735f2b35027a680291af194a9ca;hb=879d0eec420fe0fd5ddcd56c8fe62b82a6744edd;hp=17db3e2de0900f6d9c5e7f513b617c5b67a21884;hpb=345f8f47f72e16c0c70c1dc89f3b65e873cb1738;p=swftools.git diff --git a/lib/python/tags.c b/lib/python/tags.c index 17db3e2..2cd47c9 100644 --- a/lib/python/tags.c +++ b/lib/python/tags.c @@ -5,6 +5,7 @@ #include "tag.h" #include "tags.h" #include "image.h" +#include "../png.h" //---------------------------------------------------------------------------- @@ -48,7 +49,7 @@ static PyObject* f_DefineFont(PyObject* self, PyObject* args, PyObject* kwargs) if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &filename)) return NULL; - font = swf_LoadFont(filename); + font = swf_LoadFont(filename, 0); if(!font) { PyErr_SetString(PyExc_Exception, setError("Could not load %s", filename)); return NULL; @@ -105,7 +106,7 @@ static int po_parse(tag_internals_t*self) SWFPLACEOBJECT* swfpo = malloc(sizeof(SWFPLACEOBJECT)); swf_GetPlaceObject(self->tag, swfpo); i->po = swfpo; - swf_DeleteTag(self->tag);self->tag = 0; + swf_DeleteTag(0, self->tag);self->tag = 0; if(i->po->id) { i->character = tagmap_id2obj(self->tagmap, i->po->id); @@ -419,7 +420,7 @@ static int sprite_setattr(tag_internals_t*self,char*a, PyObject*obj) { sprite_internal_t*si = (sprite_internal_t*)self->data; if(self->tag) { - swf_DeleteTag(self->tag); + swf_DeleteTag(0, self->tag); self->tag = 0; } if(!strcmp(a, "tags")) { @@ -559,6 +560,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(0, self->tag);self->tag = 0; + return 1; +} static int imagetag_getWidth(PyObject* self) { tag_internals_t*itag = tag_getinternals(self); @@ -596,14 +613,48 @@ 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 PyObject* image_save(PyObject*self, PyObject*args) +{ + tag_internals_t*itag = tag_getinternals(self); + if(!image_parse(itag)) + return PY_ERROR("Couldn't parse image"); + image_internal_t*fi = (image_internal_t*)itag->data; + + char*filename = 0; + if(!PyArg_ParseTuple(args, "s", &filename)) + return NULL; + + writePNG(filename, (unsigned char*)fi->rgba ,fi->width, fi->height); + + return PY_NONE; +} + +static PyMethodDef image_methods[] = +{{"save", image_save, METH_VARARGS, "saves an image as PNG"}, + {NULL, NULL, 0, NULL} +}; + 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, + tagfunctions: image_methods, datasize: sizeof(image_internal_t), }; //---------------------------------------------------------------------------- @@ -633,7 +684,7 @@ static int shape_parse(tag_internals_t*self) SHAPE2* shape2 = malloc(sizeof(SHAPE2)); swf_ParseDefineShape(self->tag, shape2); i->shape2 = shape2; - swf_DeleteTag(self->tag);self->tag = 0; + swf_DeleteTag(0, self->tag);self->tag = 0; return 1; } static void shape_dealloc(tag_internals_t*self)