Ejemplo n.º 1
0
/* 
 * Assigns a name to a SWFBlock object.
 * Creates an exportlibrary with named symbols to be imported by other 
 * SWF movies.
 * Call SWFMovie_writeExports() when you're done with the exports
 * to actually write the tag. If you don't the tag will be added
 * at the END of the SWF.
 * see also SWFMovie_importCharacter, SWFMovie_importFont
 */
void
SWFMovie_addExport(SWFMovie movie, SWFBlock block, const char *name)
{
	switch( SWFBlock_getType(block))
	{
		case SWF_DEFINESHAPE:
		case SWF_DEFINESHAPE2:
		case SWF_DEFINESHAPE3:
		case SWF_DEFINESHAPE4:
		case SWF_DEFINEBUTTON:
		case SWF_DEFINEBUTTON2:
		case SWF_DEFINESPRITE:
		case SWF_DEFINEFONT2:
		case SWF_DEFINESOUND:
		case SWF_DEFINELOSSLESS:
		case SWF_DEFINELOSSLESS2:
		case SWF_DEFINEBITS:
		case SWF_DEFINEBITSJPEG2:
		case SWF_DEFINEBITSJPEG3:
			movie->exports = (struct SWFExport_s*)realloc(movie->exports,
					(movie->nExports+1) * sizeof(struct SWFExport_s));
			movie->exports[movie->nExports].block = block;
			movie->exports[movie->nExports].name = strdup(name);
			++movie->nExports;
			break;
		default:
			SWF_error("Exporting a character of type %d is not supported", SWFBlock_getType(block));
			break;
	}
}
Ejemplo n.º 2
0
/*
 * Adds a block to a movie.
 * This function adds a block or character to a movieclip.
 * returns a SWFDisplayItem 
 */
SWFDisplayItem
SWFMovieClip_add(SWFMovieClip clip, SWFBlock block)
{
	if ( SWFBlock_getType(block) == SWF_DEFINEBITS ||
			 SWFBlock_getType(block) == SWF_DEFINEBITSJPEG2 ||
			 SWFBlock_getType(block) == SWF_DEFINEBITSJPEG3 ||
			 SWFBlock_getType(block) == SWF_DEFINELOSSLESS ||
			 SWFBlock_getType(block) == SWF_DEFINELOSSLESS2 )
	{
		block = (SWFBlock)newSWFShapeFromBitmap((SWFBitmap)block, SWFFILL_TILED_BITMAP);
	}

	if ( SWFBlock_isCharacter(block) )
	{
		SWFCharacter_getDependencies((SWFCharacter)block,
																 &CHARACTER(clip)->dependencies,
																 &CHARACTER(clip)->nDependencies);

		SWFCharacter_addDependency((SWFCharacter)clip, (SWFCharacter)block);

		SWFCharacter_setFinished((SWFCharacter)block);

		return SWFDisplayList_add(clip->displayList, clip->blockList, (SWFCharacter)block);
	}
	else
	{
		/* XXX - make sure it's a legit block for a sprite */
		SWFBlockList_addBlock(clip->blockList, block);
	}

	return NULL;
}
Ejemplo n.º 3
0
/*
 * Adds a block to a movie.
 * This function adds a block or character to a movie.
 * Do not use this function. Use SWFMovie_add instead
 * returns a SWFDisplayItem 
 */
