2 #include "primitives.h"
7 //----------------------------------------------------------------------------
9 typedef struct _font_internal
13 staticforward tag_internals_t font_tag;
15 static int font_parse(tag_internals_t*self)
17 font_internal_t*font = (font_internal_t*)self->data;
19 PyErr_SetString(PyExc_Exception, setError("Font parsing not implemented yet"));
22 static void font_dealloc(tag_internals_t*self)
24 font_internal_t*font = (font_internal_t*)self->data;
26 swf_FontFree(font->font);
30 static int font_fillTAG(tag_internals_t*self)
32 font_internal_t*fi = (font_internal_t*)self->data;
35 self->tag = swf_InsertTag(0, ST_DEFINEFONT2);
36 swf_FontSetDefine2(self->tag, fi->font);
39 static PyObject* f_DefineFont(PyObject* self, PyObject* args, PyObject* kwargs)
41 static char *kwlist[] = {"filename", NULL};
46 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &filename))
49 font = swf_LoadFont(filename);
51 PyErr_SetString(PyExc_Exception, setError("Could not load %s", filename));
55 tag = tag_new(&font_tag);
56 tag_internals_t*itag = tag_getinternals(tag);
57 font_internal_t*fi = (font_internal_t*)itag->data;
60 return (PyObject*)tag;
62 static SWFFONT* font_getSWFFONT(PyObject*self)
64 PY_ASSERT_TYPE(self, &TagClass);
65 tag_internals_t*itag = tag_getinternals(self);
66 font_internal_t*fi = (font_internal_t*)itag->data;
69 static tag_internals_t font_tag =
72 fillTAG: font_fillTAG,
73 dealloc: font_dealloc,
75 datasize: sizeof(font_internal_t),
77 //----------------------------------------------------------------------------
79 typedef struct _placeobject_internal
82 } placeobject_internal_t;
83 staticforward tag_internals_t placeobject_tag;
85 static void po_dealloc(tag_internals_t*self)
87 placeobject_internal_t*pi = (placeobject_internal_t*)self->data;
89 swf_PlaceObjectFree(pi->po);
93 static int po_parse(tag_internals_t*self)
95 placeobject_internal_t*pi = (placeobject_internal_t*)self->data;
97 PyErr_SetString(PyExc_Exception, setError("Font parsing not implemented yet"));
100 static int po_fillTAG(tag_internals_t*self)
102 placeobject_internal_t*pi = (placeobject_internal_t*)self->data;
103 self->tag = swf_InsertTag(0, ST_PLACEOBJECT2);
104 swf_SetPlaceObject(self->tag, pi->po);
107 static PyObject* f_PlaceObject(PyObject* self, PyObject* args, PyObject* kwargs)
109 static char *kwlist[] = {"character", "depth", "matrix", "colortransform", "ratio", "name", "clipdepth", "action", NULL};
111 PyObject*character = 0;
120 po = malloc(sizeof(SWFPLACEOBJECT));
121 memset(po, 0, sizeof(SWFPLACEOBJECT));
123 swf_GetPlaceObject(0, po);
125 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oi|O!O!isiO!", kwlist,
128 &MatrixClass, &matrix,
129 &CXFormClass, &cxform,
133 &ActionClass, &action
138 po->clipdepth = clipdepth;
141 if(clipdepth) po->clipdepth = clipdepth;
142 if(matrix) po->matrix = matrix_getMatrix(matrix);
143 if(cxform) po->cxform = colortransform_getCXForm(cxform);
144 if(action) po->actions = action_getAction(action);
147 tag = tag_new(&placeobject_tag);
148 tag_internals_t*itag = tag_getinternals(tag);
149 placeobject_internal_t*pi = (placeobject_internal_t*)itag->data;
151 pi->po->id = tagmap_add(itag->tagmap,(PyObject*)character);
153 mylog("+%08x(%d) PlaceObject %08x(%d)\n", (int)tag, tag->ob_refcnt, character, character->ob_refcnt);
155 return (PyObject*)tag;
157 static tag_internals_t placeobject_tag =
163 datasize: sizeof(placeobject_internal_t),
165 //----------------------------------------------------------------------------
166 staticforward tag_internals_t bgcolor_tag;
167 static PyObject* tag_setbackgroundcolor_getrgb(PyObject * self, PyObject*other)
169 tag_internals_t*itag = tag_getinternals(self);
171 r = itag->tag->data[0];
172 g = itag->tag->data[1];
173 b = itag->tag->data[2];
174 return Py_BuildValue("(iii)", r,g,b);
176 static PyMethodDef setbgcolor_methods[] =
177 {{"getRGB", tag_setbackgroundcolor_getrgb, METH_VARARGS, "get's the color set by this tag"},
178 {NULL, NULL, 0, NULL}
180 static PyObject* f_SetBackgroundColor(PyObject* self, PyObject* args, PyObject* kwargs)
182 static char *kwlist[] = {"color", NULL};
187 tag = tag_new(&bgcolor_tag);
188 tag_internals_t*itag = tag_getinternals(tag);
190 /* 1st try- copy constructor */
191 if(!PyArg_ParseTupleAndKeywords(args, kwargs, "O!", kwlist, &ColorClass, &color)) {
193 /* 2nd try- color's contructor */
194 color = f_Color(NULL, args, kwargs);
199 itag->tag = swf_InsertTag(0, ST_SETBACKGROUNDCOLOR);
200 RGBA rgba = color_getRGBA(color);
201 swf_SetU8(itag->tag, rgba.r);
202 swf_SetU8(itag->tag, rgba.g);
203 swf_SetU8(itag->tag, rgba.b);
204 mylog(" %08x(%d) SetBackgroundColor(%02x,%02x,%02x) (colorobj=%08x(%d))\n", (int)tag, tag->ob_refcnt, rgba.r, rgba.g, rgba.b, color, color->ob_refcnt);
206 return (PyObject*)tag;
208 static tag_internals_t bgcolor_tag =
213 tagfunctions: setbgcolor_methods,
216 //----------------------------------------------------------------------------
217 staticforward tag_internals_t protect_tag;
218 static PyObject* f_Protect(PyObject* self, PyObject* args, PyObject* kwargs)
220 static char *kwlist[] = {"password", NULL};
223 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &password))
226 PyObject*tag = tag_new(&protect_tag);
227 tag_internals_t*itag = tag_getinternals(tag);
228 itag->tag = swf_InsertTag(0, ST_PROTECT);
230 swf_SetPassword(itag->tag, password);
232 mylog("+%08x(%d) f_Protect", (int)tag, tag->ob_refcnt);
233 return (PyObject*)tag;
235 static tag_internals_t protect_tag =
243 //----------------------------------------------------------------------------
244 staticforward tag_internals_t end_tag;
245 static tag_internals_t end_tag =
253 //----------------------------------------------------------------------------
254 staticforward tag_internals_t text_tag;
256 typedef struct _text_internal
263 staticforward tag_internals_t placeobject_tag;
265 static int text_fillTAG(tag_internals_t*self)
267 text_internal_t*ti = (text_internal_t*)self->data;
268 self->tag= swf_InsertTag(0, ST_DEFINETEXT2);
269 swf_SetU16(self->tag, /*ID*/0);
270 SRECT r = swf_SetDefineText(self->tag, ti->swffont, &ti->rgba, ti->text, ti->size);
273 static PyObject* f_DefineText(PyObject* self, PyObject* args, PyObject* kwargs)
275 static char *kwlist[] = {"font", "text", "size", "color", NULL};
282 RGBA rgba = {255,0,0,0};
286 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!u#i|O!", kwlist, &TagClass, &font, &text, &textlen, &size, &ColorClass, &color))
289 unicode16 = PyUnicode_DecodeUTF16(text, textlen*2, NULL, NULL);
290 unicode8 = PyUnicode_AsUTF8String(unicode16);
291 text = PyString_AS_STRING(unicode8);
294 rgba = color_getRGBA(color);
296 mylog("DefineText: text = %s", text);
298 tag = tag_new(&text_tag);
299 tag_internals_t* itag = tag_getinternals(tag);
300 text_internal_t*ti = (text_internal_t*)itag->data;
302 ti->swffont = font_getSWFFONT(font);
303 int font_id = tagmap_add(itag->tagmap, font); // add dependency on font
304 ti->swffont->id = font_id; // for swf_SetDefineTexts
305 ti->text = strdup(text);
309 return (PyObject*)tag;
311 static tag_internals_t text_tag =
314 fillTAG: text_fillTAG,
317 datasize: sizeof(text_internal_t),
319 //----------------------------------------------------------------------------
321 typedef struct _videostream_internal
324 } videostream_internal_t;
325 staticforward tag_internals_t videostream_tag;
327 static int videostream_parse(tag_internals_t*self)
329 videostream_internal_t*videostream = (videostream_internal_t*)self->data;
331 PyErr_SetString(PyExc_Exception, setError("videostream parsing not implemented yet"));
334 static void videostream_dealloc(tag_internals_t*self)
336 videostream_internal_t*videostream = (videostream_internal_t*)self->data;
337 if(videostream->stream) {
338 swf_VideoStreamClear(videostream->stream);
339 free(videostream->stream);
340 videostream->stream = 0;
343 static int videostream_fillTAG(tag_internals_t*self)
345 videostream_internal_t*fi = (videostream_internal_t*)self->data;
349 PyErr_SetString(PyExc_Exception, setError("videostream filling not implemented yet"));return 0;
352 static PyObject* f_DefineVideoStream(PyObject* self, PyObject* args, PyObject* kwargs)
354 PyObject*tag = tag_new(&videostream_tag);
356 int width=0,height=0,quant=7,frames=65535;
357 static char *kwlist[] = {"width", "height", "quant", "frames", NULL};
358 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|ii", kwlist, &TagClass, &width, &height, &quant, &frames))
361 tag_internals_t*itag = tag_getinternals(tag);
362 videostream_internal_t*fi = (videostream_internal_t*)itag->data;
363 fi->stream = malloc(sizeof(VIDEOSTREAM));
364 memset(fi->stream, 0, sizeof(VIDEOSTREAM));
366 TAG*t = swf_InsertTag(0, ST_DEFINEVIDEOSTREAM);
367 swf_SetVideoStreamDefine(t, fi->stream, frames, width, height);
368 return (PyObject*)tag;
370 static VIDEOSTREAM* videostream_getVIDEOSTREAM(PyObject*self)
372 PY_ASSERT_TYPE(self, &TagClass);
373 tag_internals_t*itag = tag_getinternals(self);
374 videostream_internal_t*fi = (videostream_internal_t*)itag->data;
377 static PyObject* videostream_getbwidth(PyObject*self, PyObject*args)
379 tag_internals_t*itag = tag_getinternals(self);
380 videostream_internal_t*fi = (videostream_internal_t*)itag->data;
381 int width = fi->stream->bbx;
382 return Py_BuildValue("i", width);
384 static PyObject* videostream_getbheight(PyObject*self, PyObject*args)
386 tag_internals_t*itag = tag_getinternals(self);
387 videostream_internal_t*fi = (videostream_internal_t*)itag->data;
388 int height = fi->stream->bby;
389 return Py_BuildValue("i", height);
391 static PyObject* videostream_addIFrame(PyObject*self, PyObject*args)
393 tag_internals_t*itag = tag_getinternals(self);
394 videostream_internal_t*fi = (videostream_internal_t*)itag->data;
396 return Py_BuildValue("s", 0);
398 static PyObject* videostream_addPFrame(PyObject*self, PyObject*args)
400 tag_internals_t*itag = tag_getinternals(self);
401 videostream_internal_t*fi = (videostream_internal_t*)itag->data;
403 return Py_BuildValue("s", 0);
405 static PyObject* videostream_addDistortionFrame(PyObject*self, PyObject*args)
407 tag_internals_t*itag = tag_getinternals(self);
408 videostream_internal_t*fi = (videostream_internal_t*)itag->data;
410 return Py_BuildValue("s", 0);
412 static PyMethodDef videostream_methods[] =
413 {{"xblocks", videostream_getbwidth, METH_VARARGS, "get's the number of horizontal blocks"},
414 {"yblocks", videostream_getbheight, METH_VARARGS, "get's the number of vertical blocks"},
415 {"addIFrame", videostream_addIFrame, METH_VARARGS, "add a I Video Frame"},
416 {"addPFrame", videostream_addPFrame, METH_VARARGS, "add a P Video Frame"},
417 {"addDistortionFrame", videostream_addDistortionFrame, METH_VARARGS, "add a MVD frame"},
418 {NULL, NULL, 0, NULL}
421 static tag_internals_t videostream_tag =
423 parse: videostream_parse,
424 fillTAG: videostream_fillTAG,
425 dealloc: videostream_dealloc,
426 tagfunctions: videostream_methods,
427 datasize: sizeof(videostream_internal_t),
430 //============================================================================
432 static PyMethodDef TagMethods[] =
435 {"BackgroundColor", (PyCFunction)f_SetBackgroundColor, METH_KEYWORDS, "Create a SetBackGroundColor Tag."},
436 {"Protect", (PyCFunction)f_Protect, METH_KEYWORDS, "Create a Protect Tag."},
437 {"Font", (PyCFunction)f_DefineFont, METH_KEYWORDS, "Create a DefineFont Tag."},
438 {"Text", (PyCFunction)f_DefineText, METH_KEYWORDS, "Create a DefineText Tag."},
439 {"PlaceObject", (PyCFunction)f_PlaceObject, METH_KEYWORDS, "Create a PlaceObject Tag."},
440 {"VideoStream", (PyCFunction)f_DefineVideoStream, METH_KEYWORDS, "Create a Videostream."},
441 {NULL, NULL, 0, NULL}
443 PyMethodDef* tags_getMethods()
445 TagClass.ob_type = &PyType_Type;
447 register_tag(ST_PLACEOBJECT,&placeobject_tag);
448 register_tag(ST_PLACEOBJECT2,&placeobject_tag);
449 register_tag(ST_SETBACKGROUNDCOLOR,&bgcolor_tag);
450 register_tag(ST_DEFINEFONT,&font_tag);
451 register_tag(ST_PROTECT,&protect_tag);
452 register_tag(ST_DEFINETEXT,&text_tag);
453 register_tag(ST_END,&end_tag);