2 #include "primitives.h"
9 //----------------------------------------------------------------------------
11 typedef struct _font_internal
15 staticforward tag_internals_t font_tag;
17 static int font_parse(tag_internals_t*self)
19 font_internal_t*font = (font_internal_t*)self->data;
21 PyErr_SetString(PyExc_Exception, setError("Font parsing not implemented yet"));
24 static void font_dealloc(tag_internals_t*self)
26 font_internal_t*font = (font_internal_t*)self->data;
28 swf_FontFree(font->font);
32 static int font_fillTAG(tag_internals_t*self)
34 font_internal_t*fi = (font_internal_t*)self->data;
37 self->tag = swf_InsertTag(0, ST_DEFINEFONT2);
38 swf_FontSetDefine2(self->tag, fi->font);
41 static PyObject* f_DefineFont(PyObject* self, PyObject* args, PyObject* kwargs)
43 static char *kwlist[] = {"filename", NULL};
48 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &filename))
51 font = swf_LoadFont(filename);
53 PyErr_SetString(PyExc_Exception, setError("Could not load %s", filename));
57 tag = tag_new(&font_tag);
58 tag_internals_t*itag = tag_getinternals(tag);
59 font_internal_t*fi = (font_internal_t*)itag->data;
62 return (PyObject*)tag;
64 static SWFFONT* font_getSWFFONT(PyObject*self)
66 PY_ASSERT_TYPE(self, &TagClass);
67 tag_internals_t*itag = tag_getinternals(self);
68 font_internal_t*fi = (font_internal_t*)itag->data;
71 static tag_internals_t font_tag =
74 fillTAG: font_fillTAG,
75 dealloc: font_dealloc,
79 datasize: sizeof(font_internal_t),
81 //----------------------------------------------------------------------------
83 typedef struct _placeobject_internal
86 } placeobject_internal_t;
87 staticforward tag_internals_t placeobject_tag;
89 static void po_dealloc(tag_internals_t*self)
91 placeobject_internal_t*pi = (placeobject_internal_t*)self->data;
93 swf_PlaceObjectFree(pi->po);
97 static int po_parse(tag_internals_t*self)
99 placeobject_internal_t*pi = (placeobject_internal_t*)self->data;
101 PyErr_SetString(PyExc_Exception, setError("Font parsing not implemented yet"));
104 static int po_fillTAG(tag_internals_t*self)
106 placeobject_internal_t*pi = (placeobject_internal_t*)self->data;
107 self->tag = swf_InsertTag(0, ST_PLACEOBJECT2);
108 swf_SetPlaceObject(self->tag, pi->po);
111 static PyObject* po_create(PyObject* self, PyObject* args, PyObject* kwargs,char move)
113 static char *kwlist[] = {"character", "depth", "matrix", "colortransform", "ratio", "name", "clipdepth", "action", NULL};
115 PyObject*character = 0;
124 po = malloc(sizeof(SWFPLACEOBJECT));
125 memset(po, 0, sizeof(SWFPLACEOBJECT));
127 swf_GetPlaceObject(0, po);
130 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oi|O!O!isiO!", kwlist,
133 &MatrixClass, &matrix,
134 &CXFormClass, &cxform,
138 &ActionClass, &action
143 po->clipdepth = clipdepth;
147 if(clipdepth) po->clipdepth = clipdepth;
148 if(matrix) po->matrix = matrix_getMatrix(matrix);
149 if(cxform) po->cxform = colortransform_getCXForm(cxform);
150 if(action) po->actions = action_getAction(action);
153 tag = tag_new(&placeobject_tag);
154 tag_internals_t*itag = tag_getinternals(tag);
155 placeobject_internal_t*pi = (placeobject_internal_t*)itag->data;
158 pi->po->id = tagmap_add(itag->tagmap,(PyObject*)character);
163 mylog("+%08x(%d) PlaceObject %08x(%d)\n", (int)tag, tag->ob_refcnt, character, character->ob_refcnt);
165 return (PyObject*)tag;
167 static PyObject* f_PlaceObject(PyObject* self, PyObject* args, PyObject* kwargs)
169 return po_create(self, args, kwargs, 0);
171 static PyObject* f_MoveObject(PyObject* self, PyObject* args, PyObject* kwargs)
173 return po_create(self, args, kwargs, 1);
175 static tag_internals_t placeobject_tag =
183 datasize: sizeof(placeobject_internal_t),
185 //----------------------------------------------------------------------------
186 staticforward tag_internals_t bgcolor_tag;
187 static PyObject* tag_setbackgroundcolor_getrgb(PyObject * self, PyObject*other)
189 tag_internals_t*itag = tag_getinternals(self);
191 r = itag->tag->data[0];
192 g = itag->tag->data[1];
193 b = itag->tag->data[2];
194 return Py_BuildValue("(iii)", r,g,b);
196 static PyMethodDef setbgcolor_methods[] =
197 {{"getRGB", tag_setbackgroundcolor_getrgb, METH_VARARGS, "get's the color set by this tag"},
198 {NULL, NULL, 0, NULL}
200 static PyObject* f_SetBackgroundColor(PyObject* self, PyObject* args, PyObject* kwargs)
202 static char *kwlist[] = {"color", NULL};
207 tag = tag_new(&bgcolor_tag);
208 tag_internals_t*itag = tag_getinternals(tag);
210 /* 1st try- copy constructor */
211 if(!PyArg_ParseTupleAndKeywords(args, kwargs, "O!", kwlist, &ColorClass, &color)) {
213 /* 2nd try- color's contructor */
214 color = f_Color(NULL, args, kwargs);
219 itag->tag = swf_InsertTag(0, ST_SETBACKGROUNDCOLOR);
220 RGBA rgba = color_getRGBA(color);
221 swf_SetU8(itag->tag, rgba.r);
222 swf_SetU8(itag->tag, rgba.g);
223 swf_SetU8(itag->tag, rgba.b);
224 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);
226 return (PyObject*)tag;
228 static tag_internals_t bgcolor_tag =
235 tagfunctions: setbgcolor_methods,
238 //----------------------------------------------------------------------------
239 staticforward tag_internals_t protect_tag;
240 static PyObject* f_Protect(PyObject* self, PyObject* args, PyObject* kwargs)
242 static char *kwlist[] = {"password", NULL};
245 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &password))
248 PyObject*tag = tag_new(&protect_tag);
249 tag_internals_t*itag = tag_getinternals(tag);
250 itag->tag = swf_InsertTag(0, ST_PROTECT);
252 swf_SetPassword(itag->tag, password);
254 mylog("+%08x(%d) f_Protect", (int)tag, tag->ob_refcnt);
255 return (PyObject*)tag;
257 static tag_internals_t protect_tag =
267 //----------------------------------------------------------------------------
268 staticforward tag_internals_t showframe_tag;
269 static PyObject* f_ShowFrame(PyObject* self, PyObject* args, PyObject* kwargs)
271 static char *kwlist[] = {"name", NULL};
273 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &name))
276 PyObject*tag = tag_new(&showframe_tag);
277 tag_internals_t*itag = tag_getinternals(tag);
278 itag->tag = swf_InsertTag(0, ST_SHOWFRAME);
279 mylog("+%08x(%d) f_ShowFrame", (int)tag, tag->ob_refcnt);
280 return (PyObject*)tag;
282 static tag_internals_t showframe_tag =
292 //----------------------------------------------------------------------------
293 staticforward tag_internals_t removeobject_tag;
294 static PyObject* f_RemoveObject(PyObject* self, PyObject* args, PyObject* kwargs)
296 static char *kwlist[] = {"depth", NULL};
298 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &depth))
301 PyObject*tag = tag_new(&removeobject_tag);
302 tag_internals_t*itag = tag_getinternals(tag);
303 itag->tag = swf_InsertTag(0, ST_REMOVEOBJECT);
304 swf_SetU16(itag->tag, depth);
305 mylog("+%08x(%d) f_RemoveObject", (int)tag, tag->ob_refcnt);
306 return (PyObject*)tag;
308 static tag_internals_t removeobject_tag =
318 //----------------------------------------------------------------------------
319 staticforward tag_internals_t sprite_tag;
320 typedef struct _sprite_internal
325 static int sprite_fillTAG(tag_internals_t*self)
327 mylog("+%08x(?) sprite_fillTAG", (int)self);
329 sprite_internal_t*si = (sprite_internal_t*)self->data;
331 TAG*sprite = swf_InsertTag(0, ST_DEFINESPRITE);
332 swf_SetU16(sprite, 0); //id
333 swf_SetU16(sprite, 0); //frames
335 TAG*tag = taglist_getTAGs2(si->taglist, self->tagmap, 0);
337 /* pass through exception */
341 while(tag2->next) tag2 = tag2->next;
342 swf_InsertTag(tag2, ST_END);
347 swf_FoldSprite(sprite);
352 static PyObject* f_Sprite(PyObject* self, PyObject* args, PyObject* kwargs)
354 static char *kwlist[] = {"name", NULL};
356 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &name))
359 PyObject*tag = tag_new(&sprite_tag);
360 tag_internals_t*itag = tag_getinternals(tag);
361 sprite_internal_t*si = (sprite_internal_t*)itag->data;
362 si->taglist = taglist_new();
363 mylog("+%08x(%d) f_DefineSprite", (int)tag, tag->ob_refcnt);
364 return (PyObject*)tag;
366 static PyObject* sprite_getattr(tag_internals_t*self,char*a)
368 sprite_internal_t*si = (sprite_internal_t*)self->data;
369 if(!strcmp(a, "tags")) {
370 Py_INCREF(si->taglist);
375 static int sprite_setattr(tag_internals_t*self,char*a, PyObject*obj)
377 sprite_internal_t*si = (sprite_internal_t*)self->data;
379 swf_DeleteTag(self->tag);
382 if(!strcmp(a, "tags")) {
383 PY_ASSERT_TYPE(obj,&TagListClass);
384 Py_DECREF(si->taglist);
386 Py_INCREF(si->taglist);
391 static tag_internals_t sprite_tag =
394 fillTAG: sprite_fillTAG,
396 getattr: sprite_getattr,
397 setattr: sprite_setattr,
399 datasize: sizeof(sprite_internal_t),
401 //----------------------------------------------------------------------------
402 staticforward tag_internals_t end_tag;
403 static tag_internals_t end_tag =
413 //----------------------------------------------------------------------------
414 staticforward tag_internals_t text_tag;
416 typedef struct _text_internal
424 staticforward tag_internals_t placeobject_tag;
426 static int text_fillTAG(tag_internals_t*self)
428 text_internal_t*ti = (text_internal_t*)self->data;
429 self->tag= swf_InsertTag(0, ST_DEFINETEXT2);
430 swf_SetU16(self->tag, /*ID*/0);
431 ti->bbox = swf_SetDefineText(self->tag, ti->swffont, &ti->rgba, ti->text, ti->size);
434 static PyObject* text_getattr(tag_internals_t*self,char*a)
436 text_internal_t*si = (text_internal_t*)self->data;
437 if(!strcmp(a, "bbox")) {
438 return f_BBox2(si->bbox);
442 static PyObject* f_DefineText(PyObject* self, PyObject* args, PyObject* kwargs)
444 static char *kwlist[] = {"font", "text", "size", "color", NULL};
449 RGBA rgba = {255,0,0,0};
453 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!Oi|O!", kwlist, &TagClass, &font, &otext, &size, &ColorClass, &color))
455 if(PyUnicode_Check(otext)) {
456 text = PyString_AS_STRING(PyUnicode_AsUTF8String(otext));
457 } else if(PyString_Check(otext)) {
458 text = PyString_AS_STRING(otext);
462 rgba = color_getRGBA(color);
464 mylog("DefineText: text = %s", text);
466 tag = tag_new(&text_tag);
467 tag_internals_t* itag = tag_getinternals(tag);
468 text_internal_t*ti = (text_internal_t*)itag->data;
470 ti->swffont = font_getSWFFONT(font);
471 int font_id = tagmap_add(itag->tagmap, font); // add dependency on font
472 ti->swffont->id = font_id; // for swf_SetDefineTexts
473 ti->text = strdup(text);
477 return (PyObject*)tag;
479 static tag_internals_t text_tag =
482 fillTAG: text_fillTAG,
484 getattr: text_getattr,
487 datasize: sizeof(text_internal_t),
489 //----------------------------------------------------------------------------
490 staticforward tag_internals_t image_tag;
492 typedef struct _image_internal
502 staticforward tag_internals_t image_tag;
504 static int image_fillTAG(tag_internals_t*self)
506 image_internal_t*ti = (image_internal_t*)self->data;
507 self->tag= swf_InsertTag(0, ST_DEFINEBITSLOSSLESS2);
508 swf_SetU16(self->tag, /*ID*/0);
509 swf_SetLosslessBits(self->tag, ti->width, ti->height, ti->rgba, BMF_32BIT);
512 static void image_dealloc(tag_internals_t*self)
514 image_internal_t*pi = (image_internal_t*)self->data;
516 free(pi->rgba);pi->rgba = 0;
519 static int imagetag_getWidth(PyObject* self)
521 tag_internals_t*itag = tag_getinternals(self);
522 image_internal_t*pi = (image_internal_t*)itag->data;
525 static int imagetag_getHeight(PyObject* self)
527 tag_internals_t*itag = tag_getinternals(self);
528 image_internal_t*pi = (image_internal_t*)itag->data;
531 static PyObject* f_DefineImage(PyObject* self, PyObject* args, PyObject* kwargs)
533 static char *kwlist[] = {"image", NULL};
535 PyObject*tag = tag_new(&image_tag);
537 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist, &image))
540 tag = tag_new(&image_tag);
541 tag_internals_t* itag = tag_getinternals(tag);
542 image_internal_t*ti = (image_internal_t*)itag->data;
544 ti->rgba = image_toRGBA(image);
545 if(!ti->rgba) // pass through exception
547 ti->width = image_getWidth(image);
548 ti->height = image_getHeight(image);
552 ti->size = ti->width*ti->height;
554 return (PyObject*)tag;
556 static tag_internals_t image_tag =
559 fillTAG: image_fillTAG,
560 dealloc: image_dealloc,
564 datasize: sizeof(image_internal_t),
566 //----------------------------------------------------------------------------
567 staticforward tag_internals_t shape_tag;
569 typedef struct _shape_internal
573 staticforward tag_internals_t shape_tag;
575 static int shape_fillTAG(tag_internals_t*self)
577 shape_internal_t*ti = (shape_internal_t*)self->data;
578 self->tag= swf_InsertTag(0, ST_DEFINESHAPE3);
579 swf_SetU16(self->tag, /*ID*/0);
580 swf_SetShape2(self->tag, ti->shape2);
583 static void shape_dealloc(tag_internals_t*self)
585 shape_internal_t*pi = (shape_internal_t*)self->data;
587 swf_Shape2Free(pi->shape2);
591 static PyObject* f_DefineImageShape(PyObject* self, PyObject* args, PyObject* kwargs)
593 static char *kwlist[] = {"image", NULL};
596 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!", kwlist, &TagClass, &image))
599 PyObject*tag = tag_new(&shape_tag);
600 tag_internals_t* itag = tag_getinternals(tag);
601 shape_internal_t*ti = (shape_internal_t*)itag->data;
602 ti->shape2 = 0; /*HACK*/
604 int width = imagetag_getWidth(image);
605 int height = imagetag_getHeight(image);
606 int id = tagmap_add(itag->tagmap, image);
607 itag->tag= swf_InsertTag(0, ST_DEFINESHAPE3);
608 swf_SetU16(itag->tag, 0);
609 swf_ShapeSetBitmapRect(itag->tag, id, width, height);
610 return (PyObject*)tag;
613 /* TODO: move to lib/ */
614 SHAPE2*swf_StringToShape2(char*s,FILLSTYLE*f, LINESTYLE*l)
617 swf_Shape11DrawerInit(&draw, 0);
618 draw_string(&draw, s);
620 SHAPE*s1 = swf_ShapeDrawerToShape(&draw);
621 SRECT r = swf_ShapeDrawerGetBBox(&draw);
622 RGBA col;col.r=col.g=col.b=128;col.a=255;
624 swf_ShapeAddLineStyle(s1, 1, &col);
626 swf_ShapeAddSolidFillStyle(s1, &col);
628 SHAPE2*shape2 = swf_ShapeToShape2(s1);
630 shape2->bbox = malloc(sizeof(SRECT));
632 if(f && shape2->numfillstyles)
633 shape2->fillstyles[0] = *f;
634 if(l && shape2->numlinestyles)
635 shape2->linestyles[0] = *l;
639 static PyObject* f_DefineShape(PyObject* self, PyObject* args, PyObject* kwargs)
641 static char *kwlist[] = {"s", "fill", "line", NULL};
643 PyObject*fillstyle=0,*linestyle=0;
645 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OO", kwlist, &s,&fillstyle,&linestyle))
648 PyObject*tag = tag_new(&shape_tag);
649 tag_internals_t* itag = tag_getinternals(tag);
650 shape_internal_t*ti = (shape_internal_t*)itag->data;
657 if(PY_CHECK_TYPE(fillstyle, &ColorClass)) {
658 f->type = /*FILL_SOLID*/ 0;
659 f->color = color_getRGBA(fillstyle);
661 return PY_ERROR("Invalid Fillstyle");
667 if(PyTuple_Check(linestyle) && PyTuple_GET_SIZE(linestyle)==2) {
670 if(!PyArg_ParseTuple(linestyle, "fO!", &f, &ColorClass, &color))
673 l->width = (int)(f*20);
674 l->color = color_getRGBA(color);
676 return PY_ERROR("Invalid Linestyle");
679 ti->shape2 = swf_StringToShape2(s,f,l);
683 return (PyObject*)tag;
685 static PyObject* shape_getfillstyles(PyObject*self, PyObject*args)
687 tag_internals_t*itag = tag_getinternals(self);
688 shape_internal_t*fi = (shape_internal_t*)itag->data;
689 int num = fi->shape2->numfillstyles;
690 return Py_BuildValue("i", num);
692 static PyObject* shape_getlinestyles(PyObject*self, PyObject*args)
694 tag_internals_t*itag = tag_getinternals(self);
695 shape_internal_t*fi = (shape_internal_t*)itag->data;
696 int num = fi->shape2->numlinestyles;
697 return Py_BuildValue("i", num);
699 static PyMethodDef shape_methods[] =
700 {{"fillstyles", shape_getfillstyles, METH_VARARGS, "get's the number of fillstyles"},
701 {"linestyles", shape_getlinestyles, METH_VARARGS, "get's the number of linestyles"},
702 {NULL, NULL, 0, NULL}
705 static tag_internals_t shape_tag =
708 fillTAG: shape_fillTAG,
709 dealloc: shape_dealloc,
712 tagfunctions: shape_methods,
713 datasize: sizeof(shape_internal_t),
715 //----------------------------------------------------------------------------
717 typedef struct _videostream_internal
721 } videostream_internal_t;
722 staticforward tag_internals_t videostream_tag;
723 staticforward tag_internals_t videoframe_tag;
725 static int videostream_parse(tag_internals_t*self)
727 videostream_internal_t*videostream = (videostream_internal_t*)self->data;
729 PyErr_SetString(PyExc_Exception, setError("videostream parsing not implemented yet"));
732 static void videostream_dealloc(tag_internals_t*self)
734 videostream_internal_t*videostream = (videostream_internal_t*)self->data;
735 if(videostream->stream) {
736 swf_VideoStreamClear(videostream->stream);
737 free(videostream->stream);
738 videostream->stream = 0;
741 static int videostream_fillTAG(tag_internals_t*self)
743 videostream_internal_t*fi = (videostream_internal_t*)self->data;
746 PyErr_SetString(PyExc_Exception, setError("videostream filling not implemented"));
749 static PyObject* f_DefineVideoStream(PyObject* self, PyObject* args, PyObject* kwargs)
751 PyObject*tag = tag_new(&videostream_tag);
753 int width=0,height=0,frames=65535;
754 static char *kwlist[] = {"width", "height", "frames", NULL};
755 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|i", kwlist, &width, &height, &frames))
758 tag_internals_t*itag = tag_getinternals(tag);
759 videostream_internal_t*fi = (videostream_internal_t*)itag->data;
760 fi->stream = malloc(sizeof(VIDEOSTREAM));
761 memset(fi->stream, 0, sizeof(VIDEOSTREAM));
763 TAG*t = swf_InsertTag(0, ST_DEFINEVIDEOSTREAM);
764 swf_SetU16(t, 0); /* id */
765 swf_SetVideoStreamDefine(t, fi->stream, frames, width, height);
767 fi->lastiframe = -65536;
768 return (PyObject*)tag;
770 static VIDEOSTREAM* videostream_getVIDEOSTREAM(PyObject*self)
772 PY_ASSERT_TYPE(self, &TagClass);
773 tag_internals_t*itag = tag_getinternals(self);
774 videostream_internal_t*fi = (videostream_internal_t*)itag->data;
777 static PyObject* videostream_getbwidth(PyObject*self, PyObject*args)
779 tag_internals_t*itag = tag_getinternals(self);
780 videostream_internal_t*fi = (videostream_internal_t*)itag->data;
781 int width = fi->stream->bbx;
782 return Py_BuildValue("i", width);
784 static PyObject* videostream_getbheight(PyObject*self, PyObject*args)
786 tag_internals_t*itag = tag_getinternals(self);
787 videostream_internal_t*fi = (videostream_internal_t*)itag->data;
788 int height = fi->stream->bby;
789 return Py_BuildValue("i", height);
791 static PyObject* videostream_addBlackFrame(PyObject*self, PyObject*args, PyObject*kwargs)
793 tag_internals_t*_itag = tag_getinternals(self);
794 videostream_internal_t*fi = (videostream_internal_t*)_itag->data;
796 TAG* t = swf_InsertTag(0, ST_VIDEOFRAME);
798 PyObject*tag = tag_new(&videoframe_tag);
799 tag_internals_t*itag = tag_getinternals(tag);
801 swf_SetU16(t,0); /* id */
802 swf_SetVideoStreamBlackFrame(t, fi->stream);
803 fi->lastiframe = fi->stream->frame;
806 tagmap_addMapping(itag->tagmap, 0, self);
809 static PyObject* videostream_addFrame(PyObject*self, PyObject*args, PyObject*kwargs)
811 tag_internals_t*_itag = tag_getinternals(self);
812 videostream_internal_t*fi = (videostream_internal_t*)_itag->data;
815 char*type=0; // none, "i", "p"
817 static char *kwlist[] = {"image", "quant", "type", NULL};
818 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|is", kwlist, &image, &quant, &type))
820 if(fi->stream->owidth != image_getWidth(image)) {
821 PyErr_SetString(PyExc_Exception, setError("bad image width %d!=%d", image_getWidth(image), fi->stream->width));return 0;
823 if(fi->stream->oheight != image_getHeight(image)) {
824 PyErr_SetString(PyExc_Exception, setError("bad image width %d!=%d", image_getHeight(image), fi->stream->height));return 0;
826 PyObject*tag = tag_new(&videoframe_tag);
827 tag_internals_t*itag = tag_getinternals(tag);
829 RGBA*pic = image_toRGBA(image);
833 /*{ int f,j=0,i=0,rr,gg,bb;
836 char*filename="test.ppm";
837 printf("Creating %s %dx%d\n",filename, 512,512);
838 o=fopen(filename, "wb");
839 fprintf(o,"P6\n%d %d\n255\n",512, 512);
845 fprintf(o,"%c%c%c",rr,gg,bb);
852 TAG* t = swf_InsertTag(0, ST_VIDEOFRAME);
853 if((type && (type[0]=='I' || type[0]=='i')) || (type==0 && fi->lastiframe+64 < fi->stream->frame)) {
854 swf_SetU16(t,0); /* id */
855 swf_SetVideoStreamIFrame(t, fi->stream, pic, quant);
856 fi->lastiframe = fi->stream->frame;
859 swf_SetVideoStreamPFrame(t, fi->stream, pic, quant);
862 tagmap_addMapping(itag->tagmap, 0, self);
866 static PyObject* videostream_addDistortionFrame(PyObject*self, PyObject*args, PyObject*kwargs)
868 tag_internals_t*_itag = tag_getinternals(self);
869 videostream_internal_t*fi = (videostream_internal_t*)_itag->data;
871 static char *kwlist[] = {"image", "quant", NULL};
874 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i", kwlist, &array, &quant))
877 signed char* movex = malloc(fi->stream->bbx * fi->stream->bby * 1);
878 signed char* movey = malloc(fi->stream->bbx * fi->stream->bby * 1);
879 RGBA** pics = (RGBA**)malloc(fi->stream->bbx * fi->stream->bby * sizeof(void*));
880 signed char* itx=movex;
881 signed char* ity=movey;
884 if(!array || !PySequence_Check(array))
885 return PY_ERROR("Not an array");
886 if(PySequence_Length(array) < fi->stream->bby)
887 return PY_ERROR("Array (y) has to have at least %d elements, but has only %d ", fi->stream->bby, PySequence_Length(array));
888 for(y=0;y<fi->stream->bby;y++) {
889 PyObject*line = PySequence_GetItem(array, y);
890 if(!line || !PySequence_Check(line))
891 return PY_ERROR("Not an array of arrays");
892 if(PySequence_Length(line) < fi->stream->bbx)
893 return PY_ERROR("Inner arrays (x) have to be at least %d long- %dth is only %d", fi->stream->bbx, y, PySequence_Length(line));
895 for(x=0;x<fi->stream->bbx;x++) {
896 PyObject*pixel = PySequence_GetItem(line, x);
903 if(PyComplex_Check(pixel)) {
904 xy = pixel; image = 0;
905 } else if(PyString_Check(pixel)) {
906 xy = 0; image = pixel;
907 } else if(PyTuple_Check(pixel)) {
908 int size = PyTuple_GET_SIZE(pixel);
909 if(size!=2) return PY_ERROR("Tuples have to have size 2 (xy,img)");
910 xy = PyTuple_GetItem(pixel, 0);
912 if(!PyComplex_Check(xy)) return PY_ERROR("Tuples must be (COMPLEX,string)");
913 image = PyTuple_GetItem(pixel, 1);
915 if(!PyString_Check(image)) return PY_ERROR("Tuples must be (complex,STRING)");
923 *itx = (signed char)PyComplex_RealAsDouble(pixel);
924 *ity = (signed char)PyComplex_ImagAsDouble(pixel);
929 PyString_AsStringAndSize(image,&string,&size);
931 return PY_ERROR("image strings must be >= 256*3");
933 *pic = malloc(sizeof(RGBA)*16*16);
935 for(t=0;t<16*16;t++) {
936 (*pic)[t].r = string[t*3];
937 (*pic)[t].g = string[t*3+1];
938 (*pic)[t].b = string[t*3+2];
948 PyObject*tag = tag_new(&videoframe_tag);
949 tag_internals_t*itag = tag_getinternals(tag);
951 TAG* t = swf_InsertTag(0, ST_VIDEOFRAME);
952 swf_SetU16(t,0); /* id */
953 swf_SetVideoStreamMover(t, fi->stream, movex, movey,(void**)pics, quant);
956 tagmap_addMapping(itag->tagmap, 0, self);
958 for(x=0;x<fi->stream->bbx*fi->stream->bby;x++) {
960 free(pics[x]);pics[x] = 0;
970 static PyMethodDef videostream_methods[] =
971 {{"xblocks", videostream_getbwidth, METH_VARARGS, "get's the number of horizontal blocks"},
972 {"yblocks", videostream_getbheight, METH_VARARGS, "get's the number of vertical blocks"},
973 {"addFrame", (PyCFunction)videostream_addFrame, METH_KEYWORDS, "add a Video Frame"},
974 {"addBlackFrame", (PyCFunction)videostream_addBlackFrame, METH_KEYWORDS, "add a black Video Frame"},
975 {"addDistortionFrame", (PyCFunction)videostream_addDistortionFrame, METH_KEYWORDS, "add a MVD frame"},
976 {NULL, NULL, 0, NULL}
979 static tag_internals_t videostream_tag =
981 parse: videostream_parse,
982 fillTAG: videostream_fillTAG,
983 dealloc: videostream_dealloc,
986 tagfunctions: videostream_methods,
987 datasize: sizeof(videostream_internal_t),
990 //============================================================================
992 static tag_internals_t videoframe_tag =
1003 //============================================================================
1005 static PyMethodDef TagMethods[] =
1008 {"BackgroundColor", (PyCFunction)f_SetBackgroundColor, METH_KEYWORDS, "Create a SetBackGroundColor Tag."},
1009 {"Protect", (PyCFunction)f_Protect, METH_KEYWORDS, "Create a Protect Tag."},
1010 {"Font", (PyCFunction)f_DefineFont, METH_KEYWORDS, "Create a DefineFont Tag."},
1011 {"Text", (PyCFunction)f_DefineText, METH_KEYWORDS, "Create a DefineText Tag."},
1012 {"PlaceObject", (PyCFunction)f_PlaceObject, METH_KEYWORDS, "Create a PlaceObject Tag."},
1013 {"RemoveObject", (PyCFunction)f_RemoveObject, METH_KEYWORDS, "Create a RemoveObject Tag."},
1014 {"MoveObject", (PyCFunction)f_MoveObject, METH_KEYWORDS, "Create a PlaceObject Move Tag."},
1015 {"VideoStream", (PyCFunction)f_DefineVideoStream, METH_KEYWORDS, "Create a Videostream."},
1016 {"Image", (PyCFunction)f_DefineImage, METH_KEYWORDS, "Create an SWF Image Tag."},
1017 {"ImageShape", (PyCFunction)f_DefineImageShape, METH_KEYWORDS, "Create an SWF Image Shape Tag."},
1018 {"Shape", (PyCFunction)f_DefineShape, METH_KEYWORDS, "Create an SWF Shape Tag."},
1019 {"ShowFrame", (PyCFunction)f_ShowFrame, METH_KEYWORDS, "Create an SWF Show Frame Tag."},
1020 {"Sprite", (PyCFunction)f_Sprite, METH_KEYWORDS, "Create an SWF Sprite Tag."},
1021 {NULL, NULL, 0, NULL}
1023 PyMethodDef* tags_getMethods()
1025 TagClass.ob_type = &PyType_Type;
1027 register_tag(ST_PLACEOBJECT,&placeobject_tag);
1028 register_tag(ST_PLACEOBJECT2,&placeobject_tag);
1029 register_tag(ST_REMOVEOBJECT,&removeobject_tag);
1030 register_tag(ST_REMOVEOBJECT2,&removeobject_tag);
1031 register_tag(ST_SETBACKGROUNDCOLOR,&bgcolor_tag);
1032 register_tag(ST_DEFINEFONT,&font_tag);
1033 register_tag(ST_PROTECT,&protect_tag);
1034 register_tag(ST_DEFINETEXT,&text_tag);
1035 register_tag(ST_DEFINEBITSJPEG,&image_tag);
1036 register_tag(ST_DEFINEBITSJPEG2,&image_tag);
1037 register_tag(ST_DEFINEBITSJPEG3,&image_tag);
1038 register_tag(ST_DEFINEBITSLOSSLESS,&image_tag);
1039 register_tag(ST_DEFINEBITSLOSSLESS2,&image_tag);
1040 register_tag(ST_DEFINESHAPE,&shape_tag);
1041 register_tag(ST_DEFINESHAPE2,&shape_tag);
1042 register_tag(ST_DEFINESHAPE3,&shape_tag);
1043 register_tag(ST_SHOWFRAME,&showframe_tag);
1044 register_tag(ST_DEFINEVIDEOSTREAM,&videostream_tag);
1045 register_tag(ST_VIDEOFRAME,&videoframe_tag);
1046 register_tag(ST_DEFINESPRITE,&sprite_tag);
1047 register_tag(ST_END,&end_tag);