📄 script.cc
字号:
} font->setFontLookUpTable(lut); delete offsetTable; addCharacter(font); // This is an incomplete parsing return;memory_error: outOfMemory = 1; if (font) delete font; if (offsetTable) delete offsetTable; if (lut) delete lut; if (shapes) delete[] shapes;}TextRecord * CInputScript::ParseTextRecord(int hasAlpha){ TextRecord *tr; TextFlags flags; flags = (TextFlags) GetByte(); if (flags == 0) return 0; tr = new TextRecord; if (tr == NULL) { outOfMemory = 1; return 0; } tr->flags = flags; if (flags & isTextControl) { if (flags & textHasFont) { long fontId; fontId = GetWord(); tr->font = (SwfFont *)getCharacter(fontId); } if (flags & textHasColor) { tr->color.red = GetByte(); tr->color.green = GetByte(); tr->color.blue = GetByte(); if (hasAlpha) { tr->color.alpha = GetByte(); } else { tr->color.alpha = ALPHA_OPAQUE; } } if (flags & textHasXOffset) { tr->xOffset = GetWord(); } if (flags & textHasYOffset) { tr->yOffset = GetWord(); } if (flags & textHasFont) { tr->fontHeight = GetWord(); } tr->nbGlyphs = GetByte(); } else { tr->flags = (TextFlags)0; tr->nbGlyphs = (long)flags; } tr->glyphs = new Glyph[ tr->nbGlyphs ]; if (tr->glyphs == NULL) { outOfMemory = 1; delete tr; return 0; } InitBits(); for (int g = 0; g < tr->nbGlyphs; g++) { tr->glyphs[g].index = GetBits(m_nGlyphBits); tr->glyphs[g].xAdvance = GetBits(m_nAdvanceBits); } return tr;}void CInputScript::ParseDefineText(int hasAlpha){ Text *text; TextRecord *textRecord; Matrix m; Rect rect; U32 tagid = (U32) GetWord(); text = new Text(tagid); if (text == NULL) { outOfMemory = 1; return; } GetRect(&rect); text->setTextBoundary(rect); GetMatrix(&m); text->setTextMatrix(m); m_nGlyphBits = GetByte(); m_nAdvanceBits = GetByte(); do { textRecord = ParseTextRecord(hasAlpha); if (textRecord) { text->addTextRecord( textRecord ); } if (outOfMemory) { delete text; return; } if (m_filePos >= m_tagEnd) break; } while (textRecord); addCharacter(text);}void CInputScript::ParseDefineSound(){ Sound *sound; U32 tagid = (U32) GetWord(); long nbSamples; long flags; char *buffer; sound = new Sound(tagid); flags = GetByte(); sound->setSoundFlags(flags); nbSamples = GetDWord(); buffer = sound->setNbSamples(nbSamples); if (buffer == NULL) { outOfMemory = 1; delete sound; return; } switch (flags & soundFormatMask) { case soundFormatADPCMCompressed: Adpcm *adpcm; adpcm = new Adpcm( &m_fileBuf[m_filePos] , flags & soundIsStereo ); adpcm->Decompress((short *)buffer, nbSamples); delete adpcm; break; case soundFormatRaw: memcpy(buffer, &m_fileBuf[m_filePos], m_tagLen-5); break; case soundFormatMP3Compressed: Mp3 *mp3; int delay; delay = GetWord(); mp3 = new Mp3( &m_fileBuf[m_filePos], m_tagEnd-m_filePos, flags ); mp3->Decompress((short*)buffer, nbSamples); delete mp3; break; default: fprintf(stderr, "unknown sound format %lx\n", flags); memset(buffer, 0, nbSamples); break; } addCharacter(sound);}void CInputScript::ParseDefineButtonSound(){ U32 tagid = (U32) GetWord(); Button *button; tagid = tagid; printf("tagDefineButtonSound \ttagid %-5u\n", tagid); button = (Button *)getCharacter(tagid); if (button == 0) { printf(" Couldn't find Button id %d\n", tagid); return; } // step through for button states for (int i = 0; i < 4; i++) { Sound *sound; U32 soundTag = GetWord(); sound = (Sound *)getCharacter(soundTag); if (sound) { if (sound->getType() != SoundType) { printf(" Sound id %d not a sound (type is %d)\n", (int)soundTag, sound->getType()); } else { button->setButtonSound(sound,i); } } else if (soundTag) { printf(" Couldn't find Sound id %d\n", soundTag); } switch (i) { case 0: printf("upState \ttagid %-5u\n", soundTag); break; case 1: printf("overState \ttagid %-5u\n", soundTag); break; case 2: printf("downState \ttagid %-5u\n", soundTag); break; } if (soundTag) { U32 code = GetByte(); printf("sound code %u", code); if ( code & soundHasInPoint ) printf(" inpoint %u", GetDWord()); if ( code & soundHasOutPoint ) printf(" outpoint %u", GetDWord()); if ( code & soundHasLoops ) printf(" loops %u", GetWord()); printf("\n"); if ( code & soundHasEnvelope ) { int points = GetByte(); for ( int p = 0; p < points; p++ ) { printf("\n"); printf("mark44 %u", GetDWord()); printf(" left chanel %u", GetWord()); printf(" right chanel %u", GetWord()); printf("\n"); } } } if (m_filePos == m_tagEnd) break; }}void CInputScript::ParseSoundStreamHead(){ int mixFormat = GetByte(); // The stream settings int format = GetByte(); int nSamples = GetWord(); mixFormat = mixFormat; format = format; nSamples = nSamples; printf("tagSoundStreamHead \tmixFrmt %-3u frmt %-3u nSamples %-5u\n", mixFormat, format, nSamples);}void CInputScript::ParseSoundStreamHead2(){ int mixFormat = GetByte(); // The stream settings int format = GetByte(); int nSamples = GetWord(); mixFormat = mixFormat; format = format; nSamples = nSamples; //printf("tagSoundStreamHead2 \tmixFormat %-3u format %-3u nSamples %-5u\n", mixFormat, format, nSamples);}void CInputScript::ParseSoundStreamBlock(){ printf("tagSoundStreamBlock\n");}void CInputScript::ParseDefineButtonCxform(){ ButtonRecord *br; Button *button; U32 tagid = (U32) GetWord(); button = (Button *)getCharacter(tagid); for (br = button->getButtonRecords(); br; br = br->next) { br->cxform = new Cxform; GetCxform(br->cxform, false); }}void CInputScript::ParseNameCharacter(){ U32 tagid = (U32) GetWord(); char *label = strdup(GetString()); nameCharacter(tagid, label);}void CInputScript::ParseFrameLabel(){ char *label = strdup(GetString()); program->setCurrentFrameLabel(label);}void CInputScript::ParseDefineMouseTarget(){ printf("tagDefineMouseTarget\n");}void CInputScript::ParseDefineSprite(){ Sprite *sprite; Program *prg; int status; U32 tagid = (U32) GetWord(); U32 frameCount = (U32) GetWord(); if (frameCount == 0) return; printf("tagDefineSprite \ttagid %-5u \tframe count %-5u\n", tagid, frameCount); sprite = new Sprite(program->movie, tagid, frameCount); if (sprite == NULL) { outOfMemory = 1; return; } if (sprite->getProgram() == NULL) { delete sprite; outOfMemory = 1; return; } prg = sprite->getProgram(); // Set current program program = prg; ParseTags(&status); if (outOfMemory) { delete sprite; return; } addCharacter(sprite);}void CInputScript::ParseUnknown(long code, long len){ printf("Unknown Tag : %d - Length = %d\n", code, len);}voidCInputScript::ParseTags(int *status) // Parses the tags within the file.{ // Initialize the end of frame flag. BOOL atEnd = false; // Loop through each tag. while (!atEnd) { U32 here; // Get the current tag. U16 code = GetTag(); if (code == notEnoughData) { m_filePos = m_tagStart; *status |= FLASH_PARSE_NEED_DATA; return; } //printf("Code %d, tagLen %8u \n", code, m_tagLen); here = m_filePos; // Get the tag ending position. U32 tagEnd = m_tagEnd; if (m_tagEnd > m_actualSize) { m_filePos = m_tagStart; *status |= FLASH_PARSE_NEED_DATA; return; } switch (code) { case stagProtect: break; case stagEnd: // We reached the end of the file. atEnd = true; printf("End of Movie\n"); break; case stagShowFrame: // Validate frame program->validateLoadingFrame(); *status |= FLASH_PARSE_WAKEUP; break; case stagFreeCharacter: ParseFreeCharacter(); break; case stagPlaceObject: ParsePlaceObject(); break; case stagPlaceObject2: ParsePlaceObject2(); break; case stagRemoveObject: ParseRemoveObject(); break; case stagRemoveObject2: ParseRemoveObject2(); break; case stagSetBackgroundColor: ParseSetBackgroundColor(); break; case stagDoAction: ParseDoAction(); break; case stagStartSound: ParseStartSound(); break; case stagStopSound: ParseStopSound(); break; case stagDefineShape: ParseDefineShape(1); break; case stagDefineShape2: ParseDefineShape(2); break; case stagDefineShape3: ParseDefineShape(3); break; case stagDefineBits: ParseDefineBits(); break; case stagDefineBitsJPEG2: ParseDefineBitsJPEG2(); break; case stagDefineBitsJPEG3: ParseDefineBitsJPEG3(); break; case stagDefineBitsLossless: ParseDefineBitsLossless(1); break; case stagDefineBitsLossless2: ParseDefineBitsLossless(2); break; case stagJPEGTables: ParseJPEGTables(); break; case stagDefineButton: ParseDefineButton(); break; case stagDefineButton2: ParseDefineButton2(); break; case stagDefineFont: ParseDefineFont(); break; case stagDefineMorphShape: ParseDefineMorphShape(); break; case stagDefineFontInfo: ParseDefineFontInfo(); break; case stagDefineText: ParseDefineText(0); break; case stagDefineText2: ParseDefineText(1); break; case stagDefineSound: ParseDefineSound(); break; case stagDefineButtonSound: ParseDefineButtonSound(); break; case stagSoundStreamHead: ParseSoundStreamHead(); break; case stagSoundStreamHead2: ParseSoundStreamHead2(); break; case stagSoundStreamBlock: ParseSoundStreamBlock(); break; case stagDefineButtonCxform: ParseDefineButtonCxform(); break; case stagDefineSprite: Program *save; save = program; ParseDefineSprite(); program->rewindMovie(); program = save; break; case stagNameCharacter: ParseNameCharacter(); break; case stagFrameLabel: ParseFrameLabel(); break; case stagDefineFont2: ParseDefineFont2(); break; default: ParseUnknown(code, m_tagLen); break; } //printf("Bytes read = %d\n", m_filePos-here); // Increment the past the tag. m_filePos = tagEnd; if (outOfMemory) { fprintf(stderr,"Flash: Out of memory\n"); *status |= FLASH_PARSE_OOM; return; } } program->validateLoadingFrame(); *status |= FLASH_PARSE_EOM;}intCInputScript::ParseData(FlashMovie *movie, char * data, long size){ int status = FLASH_PARSE_ERROR; m_fileBuf = (unsigned char *)data; m_actualSize = size; if (needHeader) { // Do we have sufficient data to read the header ? if (size < 21) { return FLASH_PARSE_NEED_DATA; // No, need more data } needHeader = 0; // Yes U8 fileHdr[8]; memcpy(fileHdr,data,8); // Verify the header and get the file size. if (fileHdr[0] != 'F' || fileHdr[1] != 'W' || fileHdr[2] != 'S' ) { //fprintf(stderr, "Not a Flash File.\n"); return FLASH_PARSE_ERROR; // Error } else { // Get the file version. m_fileVersion = (U16) fileHdr[3]; } // Get the file size. m_fileSize = (U32) fileHdr[4] | ((U32) fileHdr[5] << 8) | ((U32) fileHdr[6] << 16) | ((U32) fileHdr[7] << 24); // Verify the minimum length of a Flash file. if (m_fileSize < 21) { //printf("ERROR: File size is too short\n"); return FLASH_PARSE_ERROR; // Error } // Set the file position past the header and size information. m_filePos = 8; // Get the frame information. GetRect(&frameRect); frameRate = GetWord() >> 8; frameCount = GetWord(); program = new Program(movie, frameCount); if (program == NULL || program->totalFrames == 0) { return FLASH_PARSE_ERROR; } status |= FLASH_PARSE_START; } ParseTags(&status); return status;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -