#include "pyutils.h"
#include "primitives.h"
#include "action.h"
+#include "taglist.h"
#include "tag.h"
#include "tags.h"
#include "image.h"
parse: font_parse,
fillTAG: font_fillTAG,
dealloc: font_dealloc,
+ getattr: 0,
+ setattr: 0,
tagfunctions: 0,
datasize: sizeof(font_internal_t),
};
))
return NULL;
po->depth = depth;
- po->id = /*ID*/ 0;
po->clipdepth = clipdepth;
po->ratio = ratio;
po->name = name;
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);
parse: po_parse,
fillTAG: po_fillTAG,
dealloc: po_dealloc,
+ getattr: 0,
+ setattr: 0,
tagfunctions: 0,
datasize: sizeof(placeobject_internal_t),
};
parse: 0,
fillTAG: 0,
dealloc: 0,
+ getattr: 0,
+ setattr: 0,
tagfunctions: setbgcolor_methods,
datasize: 0,
};
parse: 0,
fillTAG: 0,
dealloc: 0,
+ getattr: 0,
+ setattr: 0,
tagfunctions: 0,
datasize: 0,
};
parse: 0,
fillTAG: 0,
dealloc: 0,
+ getattr: 0,
+ setattr: 0,
+ tagfunctions: 0,
+ datasize: 0,
+};
+//----------------------------------------------------------------------------
+staticforward tag_internals_t removeobject_tag;
+static PyObject* f_RemoveObject(PyObject* self, PyObject* args, PyObject* kwargs)
+{
+ static char *kwlist[] = {"depth", NULL};
+ int depth;
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &depth))
+ return NULL;
+
+ PyObject*tag = tag_new(&removeobject_tag);
+ tag_internals_t*itag = tag_getinternals(tag);
+ itag->tag = swf_InsertTag(0, ST_REMOVEOBJECT);
+ swf_SetU16(itag->tag, depth);
+ mylog("+%08x(%d) f_RemoveObject", (int)tag, tag->ob_refcnt);
+ return (PyObject*)tag;
+}
+static tag_internals_t removeobject_tag =
+{
+ parse: 0,
+ fillTAG: 0,
+ dealloc: 0,
+ getattr: 0,
+ setattr: 0,
tagfunctions: 0,
datasize: 0,
};
//----------------------------------------------------------------------------
+staticforward tag_internals_t sprite_tag;
+typedef struct _sprite_internal
+{
+ PyObject* taglist;
+} sprite_internal_t;
+
+static int sprite_fillTAG(tag_internals_t*self)
+{
+ mylog("+%08x(?) sprite_fillTAG", (int)self);
+
+ sprite_internal_t*si = (sprite_internal_t*)self->data;
+
+ TAG*sprite = swf_InsertTag(0, ST_DEFINESPRITE);
+ swf_SetU16(sprite, 0); //id
+ swf_SetU16(sprite, 0); //frames
+
+ TAG*tag = taglist_getTAGs2(si->taglist, self->tagmap, 0);
+ if(!tag) {
+ /* pass through exception */
+ return 0;
+ }
+ TAG*tag2 = tag;
+ while(tag2->next) tag2 = tag2->next;
+ swf_InsertTag(tag2, ST_END);
+
+ sprite->next = tag;
+ tag->prev = sprite;
+
+ swf_FoldSprite(sprite);
+ self->tag = sprite;
+ return 1;
+}
+
+static PyObject* f_Sprite(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(&sprite_tag);
+ tag_internals_t*itag = tag_getinternals(tag);
+ sprite_internal_t*si = (sprite_internal_t*)itag->data;
+ si->taglist = taglist_new();
+ mylog("+%08x(%d) f_DefineSprite", (int)tag, tag->ob_refcnt);
+ return (PyObject*)tag;
+}
+static PyObject* sprite_getattr(tag_internals_t*self,char*a)
+{
+ sprite_internal_t*si = (sprite_internal_t*)self->data;
+ if(!strcmp(a, "tags")) {
+ Py_INCREF(si->taglist);
+ return si->taglist;
+ }
+ return 0;
+}
+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);
+ self->tag = 0;
+ }
+ if(!strcmp(a, "tags")) {
+ PY_ASSERT_TYPE(obj,&TagListClass);
+ Py_DECREF(si->taglist);
+ si->taglist = obj;
+ Py_INCREF(si->taglist);
+ return 0;
+ }
+ return 1;
+}
+static tag_internals_t sprite_tag =
+{
+ parse: 0,
+ fillTAG: sprite_fillTAG,
+ dealloc: 0,
+ getattr: sprite_getattr,
+ setattr: sprite_setattr,
+ tagfunctions: 0,
+ datasize: sizeof(sprite_internal_t),
+};
+//----------------------------------------------------------------------------
staticforward tag_internals_t end_tag;
static tag_internals_t end_tag =
{
parse: 0,
fillTAG: 0,
dealloc: 0,
+ getattr: 0,
+ setattr: 0,
tagfunctions: 0,
datasize: 0,
};
SWFFONT* swffont;
RGBA rgba;
int size;
+ SRECT bbox;
} text_internal_t;
staticforward tag_internals_t placeobject_tag;
text_internal_t*ti = (text_internal_t*)self->data;
self->tag= swf_InsertTag(0, ST_DEFINETEXT2);
swf_SetU16(self->tag, /*ID*/0);
- SRECT r = swf_SetDefineText(self->tag, ti->swffont, &ti->rgba, ti->text, ti->size);
+ 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)
+{
+ text_internal_t*si = (text_internal_t*)self->data;
+ if(!strcmp(a, "bbox")) {
+ return f_BBox2(si->bbox);
+ }
+ return 0;
+}
static PyObject* f_DefineText(PyObject* self, PyObject* args, PyObject* kwargs)
{
static char *kwlist[] = {"font", "text", "size", "color", NULL};
PyObject*tag = 0;
+ PyObject*otext;
char*text = 0;
- int textlen = 0;
- PyObject*unicode16;
- PyObject*unicode8;
int size = 0;
RGBA rgba = {255,0,0,0};
PyObject*color = 0;
PyObject*font = 0;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!u#i|O!", kwlist, &TagClass, &font, &text, &textlen, &size, &ColorClass, &color))
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!Oi|O!", kwlist, &TagClass, &font, &otext, &size, &ColorClass, &color))
return NULL;
-
- unicode16 = PyUnicode_DecodeUTF16(text, textlen*2, NULL, NULL);
- unicode8 = PyUnicode_AsUTF8String(unicode16);
- text = PyString_AS_STRING(unicode8);
+ if(PyUnicode_Check(otext)) {
+ text = PyString_AS_STRING(PyUnicode_AsUTF8String(otext));
+ } else if(PyString_Check(otext)) {
+ text = PyString_AS_STRING(otext);
+ }
if(color)
rgba = color_getRGBA(color);
parse: 0,
fillTAG: text_fillTAG,
dealloc: 0,
+ getattr: text_getattr,
+ setattr: 0,
tagfunctions: 0,
datasize: sizeof(text_internal_t),
};
parse: 0,
fillTAG: image_fillTAG,
dealloc: image_dealloc,
+ getattr: 0,
+ setattr: 0,
tagfunctions: 0,
datasize: sizeof(image_internal_t),
};
parse: 0,
fillTAG: shape_fillTAG,
dealloc: shape_dealloc,
+ getattr: 0,
+ setattr: 0,
tagfunctions: 0,
datasize: sizeof(shape_internal_t),
};
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 {
free(pic);
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;
+ 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;y<fi->stream->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;x<fi->stream->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);
- /* DUMMY */
- TAG* t = swf_InsertTag(0, ST_REFLEX);
+
+ 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;
}
parse: videostream_parse,
fillTAG: videostream_fillTAG,
dealloc: videostream_dealloc,
+ getattr: 0,
+ setattr: 0,
tagfunctions: videostream_methods,
datasize: sizeof(videostream_internal_t),
};
parse: 0,
fillTAG: 0,
dealloc: 0,
+ getattr: 0,
+ setattr: 0,
tagfunctions: 0,
datasize: 0
};
{"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."},
+ {"RemoveObject", (PyCFunction)f_RemoveObject, METH_KEYWORDS, "Create a RemoveObject 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."},
+ {"Sprite", (PyCFunction)f_Sprite, METH_KEYWORDS, "Create an SWF Sprite Tag."},
{NULL, NULL, 0, NULL}
};
PyMethodDef* tags_getMethods()
register_tag(ST_PLACEOBJECT,&placeobject_tag);
register_tag(ST_PLACEOBJECT2,&placeobject_tag);
+ register_tag(ST_REMOVEOBJECT,&removeobject_tag);
+ register_tag(ST_REMOVEOBJECT2,&removeobject_tag);
register_tag(ST_SETBACKGROUNDCOLOR,&bgcolor_tag);
register_tag(ST_DEFINEFONT,&font_tag);
register_tag(ST_PROTECT,&protect_tag);
register_tag(ST_DEFINEBITSJPEG3,&image_tag);
register_tag(ST_DEFINEBITSLOSSLESS,&image_tag);
register_tag(ST_DEFINEBITSLOSSLESS2,&image_tag);
+ register_tag(ST_SHOWFRAME,&showframe_tag);
+ register_tag(ST_DEFINEVIDEOSTREAM,&videostream_tag);
+ register_tag(ST_VIDEOFRAME,&videoframe_tag);
+ register_tag(ST_DEFINESPRITE,&sprite_tag);
register_tag(ST_END,&end_tag);
return TagMethods;
}
-