SWFDisplayItem
SWFMovie_add_internal(SWFMovie movie /* movie to which the block will be added */,
                      SWFMovieBlockType ublock /* block to add to the movie */)
{
	SWFBlock block = ublock.block;
	if ( block == NULL )
		return NULL;

	/* if they're trying to add a raw bitmap, we'll be nice and turn
		 it into a shape */

	if ( SWFBlock_getType(block) == SWF_DEFINEBITS ||
			 SWFBlock_getType(block) == SWF_DEFINEBITSJPEG2 ||
			 SWFBlock_getType(block) == SWF_DEFINEBITSJPEG3 ||
			 SWFBlock_getType(block) == SWF_DEFINELOSSLESS ||
			 SWFBlock_getType(block) == SWF_DEFINELOSSLESS2 )
	{
		block = (SWFBlock)newSWFShapeFromBitmap((SWFBitmap)block, SWFFILL_TILED_BITMAP);
	}

	/* if it's a text object, we need to translate fonts into font characters */

	if ( SWFBlock_getType(block) == SWF_DEFINETEXT ||
			 SWFBlock_getType(block) == SWF_DEFINETEXT2 )
	{
		SWFMovie_resolveTextFonts(movie, (SWFText)block);
	}

	if ( SWFBlock_getType(block) == SWF_DEFINEEDITTEXT)
	{
		SWFMovie_resolveTextfieldFont(movie, (SWFTextField)block);
	}

	// not nice but has to be done!
	if ( SWFBlock_getType(block) == SWF_INITACTION)
	{
		SWFInitAction init = (SWFInitAction)block;
		SWFMovieClip mc = SWFInitAction_getMovieClip(init);
		if(mc != NULL)
			SWFMovie_addBlock(movie, (SWFBlock)mc);
	} 
	
	if ( SWFBlock_isCharacter(block) )
	{
		
		SWFCharacter_setFinished((SWFCharacter)block);
		SWFMovie_addCharacterDependencies(movie, (SWFCharacter)block);

		return SWFDisplayList_add(movie->displayList, 
			movie->blockList, (SWFCharacter)block);
	}
	else
		SWFMovie_addBlock(movie, block);

	return NULL;
}
Ejemplo n.º 4
0
void
SWFMovie_addBlock(SWFMovie movie, SWFBlock block)
{
	if ( SWFBlock_getType(block) == SWF_SHOWFRAME )
		++movie->nFrames;

	SWFBlockList_addBlock(movie->blockList, block);
}
Ejemplo n.º 5
0
static void
SWFMovie_addDependency(SWFMovie movie, SWFCharacter character)
{
	if ( SWFBlock_getType((SWFBlock)character) == SWF_DEFINETEXT ||
			 SWFBlock_getType((SWFBlock)character) == SWF_DEFINETEXT2 )
	{
		SWFMovie_resolveTextFonts(movie, (SWFText)character);
	}
	else if ( SWFBlock_getType((SWFBlock)character) == SWF_DEFINEEDITTEXT)
	{
		SWFMovie_resolveTextfieldFont(movie, (SWFTextField)character);
	}
	else if ( SWFBlock_getType((SWFBlock)character) == SWF_DEFINEFONT)
	{
		SWFMovie_addCharacterDependencies(movie, character);
	}
	SWFMovie_addBlock(movie, (SWFBlock)character);
}
Ejemplo n.º 6
0
/* 
 * Assigns a name to a SWFBlock object.
 * Creates an exportlibrary with named symbols to be imported by other 
 * SWF movies.
 * Call SWFMovie_writeExports() when you're done with the exports
 * to actually write the tag. If you don't the tag will be added
 * at the END of the SWF.
 * see also SWFMovie_importCharacter, SWFMovie_importFont
 */
void
SWFMovie_addExport(SWFMovie movie, SWFBlock block, const char *name)
{
	switch( SWFBlock_getType(block))
	{
		case SWF_DEFINESHAPE:
		case SWF_DEFINESHAPE2:
		case SWF_DEFINESHAPE3:
			/*SWF_warn("Exporting a shape character is not ensured to work");*/
		case SWF_DEFINESPRITE:
		case SWF_DEFINEFONT2:
			movie->exports = (struct SWFExport_s*)realloc(movie->exports,
					(movie->nExports+1) * sizeof(struct SWFExport_s));
			movie->exports[movie->nExports].block = block;
			movie->exports[movie->nExports].name = strdup(name);
			++movie->nExports;
			break;
		default:
			SWF_error("Exporting a character of type %d is not supported", SWFBlock_getType(block));
			break;
	}
}
Ejemplo n.º 7
0
/* 
 * This function replaces a displayable character with a new one.
 * Do not use this function. Use SWFMovie_replace instead!
 * returns 0 on success 
 */
