Exemple #1
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;
}
Exemple #2
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;
}