X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpython%2Ftags.c;h=9282ae81fa05d6a71660a5606072b271938cfabc;hb=a3560d1f6a09b76b62683fd089572f75ca9cc4be;hp=54625e61b114328113f0491a99f38b015af24d47;hpb=3477d799207e51e1cde8d1d8792ae838cc1f2835;p=swftools.git diff --git a/lib/python/tags.c b/lib/python/tags.c index 54625e6..9282ae8 100644 --- a/lib/python/tags.c +++ b/lib/python/tags.c @@ -3,6 +3,7 @@ #include "action.h" #include "tag.h" #include "tags.h" +#include "image.h" //---------------------------------------------------------------------------- @@ -104,7 +105,7 @@ static int po_fillTAG(tag_internals_t*self) swf_SetPlaceObject(self->tag, pi->po); return 1; } -static PyObject* f_PlaceObject(PyObject* self, PyObject* args, PyObject* kwargs) +static PyObject* po_create(PyObject* self, PyObject* args, PyObject* kwargs,char move) { static char *kwlist[] = {"character", "depth", "matrix", "colortransform", "ratio", "name", "clipdepth", "action", NULL}; @@ -138,6 +139,7 @@ static PyObject* f_PlaceObject(PyObject* self, PyObject* args, PyObject* kwargs) po->clipdepth = clipdepth; po->ratio = ratio; po->name = name; + po->move = move; if(clipdepth) po->clipdepth = clipdepth; if(matrix) po->matrix = matrix_getMatrix(matrix); if(cxform) po->cxform = colortransform_getCXForm(cxform); @@ -154,6 +156,14 @@ static PyObject* f_PlaceObject(PyObject* self, PyObject* args, PyObject* kwargs) return (PyObject*)tag; } +static PyObject* f_PlaceObject(PyObject* self, PyObject* args, PyObject* kwargs) +{ + return po_create(self, args, kwargs, 0); +} +static PyObject* f_MoveObject(PyObject* self, PyObject* args, PyObject* kwargs) +{ + return po_create(self, args, kwargs, 1); +} static tag_internals_t placeobject_tag = { parse: po_parse, @@ -241,6 +251,29 @@ static tag_internals_t protect_tag = datasize: 0, }; //---------------------------------------------------------------------------- +staticforward tag_internals_t showframe_tag; +static PyObject* f_ShowFrame(PyObject* self, PyObject* args, PyObject* kwargs) +{ + static char *kwlist[] = {"name", NULL}; + char*name= 0; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &name)) + return NULL; + + PyObject*tag = tag_new(&showframe_tag); + tag_internals_t*itag = tag_getinternals(tag); + itag->tag = swf_InsertTag(0, ST_SHOWFRAME); + mylog("+%08x(%d) f_ShowFrame", (int)tag, tag->ob_refcnt); + return (PyObject*)tag; +} +static tag_internals_t showframe_tag = +{ + parse: 0, + fillTAG: 0, + dealloc: 0, + tagfunctions: 0, + datasize: 0, +}; +//---------------------------------------------------------------------------- staticforward tag_internals_t end_tag; static tag_internals_t end_tag = { @@ -317,12 +350,145 @@ static tag_internals_t text_tag = datasize: sizeof(text_internal_t), }; //---------------------------------------------------------------------------- +staticforward tag_internals_t image_tag; + +typedef struct _image_internal +{ + RGBA*rgba; + int size; + int width; + int height; + int bpp; + char isindexed; + char islossless; +} image_internal_t; +staticforward tag_internals_t image_tag; + +static int image_fillTAG(tag_internals_t*self) +{ + image_internal_t*ti = (image_internal_t*)self->data; + self->tag= swf_InsertTag(0, ST_DEFINEBITSLOSSLESS2); + swf_SetU16(self->tag, /*ID*/0); + swf_SetLosslessBits(self->tag, ti->width, ti->height, ti->rgba, BMF_32BIT); + return 1; +} +static void image_dealloc(tag_internals_t*self) +{ + image_internal_t*pi = (image_internal_t*)self->data; + if(pi->rgba) { + free(pi->rgba);pi->rgba = 0; + } +} +static int imagetag_getWidth(PyObject* self) +{ + tag_internals_t*itag = tag_getinternals(self); + image_internal_t*pi = (image_internal_t*)itag->data; + return pi->width; +} +static int imagetag_getHeight(PyObject* self) +{ + tag_internals_t*itag = tag_getinternals(self); + image_internal_t*pi = (image_internal_t*)itag->data; + return pi->height; +} +static PyObject* f_DefineImage(PyObject* self, PyObject* args, PyObject* kwargs) +{ + static char *kwlist[] = {"image"}; + PyObject*image = 0; + PyObject*tag = tag_new(&image_tag); + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist, &image)) + return NULL; + + tag = tag_new(&image_tag); + tag_internals_t* itag = tag_getinternals(tag); + image_internal_t*ti = (image_internal_t*)itag->data; + + ti->rgba = image_toRGBA(image); + if(!ti->rgba) // pass through exception + return 0; + ti->width = image_getWidth(image); + ti->height = image_getHeight(image); + ti->isindexed = 0; + ti->islossless = 1; + ti->bpp = 32; + ti->size = ti->width*ti->height; + + return (PyObject*)tag; +} +static tag_internals_t image_tag = +{ + parse: 0, + fillTAG: image_fillTAG, + dealloc: image_dealloc, + tagfunctions: 0, + datasize: sizeof(image_internal_t), +}; +//---------------------------------------------------------------------------- +staticforward tag_internals_t shape_tag; + +typedef struct _shape_internal +{ + SHAPE2*shape; +} shape_internal_t; +staticforward tag_internals_t shape_tag; + +static int shape_fillTAG(tag_internals_t*self) +{ + shape_internal_t*ti = (shape_internal_t*)self->data; + self->tag= swf_InsertTag(0, ST_DEFINESHAPE3); + swf_SetU16(self->tag, /*ID*/0); + swf_SetShape2(self->tag, ti->shape); + return 1; +} +static void shape_dealloc(tag_internals_t*self) +{ + shape_internal_t*pi = (shape_internal_t*)self->data; + if(pi->shape) { + swf_Shape2Free(pi->shape); + pi->shape = 0; + } +} +static PyObject* f_DefineImageShape(PyObject* self, PyObject* args, PyObject* kwargs) +{ + static char *kwlist[] = {"image"}; + PyObject*shape = 0; + PyObject*tag = tag_new(&shape_tag); + PyObject*image = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!", kwlist, &TagClass, &image)) + return NULL; + + tag = tag_new(&shape_tag); + tag_internals_t* itag = tag_getinternals(tag); + shape_internal_t*ti = (shape_internal_t*)itag->data; + ti->shape = 0; /*HACK*/ + + int width = imagetag_getWidth(image); + int height = imagetag_getHeight(image); + int id = tagmap_add(itag->tagmap, image); + itag->tag= swf_InsertTag(0, ST_DEFINESHAPE3); + swf_SetU16(itag->tag, 0); + swf_ShapeSetBitmapRect(itag->tag, id, width, height); + return (PyObject*)tag; +} +static tag_internals_t shape_tag = +{ + parse: 0, + fillTAG: shape_fillTAG, + dealloc: shape_dealloc, + tagfunctions: 0, + datasize: sizeof(shape_internal_t), +}; +//---------------------------------------------------------------------------- typedef struct _videostream_internal { VIDEOSTREAM* stream; + int lastiframe; } videostream_internal_t; staticforward tag_internals_t videostream_tag; +staticforward tag_internals_t videoframe_tag; static int videostream_parse(tag_internals_t*self) { @@ -345,18 +511,19 @@ static int videostream_fillTAG(tag_internals_t*self) videostream_internal_t*fi = (videostream_internal_t*)self->data; if(self->tag) return 1; - /* TODO */ - PyErr_SetString(PyExc_Exception, setError("videostream filling not implemented yet"));return 0; - return 1; + PyErr_SetString(PyExc_Exception, setError("videostream filling not implemented")); + return 0; } static PyObject* f_DefineVideoStream(PyObject* self, PyObject* args, PyObject* kwargs) { PyObject*tag = tag_new(&videostream_tag); - int width=0,height=0,quant=7,frames=65535; - static char *kwlist[] = {"width", "height", "quant", "frames", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|ii", kwlist, &TagClass, &width, &height, &quant, &frames)) + int width=0,height=0,frames=65535; + static char *kwlist[] = {"width", "height", "frames", NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|i", kwlist, &width, &height, &frames)) return NULL; + + printf(": %d %d\n", width, height); tag_internals_t*itag = tag_getinternals(tag); videostream_internal_t*fi = (videostream_internal_t*)itag->data; @@ -364,7 +531,10 @@ static PyObject* f_DefineVideoStream(PyObject* self, PyObject* args, PyObject* k memset(fi->stream, 0, sizeof(VIDEOSTREAM)); TAG*t = swf_InsertTag(0, ST_DEFINEVIDEOSTREAM); + swf_SetU16(t, 0); /* id */ swf_SetVideoStreamDefine(t, fi->stream, frames, width, height); + itag->tag = t; + fi->lastiframe = -65536; return (PyObject*)tag; } static VIDEOSTREAM* videostream_getVIDEOSTREAM(PyObject*self) @@ -388,33 +558,61 @@ static PyObject* videostream_getbheight(PyObject*self, PyObject*args) int height = fi->stream->bby; return Py_BuildValue("i", height); } -static PyObject* videostream_addIFrame(PyObject*self, PyObject*args) -{ - tag_internals_t*itag = tag_getinternals(self); - videostream_internal_t*fi = (videostream_internal_t*)itag->data; - /* TODO */ - return Py_BuildValue("s", 0); -} -static PyObject* videostream_addPFrame(PyObject*self, PyObject*args) +static PyObject* videostream_addFrame(PyObject*self, PyObject*args, PyObject*kwargs) { - tag_internals_t*itag = tag_getinternals(self); - videostream_internal_t*fi = (videostream_internal_t*)itag->data; - /* TODO */ - return Py_BuildValue("s", 0); + tag_internals_t*_itag = tag_getinternals(self); + videostream_internal_t*fi = (videostream_internal_t*)_itag->data; + + PyObject*image = 0; + char*type=0; // none, "i", "p" + int quant=7; + static char *kwlist[] = {"image", "quant", "type", NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|is", kwlist, &image, &quant, &type)) + return NULL; + if(fi->stream->width != image_getWidth(image)) { + PyErr_SetString(PyExc_Exception, setError("bad image width %d!=%d", image_getWidth(image), fi->stream->width));return 0; + } + if(fi->stream->height != image_getHeight(image)) { + PyErr_SetString(PyExc_Exception, setError("bad image width %d!=%d", image_getHeight(image), fi->stream->height));return 0; + } + PyObject*tag = tag_new(&videoframe_tag); + tag_internals_t*itag = tag_getinternals(tag); + + RGBA*pic = image_toRGBA(image); + if(!pic) + return 0; + TAG* t = swf_InsertTag(0, ST_VIDEOFRAME); + if((type && (type[0]=='I' || type[0]=='i')) || (type==0 && fi->lastiframe+64 < fi->stream->frame)) { + swf_SetU16(t,0); + swf_SetVideoStreamIFrame(t, fi->stream, pic, quant); + fi->lastiframe = fi->stream->frame; + } else { + swf_SetU16(t,0); + swf_SetVideoStreamPFrame(t, fi->stream, pic, quant); + } + itag->tag = t; + tagmap_addMapping(itag->tagmap, 0, self); + free(pic); + return tag; } static PyObject* videostream_addDistortionFrame(PyObject*self, PyObject*args) { - tag_internals_t*itag = tag_getinternals(self); - videostream_internal_t*fi = (videostream_internal_t*)itag->data; - /* TODO */ - return Py_BuildValue("s", 0); + tag_internals_t*_itag = tag_getinternals(self); + videostream_internal_t*fi = (videostream_internal_t*)_itag->data; + + PyObject*tag = tag_new(&videoframe_tag); + tag_internals_t*itag = tag_getinternals(tag); + /* DUMMY */ + TAG* t = swf_InsertTag(0, ST_REFLEX); + itag->tag = t; + + return tag; } static PyMethodDef videostream_methods[] = {{"xblocks", videostream_getbwidth, METH_VARARGS, "get's the number of horizontal blocks"}, {"yblocks", videostream_getbheight, METH_VARARGS, "get's the number of vertical blocks"}, - {"addIFrame", videostream_addIFrame, METH_VARARGS, "add a I Video Frame"}, - {"addPFrame", videostream_addPFrame, METH_VARARGS, "add a P Video Frame"}, - {"addDistortionFrame", videostream_addDistortionFrame, METH_VARARGS, "add a MVD frame"}, + {"addFrame", (PyCFunction)videostream_addFrame, METH_KEYWORDS, "add a Video Frame"}, + {"addDistortionFrame", (PyCFunction)videostream_addDistortionFrame, METH_KEYWORDS, "add a MVD frame"}, {NULL, NULL, 0, NULL} }; @@ -429,6 +627,17 @@ static tag_internals_t videostream_tag = //============================================================================ +static tag_internals_t videoframe_tag = +{ + parse: 0, + fillTAG: 0, + dealloc: 0, + tagfunctions: 0, + datasize: 0 +}; + +//============================================================================ + static PyMethodDef TagMethods[] = { /* TAGS */ @@ -437,7 +646,11 @@ static PyMethodDef TagMethods[] = {"Font", (PyCFunction)f_DefineFont, METH_KEYWORDS, "Create a DefineFont Tag."}, {"Text", (PyCFunction)f_DefineText, METH_KEYWORDS, "Create a DefineText Tag."}, {"PlaceObject", (PyCFunction)f_PlaceObject, METH_KEYWORDS, "Create a PlaceObject Tag."}, + {"MoveObject", (PyCFunction)f_MoveObject, METH_KEYWORDS, "Create a PlaceObject Move Tag."}, {"VideoStream", (PyCFunction)f_DefineVideoStream, METH_KEYWORDS, "Create a Videostream."}, + {"Image", (PyCFunction)f_DefineImage, METH_KEYWORDS, "Create an SWF Image Tag."}, + {"ImageShape", (PyCFunction)f_DefineImageShape, METH_KEYWORDS, "Create an SWF Image Shape Tag."}, + {"ShowFrame", (PyCFunction)f_ShowFrame, METH_KEYWORDS, "Create an SWF Show Frame Tag."}, {NULL, NULL, 0, NULL} }; PyMethodDef* tags_getMethods() @@ -450,6 +663,11 @@ PyMethodDef* tags_getMethods() register_tag(ST_DEFINEFONT,&font_tag); register_tag(ST_PROTECT,&protect_tag); register_tag(ST_DEFINETEXT,&text_tag); + register_tag(ST_DEFINEBITSJPEG,&image_tag); + register_tag(ST_DEFINEBITSJPEG2,&image_tag); + register_tag(ST_DEFINEBITSJPEG3,&image_tag); + register_tag(ST_DEFINEBITSLOSSLESS,&image_tag); + register_tag(ST_DEFINEBITSLOSSLESS2,&image_tag); register_tag(ST_END,&end_tag); return TagMethods;