X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpython%2Ftags.c;h=329b69f449c6a1497ea8a10614102c16c859011d;hb=e8d1f9a89eefc8035f91e296f1f6e6833d88b000;hp=e642125b8a83b9a9db5372d956180c936c1f44ef;hpb=8adbe9a5797deaff48d42b34bc3405bb7c0633cb;p=swftools.git diff --git a/lib/python/tags.c b/lib/python/tags.c index e642125..329b69f 100644 --- a/lib/python/tags.c +++ b/lib/python/tags.c @@ -105,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}; @@ -135,10 +135,10 @@ static PyObject* f_PlaceObject(PyObject* self, PyObject* args, PyObject* kwargs) )) return NULL; po->depth = depth; - po->id = /*ID*/ 0; 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); @@ -149,12 +149,24 @@ static PyObject* f_PlaceObject(PyObject* self, PyObject* args, PyObject* kwargs) tag_internals_t*itag = tag_getinternals(tag); placeobject_internal_t*pi = (placeobject_internal_t*)itag->data; pi->po = po; - pi->po->id = tagmap_add(itag->tagmap,(PyObject*)character); + if(!move) { + pi->po->id = tagmap_add(itag->tagmap,(PyObject*)character); + } else { + pi->po->id = 0; + } mylog("+%08x(%d) PlaceObject %08x(%d)\n", (int)tag, tag->ob_refcnt, character, character->ob_refcnt); 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, @@ -242,6 +254,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 = { @@ -347,6 +382,18 @@ static void image_dealloc(tag_internals_t*self) 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"}; @@ -420,8 +467,8 @@ static PyObject* f_DefineImageShape(PyObject* self, PyObject* args, PyObject* kw shape_internal_t*ti = (shape_internal_t*)itag->data; ti->shape = 0; /*HACK*/ - int width = image_getWidth(image); - int height = image_getHeight(image); + 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); @@ -467,9 +514,8 @@ 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) { @@ -477,8 +523,10 @@ static PyObject* f_DefineVideoStream(PyObject* self, PyObject* args, PyObject* k int width=0,height=0,frames=65535; static char *kwlist[] = {"width", "height", "frames", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|i", kwlist, &TagClass, &width, &height, &frames)) + 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; @@ -486,7 +534,9 @@ 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; } @@ -532,9 +582,32 @@ static PyObject* videostream_addFrame(PyObject*self, PyObject*args, PyObject*kwa tag_internals_t*itag = tag_getinternals(tag); RGBA*pic = image_toRGBA(image); + if(!pic) + return 0; + + +{ int f,j=0,i=0,rr,gg,bb; + FILE *o; + RGBA*it = pic; + char*filename="test.ppm"; + printf("Creating %s %dx%d\n",filename, 512,512); + o=fopen(filename, "wb"); + fprintf(o,"P6\n%d %d\n255\n",512, 512); + + while(j<512*512) { + rr=it->r; + gg=it->g; + bb=it->b; + fprintf(o,"%c%c%c",rr,gg,bb); + it++; + j++; + } + fclose(o); +} + 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_SetU16(t,0); /* id */ swf_SetVideoStreamIFrame(t, fi->stream, pic, quant); fi->lastiframe = fi->stream->frame; } else { @@ -544,15 +617,66 @@ static PyObject* videostream_addFrame(PyObject*self, PyObject*args, PyObject*kwa itag->tag = t; tagmap_addMapping(itag->tagmap, 0, self); free(pic); - return Py_BuildValue("s", 0); + return tag; } -static PyObject* videostream_addDistortionFrame(PyObject*self, PyObject*args) +static PyObject* videostream_addDistortionFrame(PyObject*self, PyObject*args, PyObject*kwargs) { - tag_internals_t*itag = tag_getinternals(self); - videostream_internal_t*fi = (videostream_internal_t*)itag->data; + tag_internals_t*_itag = tag_getinternals(self); + videostream_internal_t*fi = (videostream_internal_t*)_itag->data; - /* TODO */ - return Py_BuildValue("s", 0); + static char *kwlist[] = {"image", "quant", NULL}; + int quant=7; + PyObject* array = 0; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i", kwlist, &array, &quant)) + return NULL; + + signed char* movex = malloc(fi->stream->bbx * fi->stream->bby); + signed char* movey = malloc(fi->stream->bbx * fi->stream->bby); + signed char* itx=movex; + signed char* ity=movey; + int x,y; + if(!array || !PySequence_Check(array)) + return PY_ERROR("Not an array"); + if(PySequence_Length(array) < fi->stream->bby) + return PY_ERROR("Array (y) has to have at least %d elements, but has only %d ", fi->stream->bby, PySequence_Length(array)); + for(y=0;ystream->bby;y++) { + PyObject*line = PySequence_GetItem(array, y); + if(!line || !PySequence_Check(line)) + return PY_ERROR("Not an array of arrays"); + if(PySequence_Length(line) < fi->stream->bbx) + return PY_ERROR("Inner arrays (x) have to be at least %d long- %dth is only %d", fi->stream->bbx, y, PySequence_Length(line)); + + for(x=0;xstream->bbx;x++) { + PyObject*pixel = PySequence_GetItem(line, x); + if(!pixel) { + *itx = 0; + *ity = 0; + } else { + if(!PyComplex_Check(pixel)) { + return PY_ERROR("Not an array of arrays of complex numbers"); + } + *itx = (signed char)PyComplex_RealAsDouble(pixel); + *ity = (signed char)PyComplex_ImagAsDouble(pixel); + } + itx++; + ity++; + } + } + + PyObject*tag = tag_new(&videoframe_tag); + tag_internals_t*itag = tag_getinternals(tag); + + TAG* t = swf_InsertTag(0, ST_VIDEOFRAME); + swf_SetU16(t,0); /* id */ + swf_SetVideoStreamMover(t, fi->stream, movex, movey, quant); + + itag->tag = t; + tagmap_addMapping(itag->tagmap, 0, self); + + free(movex); + free(movey); + + return tag; } static PyMethodDef videostream_methods[] = {{"xblocks", videostream_getbwidth, METH_VARARGS, "get's the number of horizontal blocks"}, @@ -592,9 +716,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() @@ -616,4 +742,3 @@ PyMethodDef* tags_getMethods() return TagMethods; } -