int
SWFMovie_replace_internal(SWFMovie movie, SWFDisplayItem item, SWFMovieBlockType ublock)
{
	SWFBlock block = ublock.block;
	if(block == NULL || item == NULL)
		return -1;

	if ( SWFBlock_getType(block) == SWF_DEFINEBITS ||
			 SWFBlock_getType(block) == SWF_DEFINEBITSJPEG2 ||
			 SWFBlock_getType(block) == SWF_DEFINEBITSJPEG3 ||
			 SWFBlock_getType(block) == SWF_DEFINELOSSLESS ||
			 SWFBlock_getType(block) == SWF_DEFINELOSSLESS2 )
	{
		block = (SWFBlock)newSWFShapeFromBitmap((SWFBitmap)block, SWFFILL_TILED_BITMAP);
	}

	/* if it's a text object, we need to translate fonts into font characters */

	if ( SWFBlock_getType(block) == SWF_DEFINETEXT ||
			 SWFBlock_getType(block) == SWF_DEFINETEXT2 )
	{
		SWFMovie_resolveTextFonts(movie, (SWFText)block);
	}

	if ( SWFBlock_getType(block) == SWF_DEFINEEDITTEXT)
	{
		SWFMovie_resolveTextfieldFont(movie, (SWFTextField)block);
	}
	
	if ( SWFBlock_isCharacter(block) )
	{
		SWFCharacter_setFinished((SWFCharacter)block);
		SWFMovie_addCharacterDependencies(movie, (SWFCharacter)block);

		SWFDisplayItem_replace(item, (SWFCharacter)block);
		return 0;
	}

	SWF_warn("SWFMovie_replace: only characters can be replaced\n");
	return -1;
}
Ejemplo n.º 8
0
/*
 * Write the EXPORTASSET tag with informations gathered by calls to
 * SWFMovie_addExport.
 *
 * Call this function to control insertion of the EXPORTASSET tag, which
 * is otherwise written at the END of the SWF.
 */
