TAG*swf_AddAS3FontDefine(TAG*tag, U16 id, char*fontname)
{
    tag = swf_InsertTag(tag, ST_DOABC);
    abc_file_t*file = abc_file_new();

    //abc_class_t*cls = abc_class_new2(file, fontname, "flash.display::MovieClip");
    //abc_class_slot(cls, multiname_fromstring(fontname), multiname_fromstring("flash.text::Font"));

    abc_class_t*cls = abc_class_new2(file, fontname, "flash.text::Font");

    abc_script_t*s = abc_initscript(file);
    code_t*c = s->method->body->code;
    c = abc_getlocal_0(c);
    c = abc_pushscope(c);
    c = abc_getscopeobject(c, 0);
    c = abc_getlex(c,"flash.text::Font");
    c = abc_pushscope(c);
    c = abc_getlex(c,"flash.text::Font");
    c = abc_newclass(c,cls);
    c = abc_popscope(c);
    c = abc_initproperty(c, fontname);
    c = abc_returnvoid(c);
    s->method->body->code = c;

    abc_initscript_addClassTrait(s, multiname_fromstring(fontname), cls);
    swf_WriteABC(tag, file);
	
    tag = swf_InsertTag(tag, ST_SYMBOLCLASS);
    swf_SetU16(tag, 1);
    swf_SetU16(tag, id);
    swf_SetString(tag, fontname);

    return tag;
}
示例#2
0
TAG* write_sprite_defines(TAG*tag, SWF*sprite)
{
    TAG*rtag = sprite->firstTag;
    while(rtag && rtag->id!=ST_END) {
	if(!swf_isAllowedSpriteTag(rtag)) {
	    msg("<debug> processing sprite tag %02x", tag->id);
	    if(swf_isDefiningTag(rtag))
	    {
		msg("<debug> [sprite defs] write tag %02x (%d bytes in body)", 
			tag->id, tag->len);
		tag = swf_InsertTag(tag, rtag->id);
		swf_SetBlock(tag, rtag->data, rtag->len);
	    }
	    else if(swf_isPseudoDefiningTag(rtag))
	    {
		msg("<debug> [sprite defs] write tag %02x (%d bytes in body)", 
			tag->id, tag->len);
		tag = swf_InsertTag(tag, rtag->id);
		swf_SetBlock(tag, rtag->data, rtag->len);
	    }
	    else {
		switch(rtag->id)
		{
		    case ST_JPEGTABLES:
			   /* if we get here, jpeg_assert has already run,
			      ensuring this is the only one of it's kind,
			      so we may safely write it out */
			   tag = swf_InsertTag(tag, rtag->id);
			   swf_SetBlock(tag, rtag->data, rtag->len);
		       break;
		    case ST_EXPORTASSETS:
		       msg("<debug> deliberately ignoring EXPORTASSETS tag");
		       break;
		    case ST_ENABLEDEBUGGER:
		       msg("<debug> deliberately ignoring ENABLEDEBUGGER tag");
		       break;
		    case ST_SETBACKGROUNDCOLOR:
		       msg("<debug> deliberately ignoring BACKGROUNDCOLOR tag");
		       break;
		    case ST_SHOWFRAME:
		       msg("<debug> deliberately ignoring SHOWFRAME tag");
		       break;
		    case ST_REFLEX:
		       msg("<debug> deliberately ignoring REFLEX tag");
		       break;
		    case 40:
		    case 49:
		    case 51:
		       msg("<notice> found tag %d. This is a Generator template, isn't it?", rtag->id);
		       break;
		    default:
		       msg("<notice> funny tag: %d is neither defining nor sprite", rtag->id);
		}
	    }
	}
	rtag = rtag->next;
    }
    return tag;
}
示例#3
0
TAG* write_sprite(TAG*tag, SWF*sprite, int spriteid, int replaceddefine)
{
    TAG* definespritetag;
    TAG* rtag;
    int tmp;

    definespritetag = tag = swf_InsertTag(tag, ST_DEFINESPRITE);
    swf_SetU16(tag, spriteid);
    swf_SetU16(tag, sprite->frameCount);
    msg ("<notice> sprite id is %d", spriteid);

    tmp = sprite->frameCount;
    msg("<debug> %d frames to go",tmp);

    if(config.clip) {
	tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
	swf_SetU8(tag, 2+64); //flags: character+clipdepth
	swf_SetU16(tag, 0); //depth
	swf_SetU16(tag, replaceddefine); //id
	swf_SetU16(tag, 65535); //clipdepth
    }

    if(config.overlay && !config.isframe) {
	tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
	swf_SetU8(tag, 2); //flags: character
	swf_SetU16(tag, 1); //depth
	swf_SetU16(tag, replaceddefine); //id
    }

    rtag = sprite->firstTag;
    while(rtag && rtag->id!=ST_END)
    {
	if (swf_isAllowedSpriteTag(rtag)) {

	    msg("<debug> [sprite main] write tag %02x (%d bytes in body)", 
		    rtag->id, rtag->len);
	    tag = swf_InsertTag(tag, rtag->id);
	    write_changepos(tag, rtag, config.movex, config.movey, config.scalex, config.scaley, 0);

	    if(config.clip || (config.overlay && !config.isframe))
		changedepth(tag, +2);

	    if(tag->id == ST_SHOWFRAME)
	    {
		tmp--;
		msg("<debug> %d frames to go",tmp);
	    }
	}
	rtag = rtag->next;
    }
    tag = swf_InsertTag(tag, ST_END);
    return tag;
}
示例#4
0
static void swf_ShapeDrawerInit(drawer_t*draw, TAG*tag, int fillstylebits, int linestylebits)
{
    SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)rfx_calloc(sizeof(SWFSHAPEDRAWER));
    draw->internal = sdraw;

    draw->setLineStyle = swf_ShapeDrawerSetLineStyle;
    draw->setFillStyle = swf_ShapeDrawerSetFillStyle;
    draw->moveTo = swf_ShapeDrawerMoveTo;
    draw->lineTo = swf_ShapeDrawerLineTo;
    draw->splineTo = swf_ShapeDrawerSplineTo;
    draw->finish = swf_ShapeDrawerFinish;
    draw->dealloc = swf_ShapeDrawerClear;
    
    sdraw->tagfree = 0;
    if(tag == 0) {
	tag = swf_InsertTag(0, ST_DEFINESHAPE);
	sdraw->tagfree = 1;
    }
    sdraw->tag = tag;
    swf_ShapeNew(&sdraw->shape);
    draw->pos.x = 0;
    draw->pos.y = 0;

    swf_SetU8(sdraw->tag,0);
    sdraw->shape->bits.fill = fillstylebits;
    sdraw->shape->bits.line = linestylebits;
    
    sdraw->bbox.xmin = sdraw->bbox.ymin = SCOORD_MAX;
    sdraw->bbox.xmax = sdraw->bbox.ymax = SCOORD_MIN;

    sdraw->isfinished = 0;

    swf_ShapeSetStyle(sdraw->tag,sdraw->shape,linestylebits?1:0,fillstylebits?1:0,0/*?*/);
}
示例#5
0
void swf_Render_Init(RENDERBUF*buf, int posx, int posy, int width, int height, int antialize, int multiply)
{
    renderbuf_internal*i;
    int y;
    memset(buf, 0, sizeof(RENDERBUF));
    buf->width = width*multiply;
    buf->height = height*multiply;
    buf->posx = posx;
    buf->posy = posy;
    buf->internal = (renderbuf_internal*)rfx_calloc(sizeof(renderbuf_internal));
    i = (renderbuf_internal*)buf->internal;
    if(antialize < 1)
        antialize = 1;
    i->antialize = antialize;
    i->multiply = multiply*antialize;
    i->height2 = antialize*buf->height;
    i->width2 = antialize*buf->width;
    i->lines = (renderline_t*)rfx_alloc(i->height2*sizeof(renderline_t));
    for(y=0;y<i->height2;y++) {
        memset(&i->lines[y], 0, sizeof(renderline_t));
        i->lines[y].points = swf_InsertTag(0, 0);
        i->lines[y].num = 0;
    }
    i->zbuf = (int*)rfx_calloc(sizeof(int)*i->width2*i->height2);
    i->img = (RGBA*)rfx_calloc(sizeof(RGBA)*i->width2*i->height2);
    i->shapes = 0;
    i->ymin = 0x7fffffff;
    i->ymax = -0x80000000;
}
int main(int argn,char ** argv)
{ 
    srand48(time(0));
    int fi;
    SWF swf;
    TAG* tag;
    char* outfilename = "test.swf";
    char*oldpassword = "******";
    char*newpassword = "******";

    if (argn<1)
    { 
	return 0;
    }
	
    fi = open(argv[1],O_RDONLY|O_BINARY);
	
    if (fi<=0)
    { 
	fprintf(stderr,"Couldn't open %s\n", argv[1]);
    }

    if(swf_ReadSWF(fi,&swf)<0)
    { 
	fprintf(stderr,"%s is not a valid SWF file or contains errors.\n",argv[1]);
	close(fi);
    }

    tag = swf.firstTag;

    while(tag) {
	TAG*next = tag->next;
	//void  swf_SetPassword(TAG * t, const char * password);
	//int   swf_VerifyPassword(TAG * t, const char * password);
	if(tag->id == ST_PROTECT) {
	    int ret;
	    ret = swf_VerifyPassword(tag, oldpassword);
	    if(!ret) printf("Password validation failed\n");
	    else printf("Password ok\n");

	    swf_DeleteTag(&swf, tag);
	}
	tag = next;
    }

    tag = swf_InsertTag(swf.firstTag, ST_PROTECT);
    swf_SetPassword(tag, newpassword);

    fi = open(outfilename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
    if(fi<0) {
	fprintf(stderr, "couldn't create output file %s", outfilename);
    }
    if(swf_WriteSWF(fi, &swf)<0) 
        fprintf(stderr, "WriteSWF() failed.\n");

    close(fi);
    
    return 0;
}
示例#7
0
int MovieFinish(SWF * swf, TAG * t, char *sname)
{
    int handle, so = fileno(stdout);

    if (global.asset_name) {
	SWFPLACEOBJECT obj;

	t = swf_InsertTag(t, ST_END);
	t = swf_InsertTag(t, ST_EXPORTASSETS);
	swf_SetU16(t, 1);
	swf_SetU16(t, 1);
	swf_SetString(t, global.asset_name);

	t = swf_InsertTag(t, ST_PLACEOBJECT2);
	swf_GetPlaceObject(0, &obj);
	obj.depth = 1;
	obj.id = 1;
	swf_SetPlaceObject(t, &obj);

	t = swf_InsertTag(t, ST_SHOWFRAME);
    }

    t = swf_InsertTag(t, ST_END);

    if ((!isatty(so)) && (!sname))
	handle = so;
    else {
	if (!sname)
	    sname = "output.swf";
	handle = open(sname, O_BINARY | O_RDWR | O_CREAT | O_TRUNC, 0666);
    }
    if(handle<0 && sname) {
        perror(sname);
    }
    if (swf_WriteSWF(handle, swf)<0) 
        fprintf(stderr, "Unable to write output file: %s\n", sname);

    if (handle != so)
	close(handle);

    swf_FreeTags(swf);
    return 0;
}
示例#8
0
TAG *MovieStart(SWF * swf, float framerate, int dx, int dy)
{
    TAG *t;
    RGBA rgb;

    memset(swf, 0x00, sizeof(SWF));

    swf->fileVersion = global.version;
    swf->frameRate = (int)(256.0 * framerate);

    if(custom_clip) {
	swf->movieSize.xmin = clip_x1 * 20;
	swf->movieSize.ymin = clip_y1 * 20;
	swf->movieSize.xmax = clip_x2 * 20;
	swf->movieSize.ymax = clip_y2 * 20;
    } else {
	swf->movieSize.xmin = 0;
	swf->movieSize.ymin = 0;
	swf->movieSize.xmax = swf->movieSize.xmin + dx * 20;
	swf->movieSize.ymax = swf->movieSize.ymin + dy * 20;
    }

    t = swf->firstTag = swf_InsertTag(NULL, ST_SETBACKGROUNDCOLOR);

    rgb.r = rgb.g = rgb.b = rgb.a = 0x00;
    swf_SetRGB(t, &rgb);

    if (global.mx) {
	t = swf_InsertTag(t, ST_DEFINEVIDEOSTREAM);
	swf_SetU16(t, 0xf00d);
	swf_SetVideoStreamDefine(t, &stream, 65535, dx, dy);
    } else if (global.asset_name) {
	t = swf_InsertTag(t, ST_DEFINESPRITE);
	swf_SetU16(t, 1);
	swf_SetU16(t, global.next_id++);
    }

    return t;
}
示例#9
0
void swf_FontPostprocess(SWF*swf)
{
    TAG*tag = swf->firstTag;
    while(tag) {
	TAG*next = tag->next;
	if(tag->id == ST_DEFINEFONT3) {
	    U16 id = swf_GetDefineID(tag);
	    SWFFONT*font = 0;
	    swf_FontExtract(swf, id, &font);
	    if(!font->alignzones) {
		swf_FontCreateAlignZones(font);
		tag = swf_InsertTag(tag, ST_DEFINEFONTALIGNZONES);
		swf_FontSetAlignZones(tag, font);
	    }
	    swf_FontFree(font);
	}
	tag = next;
    }
}
示例#10
0
ActionTAG* swf_ActionCompile(const char* source, int version)
{
    TAG* tag;
    ActionTAG* a = 0;
    void*buffer = 0;
    int len = 0;
    int ret;
    
    tag = swf_InsertTag(NULL, ST_DOACTION);
    ret = compileSWFActionCode(source, version, &buffer, &len);
    if(!ret || buffer==0 || len == 0)
	return 0;

    swf_SetBlock(tag, (U8*)buffer, len);
    swf_SetU8(tag, 0);

    rfx_free(buffer);

    a = swf_ActionGet(tag);
    swf_DeleteTag(0, tag);
    return a;
}
示例#11
0
static void makestackmaster(SWF*swf)
{
    TAG*tag;
    int t;
    SRECT box;
    int fileversion = config.zlib?6:3;
    int frameRate = 256;
    U32 fileAttributes = 0;
    RGBA rgb;
    rgb.r=rgb.b=rgb.g=0;
    memset(&box, 0, sizeof(box));

    /* scan all slaves for bounding box */
    for(t=numslaves-1;t>=0;t--)
    {
	SWF head;
	int ret;
	int fi=open(slave_filename[t],O_RDONLY|O_BINARY);
	TAG*tag;
	if(fi<0 || swf_ReadSWF(fi, &head)<0) {
	    msg("<fatal> Couldn't open/read %s.", slave_filename[t]);
	    exit(1);
	}
	close(fi);
	swf_RemoveJPEGTables(&head);
        fileAttributes |= head.fileAttributes;
	removeCommonTags(&head);

	msg("<verbose> File %s has bounding box %d:%d:%d:%d\n",
		slave_filename[t], 
		head.movieSize.xmin, head.movieSize.ymin,
		head.movieSize.xmax, head.movieSize.ymax);

	tag = head.firstTag;
	while(tag) {
	    if(tag->id == ST_SETBACKGROUNDCOLOR && tag->len>=3) {
		rgb.r = tag->data[0];
		rgb.g = tag->data[1];
		rgb.b = tag->data[2];
	    }
	    tag=tag->next;
	}
	frameRate = head.frameRate;
	if(head.fileVersion > fileversion)
	    fileversion = head.fileVersion;
	if(!t)
	    box = head.movieSize;
	else {
	    if(head.movieSize.xmin < box.xmin)
		box.xmin = head.movieSize.xmin;
	    if(head.movieSize.ymin < box.ymin)
		box.ymin = head.movieSize.ymin;
	    if(head.movieSize.xmax > box.xmax)
		box.xmax = head.movieSize.xmax;
	    if(head.movieSize.ymax > box.ymax)
		box.ymax = head.movieSize.ymax;
	}
	msg("<verbose> New master bounding box is %d:%d:%d:%d\n",
		box.xmin, box.ymin,
		box.xmax, box.ymax);
	swf_FreeTags(&head);
    }

    memset(swf, 0, sizeof(SWF));
    swf->fileVersion = fileversion;
    swf->movieSize = box;
    swf->frameRate = frameRate;
    swf->fileAttributes = fileAttributes;

    swf->firstTag = swf_InsertTag(0, ST_SETBACKGROUNDCOLOR);
    tag = swf->firstTag;
    swf_SetRGB(tag, &rgb);
    
    for(t=0;t<numslaves;t++)
    {
	char buf[128];
	sprintf(buf, "Frame%02d", t);
	slave_name[t] = strdup(buf);

	tag = swf_InsertTag(tag, ST_DEFINESPRITE);
	swf_SetU16(tag, t+1);
	swf_SetU16(tag, 0);
	tag = swf_InsertTag(tag, ST_END);
	tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
	swf_ObjectPlace(tag, t+1, 1+t,0,0, slave_name[t]);

	if(!config.stack1 || t == numslaves-1) {
	    tag = swf_InsertTag(tag, ST_SHOWFRAME);
	}
	if(!config.stack)
	if(t!=numslaves-1)
	{
	    tag = swf_InsertTag(tag, ST_REMOVEOBJECT2);
	    swf_SetU16(tag, 1+t);
	}
    }
    tag = swf_InsertTag(tag, ST_END);
    msg("<verbose> temporary SWF created");
}
示例#12
0
static void write_font(SWFFONT * font, char *filename)
{
    SWF swf;
    TAG *t;
    SRECT r;
    RGBA rgb;
    int f;
    int useDefineFont2 = 1;
    int storeGlyphNames = 1;
   
#define WRITEFONTID 8888
    font->id = WRITEFONTID;

    memset(&swf, 0x00, sizeof(SWF));

    swf.fileVersion = 9;
    swf.frameRate = 0x4000;

    t = swf_InsertTag(NULL, ST_SETBACKGROUNDCOLOR);
    swf.firstTag = t;
    rgb.r = 0xef;
    rgb.g = 0xef;
    rgb.b = 0xff;
    swf_SetRGB(t, &rgb);
    
    t = swf_InsertTag(t, ST_DEFINEFONT3);
    swf_FontSetDefine2(t, font);

    t = swf_InsertTag(t, ST_DEFINEFONTALIGNZONES);
    swf_SetU16(t, font->id);
    swf_SetU8(t, 0); //thin
    int i;
    for(i=0;i<256;i++) {
	swf_SetU8(t, 2);
	swf_SetF16(t, 82.0 / 1024.0);
	swf_SetF16(t, 82.0 / 1024.0);
	swf_SetF16(t, ((i%16/2)*82.0) / 1024.0);
	swf_SetF16(t, ((i/16/2)*82.0) / 1024.0);
	/*
	if(i<128 && (i&15)<8) {
	    swf_SetF16(t, 0.0);
	    swf_SetF16(t, 0.0);
	    swf_SetF16(t, 640.0 / 1024.0);
	    swf_SetF16(t, 640.0 / 1024.0);
	} else if(i<128 && (i&15)>=8) {
	    swf_SetF16(t, 0.0 / 1024.0);
	    swf_SetF16(t, 0.0   / 1024.0);
	    swf_SetF16(t, 330.0 / 1024.0);
	    swf_SetF16(t, 640.0 / 1024.0);
	} else if(i>=128 && (i&15)<8) {
	    swf_SetF16(t, 0.0   / 1024.0);
	    swf_SetF16(t, 0.0 / 1024.0);
	    swf_SetF16(t, 640.0 / 1024.0);
	    swf_SetF16(t, 330.0 / 1024.0);
	} else {
	    swf_SetF16(t, 0.0 / 1024.0);
	    swf_SetF16(t, 0.0 / 1024.0);
	    swf_SetF16(t, 330.0 / 1024.0);
	    swf_SetF16(t, 330.0 / 1024.0);
	}*/
	swf_SetU8(t, 3); // x and y
    }

    int s;
    int xmax = 0;
    int ymax = 0;
    int ypos = 1;
    U8 gbits, abits;
    int x, y, c;
    int range = font->maxascii;

    c = 0;
    range = 256;

    xmax = 1280;
    ymax = 1280*20;

    swf.movieSize.xmax = xmax * 20;
    swf.movieSize.ymax = ymax;

    t = swf_InsertTag(t, ST_DEFINETEXT);
    swf_SetU16(t, font->id + 1);	// ID
    r.xmin = 0;
    r.ymin = 0;
    r.xmax = swf.movieSize.xmax;
    r.ymax = swf.movieSize.ymax;
    swf_SetRect(t, &r);
    swf_SetMatrix(t, NULL);
    abits = swf_CountBits(xmax * 16, 0);
    gbits = 8;
    swf_SetU8(t, gbits);
    swf_SetU8(t, abits);

    rgb.r = 0x00;
    rgb.g = 0x00;
    rgb.b = 0x00;
    ypos = 2;
    
    int textscale = 1024;
    for (y = 0; y < ((range + 15) / 16); y++) {
	for (x = 0; x < 16; x++) {
	    //swf_TextSetInfoRecord(t, font, textscale, &rgb, x*64*20+64*20+10+(x+y)*20, y*64*20+128*20+10+(x^y)*20);
	    swf_TextSetInfoRecord(t, font, textscale, &rgb, x*64*20+64*20+10, y*64*20+128*20+10);
	    int g = y * 16 + x;
	    swf_SetU8(t, 1);
	    swf_SetBits(t, g, gbits);
	    swf_SetBits(t, 0, abits);
	    swf_ResetWriteBits(t);
	}
    }
    swf_SetU8(t, 0);
		 
    t = swf_InsertTag(t, ST_CSMTEXTSETTINGS);
    swf_SetU16(t, font->id + 1);
    swf_SetU8(t, (1<<3)//grid
	         |0x40//flashtype
		 );
    swf_SetU32(t, 0x20000);//thickness
    swf_SetU32(t, 0x800000);//sharpness
    swf_SetU8(t, 0);//reserved

    t = swf_InsertTag(t, ST_PLACEOBJECT2);
    swf_ObjectPlace(t, font->id + 1, 1, NULL, NULL, NULL);

    t = swf_InsertTag(t, ST_SHOWFRAME);
    t = swf_InsertTag(t, ST_END);

    f = open(filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0644);
    if FAILED
	(swf_WriteSWF(f, &swf)) fprintf(stderr, "WriteSWF() failed in writeFont().\n");
    close(f);

    swf_FreeTags(&swf);
}
示例#13
0
文件: SWF.c 项目: DJwa163/swftools
//----------------------------------------------------------------------------
static PyObject * swf_save(PyObject* self, PyObject* args, PyObject* kwargs)
{
    static char *kwlist[] = {"name", "compress", NULL};
    SWFObject*swfo;
    SWF*swf;
    int fi;
    char*filename = 0;
    int compress = 0;
    
    if(!self)
	return NULL;

    swfo = (SWFObject*)self;
    swf = &swfo->swf;
    
    filename = swfo->filename;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|si", kwlist, &filename, &compress))
	return NULL;
    
    mylog(" %08x(%d) f_save filename=%s compress=%d\n", (int)self, self->ob_refcnt, filename, compress);

    // keyword arg compress (=1) forces compression
    if(compress)
	swf->compressed = 1;
    
    swf->firstTag = taglist_getTAGs(swfo->taglist);

    /*if(!swf->firstTag)
	return NULL;*/

    // fix the file, in case it is empty or not terminated properly
    {
	TAG*tag = swf->firstTag;
	if(!tag)
	    tag = swf->firstTag = swf_InsertTag(0,ST_END);
	while(tag && tag->next) {
	    tag = tag->next;
	}
	if(tag->id != ST_END) {
	    tag = swf_InsertTag(tag,ST_END);
	}
    }

    fi = open(filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
    if(fi<0) {
	PyErr_SetString(PyExc_Exception, setError("couldn't create output file %s", filename));
	return 0;
    }
    if(swf_WriteSWF(fi, swf)<0) {
        close(fi);
        PyErr_SetString(PyExc_Exception, setError("WriteSWC() failed."));
        return 0;
    }
    close(fi);

    swf_FreeTags(swf);
    /*{ TAG * t = swf->firstTag;
      while (t)
      { 
	mylog("tag: %08x\n",t);
	mylog("  id: %d (%s)\n", t->id, swf_TagGetName(t));
	mylog("  data: %08x (%d bytes)\n", t->data, t->len);
	mylog("  next: %08x\n", t->next);
	TAG * tnew = t->next;
	mylog("->free data\n");
	if (t->data) free(t->data);
	mylog("->free tag\n");
	free(t);
	t = tnew;
      }
    }*/
    swf->firstTag = 0;
    
    mylog(" %08x(%d) f_save filename=%s done\n", (int)self, self->ob_refcnt, filename);
    
    return PY_NONE;
}
示例#14
0
int main (int argc,char ** argv)
{ SWF swf;
  TAG* t;
  RGBA rgb;
  SRECT r;
  SHAPE* s;
  S32 width = 800,height = 800;
  int fs,ls; // line & fillstyle
  JPEGBITS* jpeg;
  MATRIX m;  
  
  int f,i,j,frame;
  
  memset(&swf,0x00,sizeof(SWF));

  swf.fileVersion    = 4;
  swf.frameRate      = 0x4000;
  swf.movieSize.xmax = 4*width;
  swf.movieSize.ymax = 4*height;

  swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
  t = swf.firstTag;

        rgb.r = 0xff;
        rgb.g = 0xff;
        rgb.b = 0xff;
        swf_SetRGB(t,&rgb);

    t = swf_InsertTag(t,ST_DEFINEBITSJPEG2);

         swf_SetU16(t,ID_BITMAP);
         
         if (FAILED(swf_SetJPEGBits(t,"texture.jpg",QUALITY)))
         { fprintf(stderr,"Error: texture.jpg (256x256) not found in work directory.\n");
           exit(1);
         }
         
    t = swf_InsertTag(t,ST_DEFINESHAPE);
    
         swf_ShapeNew(&s);
         rgb.b = rgb.g = rgb.r = 0x00;
         ls = 0;
         rgb.b = 0xff;
  
         fs = swf_ShapeAddBitmapFillStyle(s,NULL,ID_BITMAP,0);
    
         swf_SetU16(t,ID_SHAPE);    // ID   
         
         r.xmin = 0;
         r.ymin = 0;
         r.xmax = 2*width;
         r.ymax = 2*height;
         
         swf_SetRect(t,&r);

         swf_SetShapeHeader(t,s);
         
         swf_ShapeSetAll(t,s,0,0,ls,fs,0);
         swf_ShapeSetLine(t,s,width,0);
         swf_ShapeSetLine(t,s,-width,height);
         swf_ShapeSetLine(t,s,0,-height);
         swf_ShapeSetEnd(t);

         swf_ShapeFree(s);
    
  for (frame=0;frame<64;frame++)
  {

    /* Test procedure for swf_MatrixJoin

    MATRIX m1,m2;

    // set m1 to left rotation
     
    m1.sy = m1.sx = (int)(cos(((float)(frame))/32*3.141)*0x10000);
    m1.r0 = (int)(sin(((float)(frame))/32*3.141)*0x10000);
    m1.r1 = -m1.r0;
    m1.tx = width+frame*4; m1.ty = height;

    // set m2 to right rotation

    m2.sy = m2.sx = (int)(cos(((float)(64-frame))/32*3.141)*0x10000);
    m2.r0 = (int)(sin(((float)(64-frame))/32*3.141)*0x10000);
    m2.r1 = -m2.r0;
    m2.tx = width; m2.ty = height;

    // joining m1 and m2 should lead to no transformation

    swf_MatrixJoin(&m,&m1,&m2);

    */

    int dx0 = width;    // constants of shape 
    int dy0 = width;

    int px0 = 2*width;  // destination of mapping
    int py0 = 2*width;

    int px1 = 3*width;
    int py1 = 2*width-frame*4;

    int px2 = 2*width-frame*8;
    int py2 = 3*width;

    swf_MatrixMapTriangle(&m,dx0,dy0,px0,py0,px1,py1,px2,py2);

    t = swf_InsertTag(t,ST_PLACEOBJECT2);

        if (!frame)
         swf_ObjectPlace(t,ID_SHAPE,1,&m,NULL,NULL);
        else
          swf_ObjectMove(t,1,&m,NULL);
 
    t = swf_InsertTag(t,ST_SHOWFRAME);
  }
  
  
  t = swf_InsertTag(t,ST_END);
  
//  swf_WriteCGI(&swf);

  f = open("transtest.swf",O_RDWR|O_CREAT|O_TRUNC|O_BINARY,0644);
  if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
  close(f);

  swf_FreeTags(&swf);

#ifdef __NT__
  system("start ..\\transtest.swf");
#endif
  
  return 0;
}
示例#15
0
int main (int argc,char ** argv)
{
    char buf[512];
    char*currentdir = getcwd(buf, 512);
    if(!currentdir) {
        as3_warning("Could not determine the current directory");
    } else {
        as3_add_include_dir(currentdir);
    }

    int t;
    processargs(argc, argv);
    as3_setverbosity(verbose);

    if(!filename) {
	args_callback_usage(argv[0]);
	exit(1);
    }
    if(!outputname) {
	outputname = stripFilename(filename, ".swf");
        //as3_warning("output name not given, writing to %s", outputname);
    }

    if(!strcmp(filename, ".")) {
        as3_parse_directory(".");
    } else {
        as3_parse_file(filename);
    }

    void*code = as3_getcode();

    SWF swf;
    memset(&swf, 0, sizeof(swf));
    swf.fileVersion = flashversion;
    swf.frameRate = framerate*0x100;
    swf.movieSize.xmin = 0;
    swf.movieSize.ymin = 0;
    swf.movieSize.xmax = width*20;
    swf.movieSize.ymax = height*20;
    TAG*tag = swf.firstTag = swf_InsertTag(0, ST_DOABC);
    swf_WriteABC(tag, code);

    if(!mainclass)
        mainclass = as3_getglobalclass();
    if(mainclass) {
        tag = swf_InsertTag(tag, ST_SYMBOLCLASS);
        swf_SetU16(tag, 1);
        swf_SetU16(tag, 0);
        swf_SetString(tag, mainclass);
    } else {
        as3_warning("no global public MovieClip subclass");
    }
    
    as3_destroy();

    tag = swf_InsertTag(tag, ST_SHOWFRAME);
    tag = swf_InsertTag(tag, ST_END);

    swf_FreeABC(code);
    
    if(local_with_filesystem)
        swf.fileAttributes &= ~FILEATTRIBUTE_USENETWORK;
    if(local_with_networking)
        swf.fileAttributes |= FILEATTRIBUTE_USENETWORK;

    writeSWF(&swf);
    swf_FreeTags(&swf);

    return 0;
}
示例#16
0
int catcombine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
{
    char* depths;
    int t;
    TAG*tag;
    TAG*mtag,*stag;
    if(config.isframe) {
		msg("<fatal> Can't combine --cat and --frame");
		return 101;
    }
    if(config.flashversion)
	master->fileVersion = config.flashversion;
   
    tag = master->firstTag;
    while(tag)
    {
	if(swf_isDefiningTag(tag)) {
	    int defineid = swf_GetDefineID(tag);
	    msg("<debug> tagid %02x defines object %d", tag->id, defineid);
	    masterbitmap[defineid] = 1;
	}
	tag = tag->next;
    }
    
    swf_Relocate(slave, masterbitmap);
    jpeg_assert(master, slave);
    
    memcpy(newswf, master, sizeof(SWF));
    adjustheader(newswf);

    tag = newswf->firstTag = swf_InsertTag(0, ST_REFLEX); // to be removed later

    depths = malloc_safe(65536);
    if(!depths) {
	msg("<fatal> Couldn't allocate %d bytes of memory", 65536);
	return 111;
    }
    memset(depths, 0, 65536);
    mtag = master->firstTag;
    while(mtag && mtag->id!=ST_END)
    {
	int num=1;
	U16 depth;
	msg("<debug> [master] write tag %02x (%d bytes in body)", 
		mtag->id, mtag->len);
	switch(mtag->id) {
	    case ST_PLACEOBJECT2:
		num++;
	    case ST_PLACEOBJECT: {
	       depth = swf_GetDepth(mtag);
	       depths[depth] = 1;
	    }
	    break;
	    case ST_REMOVEOBJECT: {
	       depth = swf_GetDepth(mtag);
	       depths[depth] = 0;
	    }
	    break;
	    case ST_REMOVEOBJECT2: {
	       depth = swf_GetDepth(mtag);
	       depths[depth] = 0;
	    }
	    break;
	}
	tag = swf_InsertTag(tag, mtag->id);
	swf_SetBlock(tag, mtag->data, mtag->len);

	mtag = mtag->next;
    }

    for(t=0;t<65536;t++) 
    if(depths[t])
    {
	char data[16];
	int len;
	tag = swf_InsertTag(tag, ST_REMOVEOBJECT2);
	swf_SetU16(tag, t);
    }
    free(depths);

    stag = slave->firstTag;
    while(stag && stag->id!=ST_END)
    {
	msg("<debug> [slave] write tag %02x (%d bytes in body)", 
		stag->id, stag->len);
	tag = swf_InsertTag(tag, stag->id);
	swf_SetBlock(tag, stag->data, stag->len);
	stag = stag->next;
    }
    tag = swf_InsertTag(tag, ST_END);

    swf_DeleteTag(newswf, tag);

	return 0;
}
示例#17
0
TAG* write_master(TAG*tag, SWF*master, SWF*slave, int spriteid, int replaceddefine, int flags)
{
    int outputslave = 0;
    int frame = 1;
    int sframe = 0;
    int slavewritten = 0;
    int deletedepth = -1;

    TAG* rtag = master->firstTag;
    TAG* stag = slave->firstTag;

    while(rtag && rtag->id!=ST_END)
    {
	if(rtag->id == ST_SHOWFRAME && outputslave)
	{
	    while(stag && stag->id!=ST_END) {
		if(stag->id == ST_SHOWFRAME) {
		    stag = stag->next;
		    sframe++;
		    break;
		}
		if(tag_ok_for_slave(stag->id)) {
		    tag = swf_InsertTag(tag, stag->id);
		    write_changepos(tag, stag, config.movex, config.movey, config.scalex, config.scaley, 0);
		}
		stag = stag->next;
	    }
	}
	if(rtag->id == ST_SHOWFRAME)
	{
	    frame ++;
	    tag = swf_InsertTag(tag, ST_SHOWFRAME);
            if(deletedepth>=0) {
                tag = swf_InsertTag(tag, ST_REMOVEOBJECT2);
                swf_SetU16(tag, deletedepth);
                deletedepth=-1;
            }
	    rtag = rtag->next;
            continue;
	}

	if(swf_isDefiningTag(rtag) && (flags&FLAGS_WRITEDEFINES))
	{
	    msg("<debug> [master] write tag %02x (%d bytes in body)", 
		    rtag->id, rtag->len);
	    if(swf_GetDefineID(rtag) == spriteid && !config.isframe)
	    {
		if(config.overlay)
		{
		    tag = swf_InsertTag(tag, rtag->id);
		    swf_SetBlock(tag, rtag->data, rtag->len);
		    swf_SetDefineID(tag, replaceddefine);
		} else {
		    /* don't write this tag */
		    msg("<verbose> replacing tag %d ID %d with sprite", rtag->id ,spriteid);
		}

		if(flags&FLAGS_WRITESPRITE)
		{
		    msg("<debug> writing sprite defines");
		    tag = write_sprite_defines(tag, slave);
		    msg("<debug> writing sprite");
		    tag = write_sprite(tag, slave, spriteid, replaceddefine);
		}
		if(flags&FLAGS_WRITESLAVE)
		{
		    msg("<debug> writing slave");
		    outputslave = 1;
		}
	    } else { 
		tag = swf_InsertTag(tag, rtag->id);
		swf_SetBlock(tag, rtag->data, rtag->len);
	    }
	}
	if(frame == slaveframe) /* only happens with config.isframe: put slave at specific frame */
	{
	    if(flags&FLAGS_WRITESLAVE) {
		outputslave = 1;
		slavewritten = 1;
	    }
	    if((flags&FLAGS_WRITESPRITE) && !slavewritten)
	    {
		int id = get_free_id(masterbitmap);
		int depth = 65535;
		deletedepth = 65535;
		if(config.clip) {
		    msg("<fatal> Can't combine --clip and --frame");
		}
		
		tag = write_sprite_defines(tag, slave);
		tag = write_sprite(tag, slave, id, -1);

		tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
		    swf_SetU8(tag, 2); //flags: id
		    swf_SetU16(tag, depth);
		    swf_SetU16(tag, id);

		slavewritten = 1;
	    }
	}
	if(!swf_isDefiningTag(rtag) && (flags&FLAGS_WRITENONDEFINES))
	{
	    int dontwrite = 0;
	    switch(rtag->id) {
		case ST_PLACEOBJECT:
		case ST_PLACEOBJECT2:
		    if(frame == slaveframe && !config.overlay)
			dontwrite = 1;
		case ST_REMOVEOBJECT:
		    /* place/removetags for the object we replaced
		       should be discarded, too, as the object to insert 
		       isn't a sprite 
		     */
		    if(spriteid>=0 && swf_GetPlaceID(rtag) == spriteid && 
			    !config.isframe && config.merge)
			dontwrite = 1;
		break;
		case ST_REMOVEOBJECT2:
		break;
	    }
	    if(!dontwrite) {
		msg("<debug> [master] write tag %02x (%d bytes in body)", 
			rtag->id, rtag->len);
		tag = swf_InsertTag(tag, rtag->id);
		write_changepos(tag, rtag, config.mastermovex, config.mastermovey, config.masterscalex, config.masterscaley, 1);
		
	    }
	}
	rtag = rtag->next;
    }
   
    if(outputslave) 
    while(stag && stag->id!=ST_END)
    {
	    if(tag_ok_for_slave(stag->id)) {
		msg("<debug> [slave] write tag %02x (%d bytes in body), %.2f %.2f", rtag->id, rtag->len, config.movex /20.0, config.movey /20.0);
		tag = swf_InsertTag(tag, stag->id);
		write_changepos(tag, stag, config.movex, config.movey, config.scalex, config.scaley, 0);
	    }
	    stag = stag->next;
    }
    if(!slavewritten && config.isframe && (flags&(FLAGS_WRITESLAVE|FLAGS_WRITESPRITE)))
    {
	if(slaveframe>=0)
	    msg("<warning> Frame %d doesn't exist in file. No substitution will occur",
		    slaveframe);
	else
	    msg("<warning> Frame \"%s\" doesn't exist in file. No substitution will occur",
		    slavename);
    }
    tag = swf_InsertTag(tag, ST_END);
    return tag;
}
示例#18
0
void swf_AddButtonLinks(SWF*swf, char stop_each_frame, char events)
{
    int num_frames = 0;
    int has_buttons = 0;
    TAG*tag=swf->firstTag;

    unsigned int checksum = 0;
    while(tag) {
        if(tag->id == ST_SHOWFRAME)
            num_frames++;
        if(tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2)
            has_buttons = 1;
	crc32_add_bytes(checksum, tag->data, tag->len);
        tag = tag->next;
    }
    int t = time(0);
    checksum = crc32_add_bytes(checksum, &t, sizeof(t));

    unsigned char h[16];
    unsigned char file_signature[33];
    sprintf((char*)file_signature, "%x", checksum);

    char scenename1[80], scenename2[80];
    sprintf(scenename1, "rfx.MainTimeline_%s", file_signature);
    sprintf(scenename2, "rfx::MainTimeline_%s", file_signature);

    abc_file_t*file = abc_file_new();
    abc_method_body_t*c = 0;
   
    abc_class_t*cls = abc_class_new2(file, scenename2, "flash.display::MovieClip");
  
    TAG*abctag = swf_InsertTagBefore(swf, swf->firstTag, ST_DOABC);
    
    tag = swf_InsertTag(abctag, ST_SYMBOLCLASS);
    swf_SetU16(tag, 1);
    swf_SetU16(tag, 0);
    swf_SetString(tag, scenename1);

    c = abc_class_getstaticconstructor(cls, 0)->body;
    c->old.max_stack = 1;
    c->old.local_count = 1;
    c->old.init_scope_depth = 9;
    c->old.max_scope_depth = 10;

    __ getlocal_0(c);
    __ pushscope(c);
    __ returnvoid(c);

    c = abc_class_getconstructor(cls, 0)->body;
    c->old.max_stack = 3;
    c->old.local_count = 1;
    c->old.init_scope_depth = 10;
    c->old.max_scope_depth = 11;
    
    debugfile(c, "constructor.as");

    __ getlocal_0(c);
    __ pushscope(c);

    __ getlocal_0(c);
    __ constructsuper(c,0);

    if(stop_each_frame || has_buttons) {
        int frame = 0;
        tag = swf->firstTag;
        abc_method_body_t*f = 0; //frame script
        while(tag && tag->id!=ST_END) {
            char framename[80];
            char needs_framescript=0;
            char buttonname[80];
            char functionname[80];
            sprintf(framename, "[packageinternal]rfx::frame%d_%s", frame, file_signature);
            
            if(!f && (tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2 || stop_each_frame)) {
                /* make the contructor add a frame script */
                __ findpropstrict(c,"[package]::addFrameScript");
                __ pushuint(c,frame);
                __ getlex(c,framename);
                __ callpropvoid(c,"[package]::addFrameScript",2);

                f = abc_class_method(cls, 0, multiname_fromstring(framename))->body;
                f->old.max_stack = 3;
                f->old.local_count = 1;
                f->old.init_scope_depth = 10;
                f->old.max_scope_depth = 11;
                __ debugfile(f, "framescript.as");
                __ debugline(f, 1);
                __ getlocal_0(f);
                __ pushscope(f);
                if(stop_each_frame) {
                    __ findpropstrict(f, "[package]::stop");
                    __ callpropvoid(f, "[package]::stop", 0);
                }
            }

            if(tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2) {
                U16 id = swf_GetDefineID(tag);
                sprintf(buttonname, "::button%d", swf_GetDefineID(tag));
                __ getlex(f,buttonname);
                __ getlex(f,"flash.events::MouseEvent");
                __ getproperty(f, "::CLICK");
                sprintf(functionname, "::clickbutton%d_%s", swf_GetDefineID(tag), file_signature);
                __ getlex(f,functionname);
                __ callpropvoid(f, "::addEventListener" ,2);

                needs_framescript = 1;

                abc_method_body_t*h =
                    abc_class_method(cls, 0, multiname_fromstring(functionname))->body;
                list_append(h->method->parameters, multiname_fromstring("flash.events::MouseEvent"));

                h->old.max_stack = 6;
                h->old.local_count = 2;
                h->old.init_scope_depth = 10;
                h->old.max_scope_depth = 11;
                __ getlocal_0(h);
                __ pushscope(h);

                ActionTAG*oldaction = swf_ButtonGetAction(tag);
                if(oldaction && oldaction->op == ACTION__GOTOFRAME) {
                    int framenr = GET16(oldaction->data);
                    if(!events) {
                        __ findpropstrict(h,"[package]::gotoAndStop");
                        __ pushuint(h,framenr+1);
                        __ callpropvoid(h,"[package]::gotoAndStop", 1);
                    } else {
                        char framename[80];
                        sprintf(framename, "frame%d_%s", framenr, file_signature);
                        __ getlocal_0(h); //this
                        __ findpropstrict(h, "[package]flash.events::TextEvent");
                        __ pushstring(h, "link");
                        __ pushtrue(h);
                        __ pushtrue(h);
                        __ pushstring(h, framename);
                        __ constructprop(h,"[package]flash.events::TextEvent", 4);
                        __ callpropvoid(h,"[package]::dispatchEvent", 1);
                    }
                } else if(oldaction && oldaction->op == ACTION__GETURL) {
                    if(!events) {
                        __ findpropstrict(h,"flash.net::navigateToURL");
                        __ findpropstrict(h,"flash.net::URLRequest");
                        // TODO: target _blank
                        __ pushstring(h,(char*)oldaction->data); //url
                        __ constructprop(h,"flash.net::URLRequest", 1);
                        __ callpropvoid(h,"flash.net::navigateToURL", 1);
                    } else {
                        __ getlocal_0(h); //this
                        __ findpropstrict(h, "[package]flash.events::TextEvent");
                        __ pushstring(h, "link");
                        __ pushtrue(h);
                        __ pushtrue(h);
                        __ pushstring(h,(char*)oldaction->data); //url
                        __ constructprop(h,"[package]flash.events::TextEvent", 4);
                        __ callpropvoid(h,"[package]::dispatchEvent", 1);
                    }
                } else if(oldaction) {
                    fprintf(stderr, "Warning: Couldn't translate button code of button %d to flash 9 abc action\n", id);
                }
                __ returnvoid(h);
                swf_ActionFree(oldaction);
            }
            if(tag->id == ST_SHOWFRAME) {
                if(f) {
                    __ returnvoid(f);
                    f = 0;
                }
                frame++;
            }
            tag = tag->next;
        }
        if(f) {
            __ returnvoid(f);
        }
    }
    __ returnvoid(c);

    tag = swf->firstTag;
    while(tag) {
        if(tag->id == ST_DEFINEBUTTON || tag->id == ST_DEFINEBUTTON2) {
            char buttonname[80];
            sprintf(buttonname, "::button%d", swf_GetDefineID(tag));
            multiname_t*s = multiname_fromstring(buttonname);
            //abc_class_slot(cls, multiname_fromstring(buttonname), s);
            abc_class_slot(cls, multiname_fromstring(buttonname), 
                                multiname_fromstring("flash.display::SimpleButton"));
        }
        tag = tag->next;
    }


    abc_script_t*s = abc_initscript(file);
    c = s->method->body;
    c->old.max_stack = 2;
    c->old.local_count = 1;
    c->old.init_scope_depth = 1;
    c->old.max_scope_depth = 9;

    __ getlocal_0(c);
    __ pushscope(c);
    __ getscopeobject(c, 0);
    __ getlex(c,"::Object");
    __ pushscope(c);
    __ getlex(c,"flash.events::EventDispatcher");
    __ pushscope(c);
    __ getlex(c,"flash.display::DisplayObject");
    __ pushscope(c);
    __ getlex(c,"flash.display::InteractiveObject");
    __ pushscope(c);
    __ getlex(c,"flash.display::DisplayObjectContainer");
    __ pushscope(c);
    __ getlex(c,"flash.display::Sprite");
    __ pushscope(c);
    __ getlex(c,"flash.display::MovieClip");
    __ pushscope(c);
    __ getlex(c,"flash.display::MovieClip");
    __ newclass(c,cls);
    __ popscope(c);
    __ popscope(c);
    __ popscope(c);
    __ popscope(c);
    __ popscope(c);
    __ popscope(c);
    __ popscope(c);
    __ initproperty(c,scenename2);
    __ returnvoid(c);

    //abc_method_body_addClassTrait(c, "rfx:MainTimeline", 1, cls);
    multiname_t*classname = multiname_fromstring(scenename2);
    abc_initscript_addClassTrait(s, classname, cls);
    multiname_destroy(classname);

    swf_WriteABC(abctag, file);
}
示例#19
0
文件: shape1.c 项目: DJwa163/swftools
int main (int argc,char ** argv)
{ SWF swf;
  TAG* t;
  RGBA rgb;
  SRECT r;
  SHAPE* s;
  S32 width=300,height = 300;
  
  int f,i,ls1,ls2;

  memset(&swf,0x00,sizeof(SWF));        // set global movie parameters

  swf.fileVersion    = 4;               // make flash 4 compatible swf
  swf.frameRate      = 0x1900;          // about 0x19 frames per second
  
  swf.movieSize.xmax = 20*width;        // flash units: 1 pixel = 20 units
  swf.movieSize.ymax = 20*height;

  swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);

                                        // now create a tag list be connecting one after another
  
  t = swf.firstTag;

        rgb.r = 0xff;
        rgb.g = 0xff;
        rgb.b = 0xff;
        swf_SetRGB(t,&rgb);

  t = swf_InsertTag(t,ST_DEFINESHAPE);

        swf_ShapeNew(&s);               // create new shape instance

                                        // add two different linestyles
        rgb.b = rgb.g = 0x00;           
        ls1 = swf_ShapeAddLineStyle(s,40,&rgb);
        
        rgb.r = 0; rgb.b = 0xff;
        ls2 = swf_ShapeAddLineStyle(s,40,&rgb);

        swf_SetU16(t,1);                // now set character ID

        r.xmin = 0;
        r.ymin = 0;
        r.xmax = 20*width;
        r.ymax = 20*height;
        
        swf_SetRect(t,&r);              // set shape bounds


        swf_SetShapeHeader(t,s);        // write all styles to tag

        swf_ShapeSetAll(t,s,0,0,ls1,0,0); // move to (0,0), select linestyle ls1 and no fillstyle

                                        
        swf_ShapeSetLine(t,s,10*width,10*height);    // draw something
        swf_ShapeSetStyle(t,s,ls2,0,0);            // change to second linestyle 
        
        for (i=1;i<10;i++)
          swf_ShapeSetCircle(t,s,10*width,10*height,i*width,i*height);
          
        swf_ShapeSetEnd(t);                 // finish drawing

        swf_ShapeFree(s);                   // clean shape structure (which isn't needed anymore after writing the tag)

  t = swf_InsertTag(t,ST_PLACEOBJECT2);     // append tag to place your shape into the scene

        swf_ObjectPlace(t,1,1,NULL,NULL,NULL); // set character with id 1 (our shape) to depth 1 (upper most layer)

  t = swf_InsertTag(t,ST_SHOWFRAME);        // finish current frame

  t = swf_InsertTag(t,ST_END);              // finish current movie (which has just one frame)
  
//  swf_WriteCGI(&swf);    <- use this to create direct CGI output
  
                                            // write movie to file

  f = open("shape1.swf",O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
  if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
  close(f);

  swf_FreeTags(&swf);                       // cleanup

#ifdef __NT__                               // start flash player to show result on windows systems
  system("start ..\\shape1.swf");
#endif
  
  return 0;
}
示例#20
0
int mainCombine(int argn, char *argv[])
{
    int fi;
    SWF master;
    SWF slave;
    SWF newswf;
    int t;

    config.overlay = 0; 
    config.antistream = 0; 
    config.alloctest = 0;
    config.cat = 0;
    config.merge = 0;
    config.clip = 0;
    config.loglevel = 2; 
    config.movex = 0;
    config.movey = 0;
    config.scalex = 1.0;
    config.scaley = 1.0;
    config.sizex = 0;
    config.sizey = 0;
    config.masterscalex = 1.0;
    config.masterscaley = 1.0;
    config.mastermovex = 0;
    config.mastermovey = 0;
    config.hassizex = 0;
    config.hassizey = 0;
    config.framerate = 0;
    config.stack = 0;
    config.stack1 = 0;
    config.dummy = 0;
    config.zlib = 0;

    processargs(argn, argv);
    initLog(0,-1,0,0,-1,config.loglevel);

    if(config.merge && config.cat) {
		msg("<error> Can't combine --cat and --merge");
		return 102;
    }
    
    if(config.stack && config.cat) {
		msg("<error> Can't combine --cat and --stack");
		return 103;
    }

    if(config.stack) {
	if(config.overlay) {
	    msg("<error> Can't combine -l and -t");
	    return 104;
	}
	if(config.clip) {
	    msg("<error> Can't combine -c and -t");
	    return 105;
	}
	msg("<verbose> (stacking) %d files found\n", numslaves);

	makestackmaster(&master);
    }
    else {
	int ret;
	msg("<verbose> master entity %s (named \"%s\")\n", master_filename, master_name);
	fi = open(master_filename, O_RDONLY|O_BINARY);
	if(fi<0) {
	    msg("<fatal> Failed to open %s\n", master_filename);
	    return 106;
	}
	ret = swf_ReadSWF(fi, &master);
	if(ret<0) {
	    msg("<fatal> Failed to read from %s\n", master_filename);
	    return 107;
	}
	swf_RemoveJPEGTables(&master);
	removeCommonTags(&master);
	msg("<debug> Read %d bytes from masterfile\n", ret);
	close(fi);
    }

    for(t=0;t<numslaves;t++) {
	    msg("<verbose> slave entity(%d) %s (%s \"%s\")\n", t+1, slave_filename[t], 
		    slave_isframe[t]?"frame":"object", slave_name[t]);
    }

    if(config.dummy)
    {
	if(numslaves)
	{
	    msg("<error> --dummy (-d) implies there are zero slave objects. You supplied %d.", numslaves);
	    return 108;
	}
	numslaves = 1;
	slave_filename[0] = "!!dummy!!";
	slave_name[0] = "!!dummy!!";
	slave_isframe[0] = 0;
    }

    if (config.alloctest)
    {
	char*bitmap = malloc_safe(sizeof(char)*65536);
	memset(bitmap, 0, 65536*sizeof(char));
	memset(bitmap, 1, 101*sizeof(char));
	swf_Relocate(&master, bitmap);
	newswf = master;
	free(bitmap);
//	makestackmaster(&newswf);
    }
    else
    {
	if (!numslaves)
	{
	    if(config.cat)
		msg("<error> You must have at least two objects.");
	    else
		msg("<error> You must have at least one slave entity.");
	    return 0;
	}
	for(t = 0; t < numslaves; t++)
	{
	    config.movex = slave_movex[t];
	    config.movey = slave_movey[t];
	    config.scalex = slave_scalex[t];
	    config.scaley = slave_scaley[t];
	    config.isframe = slave_isframe[t];

	    msg("<notice> Combine [%s]%s and [%s]%s", master_name, master_filename,
		    slave_name[t], slave_filename[t]);
	    if(!config.dummy)
	    {
		int ret;
		fi = open(slave_filename[t], O_RDONLY|O_BINARY);
		if(!fi) {
		    msg("<fatal> Failed to open %s\n", slave_filename[t]);
		    return 109;
		}
		ret = swf_ReadSWF(fi, &slave);
		if(ret<0) {
		    msg("<fatal> Failed to read from %s\n", slave_filename[t]);
			return 110;
		}
		msg("<debug> Read %d bytes from slavefile\n", ret);
		close(fi);
		swf_RemoveJPEGTables(&slave);
		removeCommonTags(&slave);
	    }
	    else
	    {
		memset(&slave, 0, sizeof(slave));
		slave.firstTag = swf_InsertTag(0, ST_END);
		slave.frameRate = 0;
		slave.fileVersion = 0;
		slave.frameCount = 0;
	    }

	    int ret = combine(&master, slave_name[t], &slave, &newswf);
		if(ret != 0)
			return ret;
	    master = newswf;
	}
	if(config.dummy && !config.hassizex && !config.hassizey && !config.mastermovex && !config.mastermovey) {
	    newswf.movieSize.xmin = newswf.movieSize.xmin*config.masterscalex;
	    newswf.movieSize.ymin = newswf.movieSize.ymin*config.masterscaley;
	    newswf.movieSize.xmax = newswf.movieSize.xmax*config.masterscalex;
	    newswf.movieSize.ymax = newswf.movieSize.ymax*config.masterscaley;
	}
    }

    if(!newswf.fileVersion)
	newswf.fileVersion = 4;

    if(config.local_with_filesystem)
        newswf.fileAttributes &= ~FILEATTRIBUTE_USENETWORK;
    if(config.local_with_networking)
        newswf.fileAttributes |= FILEATTRIBUTE_USENETWORK;
    if(config.accelerated_blit)
        newswf.fileAttributes |= FILEATTRIBUTE_USEACCELERATEDBLIT;
    if(config.hardware_gpu)
        newswf.fileAttributes |= FILEATTRIBUTE_USEHARDWAREGPU;

    fi = open(outputname_c, O_BINARY|O_RDWR|O_TRUNC|O_CREAT, 0777);

    if(config.zlib) {
	if(newswf.fileVersion < 6)
	    newswf.fileVersion = 6;
        newswf.compressed = 1;
	swf_WriteSWF(fi, &newswf);
    } else {
	newswf.compressed = -1; // don't compress
	swf_WriteSWF(fi, &newswf);
    }
    close(fi);

    return 0; //ok
}
示例#21
0
int normalcombine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
{
    int spriteid = -1;
    int replaceddefine = -1;
    int frame = 0;
    char*framelabel;
    TAG * tag = master->firstTag;

    memset(depthbitmap, 0, sizeof(depthbitmap));
    
    // set the idtab
    while(tag)
    {
	int depth = swf_GetDepth(tag);
	if(depth>=0) {
	    depthbitmap[depth] = 1;
	}
	if(swf_isDefiningTag(tag)) {
	    int defineid = swf_GetDefineID(tag);
	    msg("<debug> tagid %02x defines object %d", tag->id, defineid);
	    masterbitmap[defineid] = 1;

	    if (!slavename && defineid==slaveid) {
		if(defineid>=0) {
		  spriteid = defineid;
		  msg("<notice> Slave file attached to object %d.", defineid);
		}
	    }
	} else if(tag->id == ST_EXPORTASSETS) {
	    int t;
	    int num = swf_GetU16(tag);
	    for(t=0;t<num;t++)
	    {
		U16 id = swf_GetU16(tag);
		char*name = swf_GetString(tag);
		if(spriteid<0 && slavename && !strcmp(name,slavename)) {
		    spriteid = id;
		    msg("<notice> Slave file attached to object %d exported as %s.", id, name);
		}
	    }
	} else if(tag->id == ST_SYMBOLCLASS) {
	    /* a symbolclass tag is like a define tag: it defines id 0000 */
	    int num = swf_GetU16(tag);
	    int t;
	    for(t=0;t<num;t++) {
		U16 id = swf_GetU16(tag);
		if(!id) {
		    masterbitmap[id] = 1;
		}
		swf_GetString(tag);
	    }
	} else if(tag->id == ST_PLACEOBJECT2) {
	    char * name = swf_GetName(tag);
	    int id = swf_GetPlaceID(tag);

	    {
		SWFPLACEOBJECT obj;
		swf_GetPlaceObject(tag, &obj);
		swf_PlaceObjectFree(&obj);
		if(obj.clipdepth) {
		    depthbitmap[obj.clipdepth] = 1;
		}
	    }

	    if(name)
	      msg("<verbose> tagid %02x places object %d named \"%s\"", tag->id, id, name);
	    else
	      msg("<verbose> tagid %02x places object %d (no name)", tag->id, id);

	    if (name && slavename && !strcmp(name,slavename)) {
		if(id>=0) {
		  spriteid = id;
		  msg("<notice> Slave file attached to named object %s (%d).", name, id);
		}
	    }
	} else if(tag->id == ST_SHOWFRAME) {
	    if(slaveframe>=0 && frame==slaveframe) {
		msg("<notice> Slave file attached to frame %d.", frame);
	    }
	    frame++;
	} else if(tag->id == ST_FRAMELABEL) {
	    char * name = (char *)tag->data;
	    if(name && slavename && config.isframe && !strcmp(name, slavename)) {
		slaveframe = frame;
		msg("<notice> Slave file attached to frame %d (%s).", frame, name);
	    }
	}
	tag = tag->next;
    };

    if (spriteid<0 && !config.isframe) {
	if(slavename) {
	    if(strcmp(slavename,"!!dummy!!")) {
		msg("<warning> Didn't find anything named %s in file. No substitutions will occur.", slavename);
		if(!strcmp(slavename, "swf")) {
		    msg("<warning> (If you were trying to combine rfxview with a document, try replacing 'swf' with 'viewport'.");
		}
	    }
	}
	else
	    msg("<warning> Didn't find id %d in file. No substitutions will occur.", slaveid);
	spriteid = get_free_id(masterbitmap);
    }

    swf_Relocate (slave, masterbitmap);
    
    if(config.merge)
	swf_RelocateDepth (slave, depthbitmap);
    jpeg_assert(slave, master);
    
    if (config.overlay)
	replaceddefine = get_free_id(masterbitmap);
    
    // write file 

    memcpy(newswf, master, sizeof(SWF));
    adjustheader(newswf);

    newswf->firstTag = tag = swf_InsertTag(0, ST_REFLEX); // to be removed later

    if (config.antistream) {
	if (config.merge) {
	    msg("<fatal> Can't combine --antistream and --merge");
	}
	tag = write_sprite_defines(tag, slave);
	tag = write_sprite(tag, slave, spriteid, replaceddefine);
	tag = write_master(tag, master, slave, spriteid, replaceddefine, FLAGS_WRITEDEFINES);
	tag = write_master(tag, master, slave, spriteid, replaceddefine, FLAGS_WRITENONDEFINES);
    } else {
	if (config.merge)
	    tag = write_master(tag, master, slave, spriteid, replaceddefine, 
		FLAGS_WRITEDEFINES|FLAGS_WRITENONDEFINES|   FLAGS_WRITESLAVE	);
	else
	    tag = write_master(tag, master, slave, spriteid, replaceddefine, 
		FLAGS_WRITEDEFINES|FLAGS_WRITENONDEFINES|   FLAGS_WRITESPRITE	);
    }

    swf_DeleteTag(newswf, newswf->firstTag);

	return 0;
}
示例#22
0
int main (int argc,char ** argv)
{ SWF swf;
  RGBA rgb;
  SRECT r;
  SHAPE* s;
  MATRIX m;
  ActionTAG*a1,*a2,*a3;
  S32 width = 826, height = 1169;
  
  int f,i,ls1,fs1;
  int count;
  int t;

  memset(&swf,0x00,sizeof(SWF));        // set global movie parameters

  swf.fileVersion    = 4;               // make flash 4 compatible swf
  swf.frameRate      = 0x1900;          // about 0x19 frames per second
  
  swf.movieSize.xmax = 20*width;        // flash units: 1 pixel = 20 units
  swf.movieSize.ymax = 20*height;

  swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
  tag = swf.firstTag;
  rgb.r = 0xff;
  rgb.g = 0xff;
  rgb.b = 0xff;
  swf_SetRGB(tag,&rgb);

  tag = swf_InsertTag(tag,ST_DEFINESPRITE);
  swf_SetU16(tag, 1); //id
  swf_SetU16(tag, 0); //frames
  tag = swf_InsertTag(tag,ST_END);
  tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
  swf_ObjectPlace(tag, 1, 1, 0, 0, "loader");
  
  tag = swf_InsertTag(tag,ST_SHOWFRAME);

    a1 = action_PushFloat(0, 12.0);
    a1 = action_PushString(a1, "");
    a1 = action_GetProperty(a1);
    a1 = action_PushFloat(a1, 2.0);
    a1 = action_Less(a1);
    a1 = action_If(a1, 2);
    a1 = action_GotoFrame(a1, 1);
    a1 = action_End(a1);

    a2 = action_Stop(0);
    a2 = action_End(a2);

  tag = swf_InsertTag(tag,ST_DOACTION);
  swf_ActionSet(tag, a1);
  
  tag = swf_InsertTag(tag,ST_SHOWFRAME);
  
  tag = swf_InsertTag(tag,ST_DOACTION);
  swf_ActionSet(tag, a2);
  
  tag = swf_InsertTag(tag,ST_REMOVEOBJECT2);
  swf_SetU16(tag, 1);

  tag = swf_InsertTag(tag,ST_DEFINESPRITE);
  swf_SetU16(tag, 2); //id
  swf_SetU16(tag, 0); //frames
  tag = swf_InsertTag(tag,ST_END);
  tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
  swf_ObjectPlace(tag, 2, 2, 0, 0, "movie");
  
  tag = swf_InsertTag(tag,ST_SHOWFRAME);
  
  tag = swf_InsertTag(tag,ST_END);

  f = open("PreLoaderTemplate.swf",O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
  if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
  close(f);

  swf_FreeTags(&swf);                       // cleanup

  swf_ActionFree(a1);
  swf_ActionFree(a2);

  return 0;
}