示例#1
0
void
outputTrailer (struct Movie *m)
{
SWFOutput out;

out=newSizedSWFOutput(30);
SWFOutput_writeUInt8(out,'F');
SWFOutput_writeUInt8(out,'W');
SWFOutput_writeUInt8(out,'S');
SWFOutput_writeUInt8(out,4);
SWFOutput_writeUInt32(out,SWFOutput_getLength(swfout)+23 /*size of header*/);
SWFOutput_writeBits(out,15,5);
SWFOutput_writeSBits(out,m->frame.xMin,15);
SWFOutput_writeSBits(out,m->frame.xMax,15);
SWFOutput_writeSBits(out,m->frame.yMin,15);
SWFOutput_writeSBits(out,m->frame.yMax,15);
SWFOutput_byteAlign(out);
SWFOutput_writeUInt16(out,m->rate);
SWFOutput_writeUInt16(out,m->nFrames);

/* Add the SWF_END tag */
SWFOutput_writeUInt16(swfout,0);

SWFOutput_writeToMethod(out,fileOutputMethod,stdout);
SWFOutput_writeToMethod(swfout,fileOutputMethod,stdout);
destroySWFOutput(swfout);
destroySWFOutput(out);
}
示例#2
0
文件: text.c 项目: akleine/libming
static void
writeSWFTextToMethod(SWFBlock block, SWFByteOutputMethod method, void *data)
{
	SWFText text = (SWFText)block;
	int length = 0;
	SWFOutput out;

	if ( text->matrix == NULL )
		text->matrix = newSWFMatrix(1.0, 0, 0, 1.0, 0, 0);

	length += (SWFMatrix_numBits(text->matrix)+7)/8;
	length += (SWFRect_numBits(CHARACTER(text)->bounds)+7)/8;
	length += 4;

	out = newSizedSWFOutput(length);

	SWFOutput_writeUInt16(out, CHARACTERID(text));
	SWFOutput_writeRect(out, CHARACTER(text)->bounds);
	SWFOutput_writeMatrix(out, text->matrix);
	SWFOutput_writeUInt8(out, text->nGlyphBits);
	SWFOutput_writeUInt8(out, text->nAdvanceBits);

	SWFOutput_writeToMethod(out, method, data);
	SWFOutput_writeToMethod(text->out, method, data);

	destroySWFOutput(out);
}
示例#3
0
文件: placeobject.c 项目: cran/R2SWF
void
destroySWFPlaceObject2Block(SWFPlaceObject2Block place)
{
	if ( place->actions != NULL )
		free(place->actions);

	if ( place->actionFlags != NULL )
/*	{	free(place->actionChars);	*/
		free(place->actionFlags);
/*	}	*/

	if( place->filterList != NULL )
		destroySWFFilterList(place->filterList);		

	if ( place->name != NULL )
		free(place->name);

	if ( place->out != NULL )
		destroySWFOutput(place->out);

	if ( place->matrix != NULL )
		destroySWFMatrix(place->matrix);

	if ( place->cXform != NULL )
		destroySWFCXform(place->cXform);

#if TRACK_ALLOCS
	ming_gc_remove_node(place->gcnode);
#endif

	free(place);
}
示例#4
0
文件: browserfont.c 项目: cran/R2SWF
/**
 * destroys a SWFBrowserFont instance.
 */
void
destroySWFBrowserFont(SWFBrowserFont font)
{
	destroySWFOutput(font->out);
	free(font->name);
	free(font);
}
示例#5
0
void
destroySWFProtect(SWFProtect protect)
{
    if( protect->out )
        destroySWFOutput(protect->out );
    if( protect->Password )
        free(protect->Password);
}
示例#6
0
void
destroySWFTextField(SWFTextField field)
{
	destroySWFOutput(field->out);

	if ( field->varName != NULL )
		free(field->varName);

	if ( field->string != NULL )
		free(field->string);

	if ( field->embeds != NULL )
		free(field->embeds);

	destroySWFCharacter((SWFCharacter) field);
}
示例#7
0
/*
 * Oputput a movie with SWFByteOutputMethod
 * returns the number of bytes written.
 */
int
SWFMovie_output(SWFMovie movie, SWFByteOutputMethod method, void *data)
{
	SWFOutput swfbuffer;
	int swflength;
	byte *buffer;
	int n;
	int level = SWF_compression;

	swfbuffer = SWFMovie_toOutput(movie, level);
	swflength = SWFOutput_getLength(swfbuffer);
	buffer = SWFOutput_getBuffer(swfbuffer);
	
	for(n = 0 ; n < swflength ; n++)
		method(*buffer++, data);
	destroySWFOutput(swfbuffer);
	return swflength;
}
示例#8
0
void
destroySWFShape(SWFShape shape)
{
    int i;
    if(shape->fills != NULL)
    {
        // Fills have to be destroyed by users.
        /*
        for ( i=0; i<shape->nFills; ++i )
        	destroySWFFillStyle(shape->fills[i]);
        */
        free(shape->fills);
    }
    if(shape->records != NULL)
    {
        for(i = 0; i < shape->nRecords; i++)
        {
            free(shape->records[i].record.stateChange);
        }
        free(shape->records);
    }

    if(shape->edgeBounds != NULL)
        free(shape->edgeBounds);

    for ( i=0; i<shape->nLines; ++i )
        free(shape->lines[i]);

    if ( shape->lines != NULL )
        free(shape->lines);

    destroySWFOutput(shape->out);

#if TRACK_ALLOCS
    ming_gc_remove_node(shape->gcnode);
#endif

    destroySWFCharacter((SWFCharacter) shape);
}
示例#9
0
void
outputBlock (int type, SWF_Parserstruct * blockp, FILE* stream)
{
  SWFOutput blkout;
  int i;

  if (type < 0)
    return;

  outf = stream;

  for (i = 0; i < numOutputs; i++)
    {
      if (outputs[i].type == type)
	{
	  blkout=outputs[i].output (blockp);
	  SWFOutput_writeToMethod(blkout,SWFOutputMethod,swfout);
	  destroySWFOutput(blkout);
	}
    }
  return;
}
示例#10
0
文件: text.c 项目: akleine/libming
void
destroySWFText(SWFText text)
{
	SWFTextRecord record = text->initialRecord, next;

	destroySWFOutput(text->out);

	if ( text->matrix != NULL )
		destroySWFMatrix(text->matrix);

	while ( record != NULL )
	{
		next = record->next;
		destroySWFTextRecord(record);
		record = next;
	}

#if TRACK_ALLOCS
	ming_gc_remove_node(text->gcnode);
#endif

	destroySWFCharacter((SWFCharacter) text);
}
示例#11
0
文件: shape.c 项目: tkhaga/MingHSP
void
destroySWFShape(SWFShape shape)
{
	int i, j;

	destroySWFOutput(shape->out);

	if (shape->isUsingNewStyles != TRUE) {
		for ( i=0; i<*shape->nFills; ++i )
		{
			SWFMatrix matrix = SWFFillStyle_getMatrix((*shape->fills)[i]);

			if ( matrix != NULL )
				destroySWFMatrix(matrix);

			/* gradients and bitmaps are destroyed separately */

			free((*shape->fills)[i]);
		}

		if ( *shape->fills != NULL )
			free(*shape->fills);

		for ( i=0; i<*shape->nLines; ++i )
			free((*shape->lines)[i]);

		if ( *shape->lines != NULL )
			free(*shape->lines);
	}

	if (shape->isEnded != TRUE) {
		for ( i=0; i<shape->nRecords; ++i )
		{
			ShapeRecord record = shape->records[i];

			if (record.type == SHAPERECORD_STATECHANGE &&
				 record.record.stateChange->flags & SWF_SHAPE_NEWSTYLEFLAG)
			{
				for ( j=0; i<record.record.stateChange->nFills; ++j )
				{
					SWFMatrix matrix = SWFFillStyle_getMatrix(record.record.stateChange->fills[j]);

					if ( matrix != NULL )
						destroySWFMatrix(matrix);

					/* gradients and bitmaps are destroyed separately */

					free(record.record.stateChange->fills[j]);
				}

				if ( record.record.stateChange->fills != NULL )
					free(record.record.stateChange->fills);

				for ( j=0; j<record.record.stateChange->nLines; ++j )
					free(record.record.stateChange->lines[j]);

				if ( record.record.stateChange->lines != NULL )
					free(record.record.stateChange->lines);
			}

			free(record.record.stateChange); /* all in union are pointers */
		}

		free(shape->records);
	}

#if TRACK_ALLOCS
	ming_gc_remove_node(shape->gcnode);
#endif

	destroySWFCharacter((SWFCharacter) shape);
}
示例#12
0
SWFOutput
outputSWF_DEFINEFONT2 (SWF_Parserstruct * pblock)
{
  SWFOutput hdr0,hdr1,offsettbl,*glyphdata;
  int i,size, glyphbase;
  OUT_BEGIN (SWF_DEFINEFONT2);


  glyphdata = calloc(sblock->NumGlyphs,sizeof(SWFOutput *));
  size=0;
  for (i = 0; i < sblock->NumGlyphs; i++) {
	glyphdata[i] = outputswfSWF_SHAPE (&(sblock->GlyphShapeTable[i]));
	size+= SWFOutput_getLength(glyphdata[i]);
    }

  if( size > 0xffff ) 
    sblock->FontFlagsWideOffsets=1;

  if (sblock->FontFlagsWideOffsets) {
    glyphbase=(sblock->NumGlyphs*4)+4;
    sblock->CodeTableOffset.UI32=glyphbase;
    sblock->OffsetTable.UI32[0]=glyphbase;
  } else {
    glyphbase=(sblock->NumGlyphs*2)+2;
    sblock->CodeTableOffset.UI16=glyphbase;
    sblock->OffsetTable.UI16[0]=glyphbase;
    }

  for (i = 0; i < sblock->NumGlyphs; i++) {
        if (sblock->FontFlagsWideOffsets) {
          sblock->OffsetTable.UI32[i]=sblock->CodeTableOffset.UI32;
	  sblock->CodeTableOffset.UI32=sblock->OffsetTable.UI32[i]+SWFOutput_getLength(glyphdata[i]);
	} else {
          sblock->OffsetTable.UI16[i]=sblock->CodeTableOffset.UI16;
	  sblock->CodeTableOffset.UI16=sblock->OffsetTable.UI16[i]+SWFOutput_getLength(glyphdata[i]);
	}
    }

  offsettbl=newSWFOutput();
  for (i = 0; i < sblock->NumGlyphs; i++) {
      if (sblock->FontFlagsWideOffsets) {
	SWFOutput_writeUInt32(offsettbl,sblock->OffsetTable.UI32[i]);
      } else {
	SWFOutput_writeUInt16(offsettbl,sblock->OffsetTable.UI16[i]);
	}
    }

  /* Now that we have the glyph data, and it's offset, we can start assembling
     this block */

  size=	5		/* Initial header through FontNameLen */
	+(sblock->FontNameLen)	/* FontName */
	+2;		/* NumGlyphs */

  hdr1=newSizedSWFOutput(size);
  SWFOutput_writeUInt16(hdr1,sblock->FontID);
  SWFOutput_writeBits(hdr1,sblock->FontFlagsHasLayout,1);
  SWFOutput_writeBits(hdr1,sblock->FontFlagsShiftJis,1);
  SWFOutput_writeBits(hdr1,sblock->FontFlagsSmallText,1);
  SWFOutput_writeBits(hdr1,sblock->FontFlagsFlagANSI,1);
  SWFOutput_writeBits(hdr1,sblock->FontFlagsWideOffsets,1);
  SWFOutput_writeBits(hdr1,sblock->FontFlagsWideCodes,1);
  SWFOutput_writeBits(hdr1,sblock->FontFlagsFlagsItalics,1);
  SWFOutput_writeBits(hdr1,sblock->FontFlagsFlagsBold,1);
  SWFOutput_writeUInt8(hdr1,sblock->LanguageCode);
  SWFOutput_writeUInt8(hdr1,sblock->FontNameLen);
  SWFOutput_writeBuffer(hdr1,(unsigned char *)sblock->FontName,sblock->FontNameLen);
  SWFOutput_writeUInt16(hdr1,sblock->NumGlyphs);

  /* Now, copy these parts into the hdr buffer */
  SWFOutput_writeToMethod(offsettbl,SWFOutputMethod,hdr1);
  destroySWFOutput(offsettbl);
  if (sblock->FontFlagsWideOffsets)
    {
	SWFOutput_writeUInt32(hdr1,sblock->CodeTableOffset.UI32);
    }
  else
    {
	SWFOutput_writeUInt16(hdr1,sblock->CodeTableOffset.UI16);
    }
  for (i = 0; i < sblock->NumGlyphs; i++) {
    SWFOutput_writeToMethod(glyphdata[i],SWFOutputMethod,hdr1);
    destroySWFOutput(glyphdata[i]);
  }
  free(glyphdata);

  /* Now, resume the normal linear processing this tag */

  for (i = 0; i < sblock->NumGlyphs; i++)
    {
	if( sblock->FontFlagsWideCodes ) {
	  SWFOutput_writeUInt16(hdr1,sblock->CodeTable[i]);
	} else {
	  SWFOutput_writeUInt8(hdr1,sblock->CodeTable[i]);
	}
    }

  if( sblock->FontFlagsHasLayout ) {
    SWFOutput_writeSInt16(hdr1,sblock->FontAscent);
    SWFOutput_writeSInt16(hdr1,sblock->FontDecent);
    SWFOutput_writeSInt16(hdr1,sblock->FontLeading);
    for (i = 0; i < sblock->NumGlyphs; i++) {
      SWFOutput_writeSInt16(hdr1,sblock->FontAdvanceTable[i]);
      }
    for (i = 0; i < sblock->NumGlyphs; i++) {
	outputswfSWF_RECT (hdr1,&(sblock->FontBoundsTable[i]));
        SWFOutput_byteAlign(hdr1);
      }
    SWFOutput_writeUInt16(hdr1,sblock->KerningCount);
    for (i = 0; i < sblock->KerningCount; i++) {
      if( sblock->FontFlagsWideCodes ) {
      	SWFOutput_writeUInt16(hdr1,sblock->FontKerningTable[i].FontKerningCode1);
      	SWFOutput_writeUInt16(hdr1,sblock->FontKerningTable[i].FontKerningCode2);
      	SWFOutput_writeSInt16(hdr1,sblock->FontKerningTable[i].FontKerningAdjustment);
      } else {
      	SWFOutput_writeUInt8(hdr1,sblock->FontKerningTable[i].FontKerningCode1);
      	SWFOutput_writeUInt8(hdr1,sblock->FontKerningTable[i].FontKerningCode2);
      	SWFOutput_writeSInt16(hdr1,sblock->FontKerningTable[i].FontKerningAdjustment);
      }
    }
  }

/* This code really belongs in outputTAGHeader() */
hdr0=newSizedSWFOutput(6);

if(SWFOutput_getLength(hdr1) <= 62 ) {
	fprintf(stderr,"TAG %x\n",(SWF_DEFINEFONT2<<6)|SWFOutput_getLength(hdr1));
	SWFOutput_writeUInt16(hdr0,(SWF_DEFINEFONT2<<6)|SWFOutput_getLength(hdr1));
} else {
	SWFOutput_writeUInt16(hdr0,(SWF_DEFINEFONT2<<6)|0x3f);
	SWFOutput_writeUInt32(hdr0,SWFOutput_getLength(hdr1));
}

SWFOutput_writeToMethod(hdr1,SWFOutputMethod,hdr0);
destroySWFOutput(hdr1);

return hdr0;
}
示例#13
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;
}
示例#14
0
/*
 * destroys a SWFPrebuiltClip instance
 */
void
destroySWFPrebuiltClip(SWFPrebuiltClip clip)
{	destroySWFOutput(clip->display);
	destroySWFCharacter((SWFCharacter) clip);
}
示例#15
0
void
destroySWFPrebuilt(SWFPrebuilt defines)
{	destroySWFOutput(defines->defines);
	free((SWFBlock) defines);
}