void
SWFMovie_writeExports(SWFMovie movie)
{
	int n;
	SWFBlock exports;

	if ( movie->nExports == 0 )
		return;

	for ( n=0; n<movie->nExports; ++n )
	{
		SWFBlock b = movie->exports[n].block;
		b->swfVersion = movie->version;

		if ( SWFBlock_isCharacter(b) && !SWFBlock_isDefined(b) )
		{
			SWFMovie_addCharacterDependencies(movie, (SWFCharacter)b);
			completeSWFBlock(b);
			SWFMovie_addBlock(movie, b);
			/* Workaround for movieclip exports:
			 * initAction and scalingGrid are only written when 
			 * placing the movieclip. These extra blocks should
			 * not get lost if a MC is eported only 
			 */
			if(SWFBlock_getType(b) == SWF_DEFINESPRITE)
			{
				SWFSprite sprite = (SWFSprite)b;
				if(sprite->grid)
					SWFMovie_addBlock(movie, (SWFBlock)sprite->grid);
				if(sprite->initAction)
					SWFMovie_addBlock(movie, (SWFBlock)sprite->initAction);
			}
		}
	}

	exports = (SWFBlock)newSWFExportBlock(movie->exports, movie->nExports);

	SWFMovie_addBlock(movie, exports);

	destroySWFExports(movie);
}
Ejemplo n.º 9
0
SWFOutput
SWFMovie_toOutput(SWFMovie movie, int level)
{
	int swflength;
#if USE_ZLIB
	int status;
#endif
	SWFOutput header, tempbuffer=0, buffer, swfbuffer;
	SWFBlock lastBlock;
	unsigned long compresslength;

	if ( movie->nExports > 0 )
		SWFMovie_writeExports(movie);

	if ( movie->metadata != NULL)
	{
		SWFMovie_addBlock(movie, (SWFBlock)movie->metadata);
		movie->metadata = NULL; // do not destroy with movie if added as block
	}

	/* Add a terminating SHOWFRAME tag if not already there */
	lastBlock = SWFBlockList_getLastBlock(movie->blockList);
	if ( ! lastBlock || SWFBlock_getType(lastBlock) != SWF_SHOWFRAME )
	{
		SWFMovie_nextFrame(movie);
	}

	while ( movie->nFrames < movie->totalFrames )
		SWFMovie_nextFrame(movie);

	if(movie->symbolClass)
		SWFMovie_addBlock(movie, (SWFBlock)movie->symbolClass);

	if(movie->sceneData)
		SWFMovie_addBlock(movie, (SWFBlock)movie->sceneData);

	SWFMovie_addBlock(movie, newSWFEndBlock());

	// add five for the setbackground block..
	swflength = SWFBlockList_completeBlocks(movie->blockList, movie->version);

	/* XXX - hack */
	SWFDisplayList_rewindSoundStream(movie->displayList);

	header = newSizedSWFOutput(23);

	SWFOutput_writeRect(header, movie->bounds);
	SWFOutput_writeUInt16(header, (int)floor(movie->rate*256));
	SWFOutput_writeUInt16(header, movie->nFrames);

	/* SWF >= 8: first block _must_ be SWF_FILEATTRIBUTES */ 
	if(movie->fattrs)
		writeSWFBlockToMethod((SWFBlock)movie->fattrs, SWFOutputMethod, header);

	if(movie->backgroundBlock)
		writeSWFBlockToMethod(movie->backgroundBlock, SWFOutputMethod, header);
	
	if(movie->limits)
		writeSWFBlockToMethod((SWFBlock)movie->limits, SWFOutputMethod, header);	
	SWFOutput_byteAlign(header);
	swflength += 8 + SWFOutput_getLength(header);

	// compression level check
#if USE_ZLIB
	if (level < -1) level = -1;
	if (level >  9) level = 9;
#else
	if ( level != -1 )
	{
		SWF_warn("No zlib support compiled in, "
			"cannot generate compressed output");
		level = -1; 
	}
#endif

	// reserve output buffer
	if(level >= 0)
	{	// a little bit more than the uncompressed data
		compresslength = swflength + (swflength/1000) + 15 + 1;
		swfbuffer    = newSizedSWFOutput( compresslength + 8 );
	}
	else
		swfbuffer    = newSizedSWFOutput( swflength );

	if (level >= 0) SWFOutput_writeUInt8 (swfbuffer, 'C');
	else SWFOutput_writeUInt8 (swfbuffer, 'F');
	SWFOutput_writeUInt8 (swfbuffer, 'W');
	SWFOutput_writeUInt8 (swfbuffer, 'S');

	SWFOutput_writeUInt8 (swfbuffer, movie->version);

	// Movie length
	SWFOutput_writeUInt32(swfbuffer, swflength);

	if(level >= 0)
		buffer = tempbuffer = newSizedSWFOutput( swflength - 8);
	else
		buffer = swfbuffer;

	SWFOutput_writeToMethod(header, SWFOutputMethod, buffer);

	destroySWFOutput(header);

	// fill swfbuffer with blocklist
	SWFBlockList_writeBlocksToMethod(movie->blockList, SWFOutputMethod, buffer);

#if USE_ZLIB
	if (level >= 0)
	{
		status = compress2 ( (Bytef*) SWFOutput_getBuffer(swfbuffer)+8, &compresslength, SWFOutput_getBuffer(tempbuffer), SWFOutput_getLength(tempbuffer), level);
		if (status == Z_OK) {
			SWFOutput_truncate(swfbuffer, compresslength+8);
			destroySWFOutput(tempbuffer);
		} else SWF_error("compression failed");
	}
#endif // ndef USE_ZLIB
	return swfbuffer;
}