📄 movie.c
字号:
{ 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); } /* 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); return SWFDisplayList_add(movie->displayList, (SWFCharacter)block); } else SWFMovie_addBlock(movie, block); return NULL;}voidSWFMovie_remove(SWFMovie movie , SWFDisplayItem item){ SWFDisplayItem_remove(item);}voidSWFMovie_setSoundStreamAt(SWFMovie movie, SWFSoundStream stream, float skip){ SWFBlock block = SWFSoundStream_getStreamHead(stream, movie->rate, skip); if ( block != NULL ) { SWFMovie_addBlock(movie, block); SWFDisplayList_setSoundStream(movie->displayList, stream); }}voidSWFMovie_setSoundStream(SWFMovie movie, SWFSoundStream stream){ SWFMovie_setSoundStreamAt(movie, stream, 0);}SWFSoundInstanceSWFMovie_startSound(SWFMovie movie, SWFSound sound){ SWFSoundInstance inst = newSWFSoundInstance(sound); if ( !SWFBlock_isDefined((SWFBlock)sound) ) SWFMovie_addBlock(movie, (SWFBlock)sound); SWFMovie_addBlock(movie, (SWFBlock)inst); return inst;}voidSWFMovie_stopSound(SWFMovie movie, SWFSound sound){ SWFSoundInstance inst = newSWFSoundInstance_stop(sound); // XXX - ??? if ( !SWFBlock_isDefined((SWFBlock)sound) ) SWFMovie_addBlock(movie, (SWFBlock)sound); SWFMovie_addBlock(movie, (SWFBlock)inst);}voidSWFMovie_nextFrame(SWFMovie movie){ SWFDisplayList_writeBlocks(movie->displayList, movie->blockList); SWFMovie_addBlock(movie, newSWFShowFrameBlock());}voidSWFMovie_labelFrame(SWFMovie movie, const char *label){ SWFMovie_addBlock(movie, (SWFBlock)newSWFFrameLabelBlock(label));}/* old outputfunction without possible compression *//*intSWFMovie_output(SWFMovie movie, SWFByteOutputMethod method, void *data){ int length; SWFOutput header; SWFBlock backgroundBlock; if ( movie->nExports > 0 ) SWFMovie_writeExports(movie); while ( movie->nFrames < movie->totalFrames ) SWFMovie_nextFrame(movie); SWFMovie_addBlock(movie, newSWFEndBlock()); // add five for the setbackground block.. length = SWFBlockList_completeBlocks(movie->blockList) + 5; //hack SWFDisplayList_rewindSoundStream(movie->displayList); header = newSizedSWFOutput(20); // figure size, write header SWFOutput_writeRect(header, movie->bounds); SWFOutput_writeUInt16(header, (int)floor(movie->rate*256)); SWFOutput_writeUInt16(header, movie->nFrames); SWFOutput_byteAlign(header); length += 8 + SWFOutput_getLength(header); method('F', data); method('W', data); method('S', data); method(movie->version, data); methodWriteUInt32(length, method, data); SWFOutput_writeToMethod(header, method, data); destroySWFOutput(header); backgroundBlock = (SWFBlock)newSWFSetBackgroundBlock(movie->r, movie->g, movie->b); writeSWFBlockToMethod(backgroundBlock, method, data); SWFBlockList_writeBlocksToMethod(movie->blockList, method, data); destroySWFBlock(backgroundBlock); return length;}*/SWFOutputSWFMovie_toOutput(SWFMovie movie, int level){ int swflength, status; SWFOutput header, tempbuffer, buffer, swfbuffer; SWFBlock backgroundBlock; unsigned long compresslength; if ( movie->nExports > 0 ) SWFMovie_writeExports(movie); while ( movie->nFrames < movie->totalFrames ) SWFMovie_nextFrame(movie); SWFMovie_addBlock(movie, newSWFEndBlock()); // add five for the setbackground block.. swflength = SWFBlockList_completeBlocks(movie->blockList); /* 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); backgroundBlock = (SWFBlock)newSWFSetBackgroundBlock(movie->r, movie->g, movie->b); writeSWFBlockToMethod(backgroundBlock, SWFOutputMethod, header); destroySWFBlock(backgroundBlock); SWFOutput_byteAlign(header); swflength += 8 + SWFOutput_getLength(header); // compression level check if (level < -1) level = -1; if (level > 9) level = 9; // 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 (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"); } return swfbuffer;}intSWFMovie_output(SWFMovie movie, SWFByteOutputMethod method, void *data, int level){ SWFOutput swfbuffer = SWFMovie_toOutput(movie, level); int swflength = SWFOutput_getLength(swfbuffer); byte *buffer = SWFOutput_getBuffer(swfbuffer); int n; for(n = 0 ; n < swflength ; n++) method(*buffer++, data); destroySWFOutput(swfbuffer); return swflength;}intSWFMovie_save(SWFMovie movie, const char *filename, int compressionlevel){ FILE *f = fopen(filename, "wb"); int count; if ( f == NULL ) return -1; count = SWFMovie_output(movie, fileOutputMethod, f, compressionlevel); fclose(f); return count;}intcompleteSWFImportCharacter(SWFBlock block){ block->type = SWF_UNUSEDBLOCK; return -2;}SWFImportBlockSWFMovie_addImport(SWFMovie movie, const char *filename, const char *name, int id){ int n; SWFImportBlock imports; struct importitem *ip; char *p; for(n = 0 ; n < movie->nImports ; n++) if(!strcmp(movie->imports[n]->filename, filename)) break; if(n == movie->nImports) { movie->imports = (SWFImportBlock *) realloc(movie->imports, (movie->nImports+1) * sizeof(SWFImportBlock)); movie->imports[movie->nImports++] = newSWFImportBlock(filename); } imports = movie->imports[n]; for(ip = (struct importitem *)&(imports->importlist) ; ip->next ; ) ip = ip->next; ip = ip->next = (struct importitem *)malloc(sizeof(struct importitem)); ip->next = NULL; ip->id = id; ip->name = p = (char *)malloc(strlen(name)+1); while((*p++ = *name++) != 0) ; return movie->imports[n];}SWFCharacterSWFMovie_importCharacter(SWFMovie movie, const char *filename, const char *name){ SWFCharacter res; SWFImportBlock importer; int id; res = (SWFCharacter) malloc(sizeof(struct SWFCharacter_s)); SWFCharacterInit(res); CHARACTERID(res) = id = ++SWF_gNumCharacters; BLOCK(res)->type = SWF_DEFINESPRITE; BLOCK(res)->writeBlock = NULL; BLOCK(res)->complete = completeSWFImportCharacter; BLOCK(res)->dtor = (destroySWFBlockMethod) destroySWFCharacter; importer = SWFMovie_addImport(movie, filename, name, id); SWFCharacter_addDependency(res, (SWFCharacter) importer); return res;}SWFFontCharacterSWFMovie_importFont(SWFMovie movie, const char *filename, const char *name){ SWFFontCharacter res; SWFImportBlock importer; int id; res = newSWFDummyFontCharacter(); id = CHARACTERID(res); importer = SWFMovie_addImport(movie, filename, name, id); SWFCharacter_addDependency((SWFCharacter) res, (SWFCharacter) importer); return res;}/* * Local variables: * tab-width: 2 * c-basic-offset: 2 * End: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -