SWFPLACEOBJECT* po;
po = malloc(sizeof(SWFPLACEOBJECT));
memset(po, 0, sizeof(SWFPLACEOBJECT));
-
+
swf_GetPlaceObject(0, po);
-
+
+ PyErr_Clear();
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oi|O!O!isiO!", kwlist,
&character,
&depth,
&ActionClass, &action
))
return NULL;
+
po->depth = depth;
po->clipdepth = clipdepth;
po->ratio = ratio;
text_internal_t*ti = (text_internal_t*)self->data;
self->tag= swf_InsertTag(0, ST_DEFINETEXT2);
swf_SetU16(self->tag, /*ID*/0);
- ti->bbox = swf_SetDefineText(self->tag, ti->swffont, &ti->rgba, ti->text, ti->size, 0);
+ ti->bbox = swf_SetDefineText(self->tag, ti->swffont, &ti->rgba, ti->text, ti->size);
return 1;
}
static PyObject* text_getattr(tag_internals_t*self,char*a)
}
static PyObject* f_DefineImage(PyObject* self, PyObject* args, PyObject* kwargs)
{
- static char *kwlist[] = {"image"};
+ static char *kwlist[] = {"image", NULL};
PyObject*image = 0;
PyObject*tag = tag_new(&image_tag);
typedef struct _shape_internal
{
- SHAPE2*shape;
+ SHAPE2*shape2;
} shape_internal_t;
staticforward tag_internals_t shape_tag;
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);
+ swf_SetShape2(self->tag, ti->shape2);
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;
+ if(pi->shape2) {
+ swf_Shape2Free(pi->shape2);
+ pi->shape2 = 0;
}
}
static PyObject* f_DefineImageShape(PyObject* self, PyObject* args, PyObject* kwargs)
{
- static char *kwlist[] = {"image"};
- PyObject*shape = 0;
- PyObject*tag = tag_new(&shape_tag);
+ static char *kwlist[] = {"image", NULL};
PyObject*image = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!", kwlist, &TagClass, &image))
return NULL;
- tag = tag_new(&shape_tag);
+ PyObject*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*/
+ ti->shape2 = 0; /*HACK*/
int width = imagetag_getWidth(image);
int height = imagetag_getHeight(image);
swf_ShapeSetBitmapRect(itag->tag, id, width, height);
return (PyObject*)tag;
}
+
+/* TODO: move to lib/ */
+SHAPE2*swf_StringToShape2(char*s,FILLSTYLE*f, LINESTYLE*l)
+{
+ drawer_t draw;
+ swf_Shape11DrawerInit(&draw, 0);
+ draw_string(&draw, s);
+ draw.finish(&draw);
+ SHAPE*s1 = swf_ShapeDrawerToShape(&draw);
+ SRECT r = swf_ShapeDrawerGetBBox(&draw);
+ RGBA col;col.r=col.g=col.b=128;col.a=255;
+ if(l)
+ swf_ShapeAddLineStyle(s1, 1, &col);
+ if(f)
+ swf_ShapeAddSolidFillStyle(s1, &col);
+ draw.dealloc(&draw);
+ SHAPE2*shape2 = swf_ShapeToShape2(s1);
+ swf_ShapeFree(s1);
+ shape2->bbox = malloc(sizeof(SRECT));
+ *(shape2->bbox) = r;
+ if(f && shape2->numfillstyles)
+ shape2->fillstyles[0] = *f;
+ if(l && shape2->numlinestyles)
+ shape2->linestyles[0] = *l;
+ return shape2;
+}
+
+static PyObject* f_DefineShape(PyObject* self, PyObject* args, PyObject* kwargs)
+{
+ static char *kwlist[] = {"s", "fill", "line", NULL};
+ char*s = 0;
+ PyObject*fillstyle=0,*linestyle=0;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OO", kwlist, &s,&fillstyle,&linestyle))
+ return NULL;
+
+ PyObject*tag = tag_new(&shape_tag);
+ tag_internals_t* itag = tag_getinternals(tag);
+ shape_internal_t*ti = (shape_internal_t*)itag->data;
+
+ FILLSTYLE _f,*f=0;
+ LINESTYLE _l,*l=0;
+
+ if(fillstyle) {
+ f = &_f;
+ if(PY_CHECK_TYPE(fillstyle, &ColorClass)) {
+ f->type = /*FILL_SOLID*/ 0;
+ f->color = color_getRGBA(fillstyle);
+ } else {
+ return PY_ERROR("Invalid Fillstyle");
+ }
+ }
+
+ if(linestyle) {
+ l = &_l;
+ if(PyTuple_Check(linestyle) && PyTuple_GET_SIZE(linestyle)==2) {
+ float f = 0.0;
+ PyObject*color = 0;
+ if(!PyArg_ParseTuple(linestyle, "fO!", &f, &ColorClass, &color))
+ return 0;
+
+ l->width = (int)(f*20);
+ l->color = color_getRGBA(color);
+ } else {
+ return PY_ERROR("Invalid Linestyle");
+ }
+ }
+ ti->shape2 = swf_StringToShape2(s,f,l);
+
+ itag->tag = 0;
+
+ return (PyObject*)tag;
+}
+static PyObject* shape_getfillstyles(PyObject*self, PyObject*args)
+{
+ tag_internals_t*itag = tag_getinternals(self);
+ shape_internal_t*fi = (shape_internal_t*)itag->data;
+ int num = fi->shape2->numfillstyles;
+ return Py_BuildValue("i", num);
+}
+static PyObject* shape_getlinestyles(PyObject*self, PyObject*args)
+{
+ tag_internals_t*itag = tag_getinternals(self);
+ shape_internal_t*fi = (shape_internal_t*)itag->data;
+ int num = fi->shape2->numlinestyles;
+ return Py_BuildValue("i", num);
+}
+static PyMethodDef shape_methods[] =
+{{"fillstyles", shape_getfillstyles, METH_VARARGS, "get's the number of fillstyles"},
+ {"linestyles", shape_getlinestyles, METH_VARARGS, "get's the number of linestyles"},
+ {NULL, NULL, 0, NULL}
+};
+
static tag_internals_t shape_tag =
{
parse: 0,
dealloc: shape_dealloc,
getattr: 0,
setattr: 0,
- tagfunctions: 0,
+ tagfunctions: shape_methods,
datasize: sizeof(shape_internal_t),
};
//----------------------------------------------------------------------------
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;
fi->stream = malloc(sizeof(VIDEOSTREAM));
int height = fi->stream->bby;
return Py_BuildValue("i", height);
}
+static PyObject* videostream_addBlackFrame(PyObject*self, PyObject*args, PyObject*kwargs)
+{
+ tag_internals_t*_itag = tag_getinternals(self);
+ videostream_internal_t*fi = (videostream_internal_t*)_itag->data;
+
+ TAG* t = swf_InsertTag(0, ST_VIDEOFRAME);
+
+ PyObject*tag = tag_new(&videoframe_tag);
+ tag_internals_t*itag = tag_getinternals(tag);
+
+ swf_SetU16(t,0); /* id */
+ swf_SetVideoStreamBlackFrame(t, fi->stream);
+ fi->lastiframe = fi->stream->frame;
+
+ itag->tag = t;
+ tagmap_addMapping(itag->tagmap, 0, self);
+ return tag;
+}
static PyObject* videostream_addFrame(PyObject*self, PyObject*args, PyObject*kwargs)
{
tag_internals_t*_itag = tag_getinternals(self);
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)) {
+ if(fi->stream->width != image_getWidth(image) &&
+ fi->stream->owidth != 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)) {
+ if(fi->stream->height != image_getHeight(image) &&
+ fi->stream->oheight != 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);
if(!pic)
return 0;
-
-{ int f,j=0,i=0,rr,gg,bb;
+/*{ int f,j=0,i=0,rr,gg,bb;
FILE *o;
RGBA*it = pic;
char*filename="test.ppm";
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)) {
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* movex = malloc(fi->stream->bbx * fi->stream->bby * 1);
+ signed char* movey = malloc(fi->stream->bbx * fi->stream->bby * 1);
+ RGBA** pics = (RGBA**)malloc(fi->stream->bbx * fi->stream->bby * sizeof(void*));
signed char* itx=movex;
signed char* ity=movey;
+ RGBA**pic=pics;
int x,y;
if(!array || !PySequence_Check(array))
return PY_ERROR("Not an array");
for(x=0;x<fi->stream->bbx;x++) {
PyObject*pixel = PySequence_GetItem(line, x);
+ PyObject*xy = 0;
+ PyObject*image = 0;
+
if(!pixel) {
- *itx = 0;
- *ity = 0;
+ xy = image = 0;
} else {
- if(!PyComplex_Check(pixel)) {
- return PY_ERROR("Not an array of arrays of complex numbers");
+ if(PyComplex_Check(pixel)) {
+ xy = pixel; image = 0;
+ } else if(PyString_Check(pixel)) {
+ xy = 0; image = pixel;
+ } else if(PyTuple_Check(pixel)) {
+ int size = PyTuple_GET_SIZE(pixel);
+ if(size!=2) return PY_ERROR("Tuples have to have size 2 (xy,img)");
+ xy = PyTuple_GetItem(pixel, 0);
+ if(!xy) return 0;
+ if(!PyComplex_Check(xy)) return PY_ERROR("Tuples must be (COMPLEX,string)");
+ image = PyTuple_GetItem(pixel, 1);
+ if(!image) return 0;
+ if(!PyString_Check(image)) return PY_ERROR("Tuples must be (complex,STRING)");
}
+ }
+
+ *itx = *ity = 0;
+ *pic= 0;
+
+ if(xy) {
*itx = (signed char)PyComplex_RealAsDouble(pixel);
*ity = (signed char)PyComplex_ImagAsDouble(pixel);
}
+ if(image) {
+ char*string;
+ int size;
+ PyString_AsStringAndSize(image,&string,&size);
+ if(size<256*3) {
+ return PY_ERROR("image strings must be >= 256*3");
+ }
+ *pic = malloc(sizeof(RGBA)*16*16);
+ int t;
+ for(t=0;t<16*16;t++) {
+ (*pic)[t].r = string[t*3];
+ (*pic)[t].g = string[t*3+1];
+ (*pic)[t].b = string[t*3+2];
+ (*pic)[t].a = 255;
+ }
+ }
itx++;
ity++;
+ pic++;
}
}
TAG* t = swf_InsertTag(0, ST_VIDEOFRAME);
swf_SetU16(t,0); /* id */
- swf_SetVideoStreamMover(t, fi->stream, movex, movey, quant);
+ swf_SetVideoStreamMover(t, fi->stream, movex, movey,(void**)pics, quant);
itag->tag = t;
tagmap_addMapping(itag->tagmap, 0, self);
+ for(x=0;x<fi->stream->bbx*fi->stream->bby;x++) {
+ if(pics[x]) {
+ free(pics[x]);pics[x] = 0;
+ }
+ }
+
free(movex);
free(movey);
+ free(pics);
return tag;
}
{{"xblocks", videostream_getbwidth, METH_VARARGS, "get's the number of horizontal blocks"},
{"yblocks", videostream_getbheight, METH_VARARGS, "get's the number of vertical blocks"},
{"addFrame", (PyCFunction)videostream_addFrame, METH_KEYWORDS, "add a Video Frame"},
+ {"addBlackFrame", (PyCFunction)videostream_addBlackFrame, METH_KEYWORDS, "add a black Video Frame"},
{"addDistortionFrame", (PyCFunction)videostream_addDistortionFrame, METH_KEYWORDS, "add a MVD frame"},
{NULL, NULL, 0, NULL}
};
{"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."},
+ {"Shape", (PyCFunction)f_DefineShape, METH_KEYWORDS, "Create an SWF Shape Tag."},
{"ShowFrame", (PyCFunction)f_ShowFrame, METH_KEYWORDS, "Create an SWF Show Frame Tag."},
{"Sprite", (PyCFunction)f_Sprite, METH_KEYWORDS, "Create an SWF Sprite Tag."},
{NULL, NULL, 0, NULL}
register_tag(ST_DEFINEBITSJPEG3,&image_tag);
register_tag(ST_DEFINEBITSLOSSLESS,&image_tag);
register_tag(ST_DEFINEBITSLOSSLESS2,&image_tag);
+ register_tag(ST_DEFINESHAPE,&shape_tag);
+ register_tag(ST_DEFINESHAPE2,&shape_tag);
+ register_tag(ST_DEFINESHAPE3,&shape_tag);
register_tag(ST_SHOWFRAME,&showframe_tag);
register_tag(ST_DEFINEVIDEOSTREAM,&videostream_tag);
register_tag(ST_VIDEOFRAME,&videoframe_tag);