/** * saveMovie is used to encode the objects and write them to the specified Flash file. * This method is used a simple wrapper for the FSMovie object's encodeToFile() method * so any excptions thrown when encoding the file can be handled without making the * code to generate the movie look any more complicated than necessary. * * @param the full path to the file. */ void saveMovie(FSMovie& movie, string path, string filename) { #ifdef WIN32 char separator = '\\'; #else char separator = '/'; #endif string filepath(filename); if (path.length() > 0) filepath = path + separator + filepath; try { movie.encodeToFile(filepath.c_str()); } catch (FSException e) { /* * Several exceptions could be thrown to get to this point. FSMovie will * throw an FSFileOpenException, FSAccessException or FSFormatException * if the file cannot be opened for writing, an error occurs while writing * to the file or if an error occurs while encoding the Flash data, respectively. * * All the exceptions thrown contain a message which describes why the * exception was thrown so handling them all in the same way is sufficient * for the purposes of the examples. */ cerr << e.what(); } }
StreamingSounds(int argc, const char * argv[]) : UnitTest(argc, argv) { vector<string> files; string dirIn = stringOption(options, "dirIn"); string dirOut = stringOption(options, "dirOut"); string extension = stringOption(options, "ext"); string fileIn = ""; string fileOut = ""; findFiles(dirIn, files, extension); for (vector<string>::iterator i = files.begin(); i != files.end(); ++i) { fileIn = *i; fileOut = fileIn.substr(0, fileIn.find_first_of('.')) + ".swf"; cout << fileIn << endl; #ifdef WIN32 fileOut = dirOut + "\\" + fileOut; #else fileOut = dirOut + "/" + fileOut; #endif try { FSMovie movie; FSSoundConstructor* soundGenerator = SoundConstructor(); if (soundGenerator->setSoundFromFile(fileIn.c_str()) != TransformUtil::OK) { throw FSException("Could not load sound file"); } float framesPerSecond = 12.0f; movie.setFrameSize(FSBounds(0, 0, 8000, 4000)); movie.setFrameRate(framesPerSecond); movie.add(new FSSetBackgroundColor(FSColorTable::lightblue())); /* * Calculate the time it takes to play the sound and the number of frames this * represents. */ float duration = ((float) soundGenerator->getSamplesPerChannel()) / ((float) soundGenerator->getSampleRate()); int numberOfFrames = (int) (duration * framesPerSecond); /* * Play the Streaming Sound. * * Calculate the number of decoded sound samples played for each frame and * the size, in bytes, of each block compressed sound data. */ int samplesPerBlock = soundGenerator->getSampleRate() / (int) framesPerSecond; int numberOfBlocks = soundGenerator->getSamplesPerChannel() / samplesPerBlock; /* * An FSSoundStreamHeader2 object defines the attributes of the streaming sound. */ movie.add(soundGenerator->streamHeader(samplesPerBlock)); /* * Add a streaming block for each frame so the sound is played as each frame * is displayed. */ for (int i=0; i<numberOfBlocks; i++) { movie.add(soundGenerator->streamBlock(i, samplesPerBlock)); movie.add(new FSShowFrame()); } movie.encodeToFile(fileOut.c_str()); delete soundGenerator; } catch (FSException e) { cerr << e.what(); } } }
/*! \fn F4lmDoc::slotfileExportMovie() */ void F4lmDoc::slotfileExportMovie() { F4lmView *view=pViewList->first(); CListViewItem *tmpListViewItem=(CListViewItem*)view->dad->tl->timeLineListbox->selectedItem(); int animX=view->dad->tl->layerFrames->at(tmpListViewItem->m_Row-1)->frames->last ()->tableItemNo; int z=-1*tmpListViewItem->m_Row; int xLower = 000; int yLower = 000; int xUpper = view->defSceneRect.x()*2+600; int yUpper = view->defSceneRect.y()*2+600; FSMovie movie; movie.setFrameSize(FSBounds(xLower, yLower, xUpper, yUpper)); /* * Set the frame rate at which the movie will be played. */ float framesPerSecond = 25.0f; movie.setFrameRate(framesPerSecond); /* * Set the movie's background colour to light blue. The background colour * only be set once and should be the first object added to a movie. If no * background colour is specified then the Flash Player will set it to white. */ /// TODO:defscenerect should be color here. movie.add(new FSSetBackgroundColor(FSColorTable::white())); for(int i=0;i<=view->dad->tl->layerMaxColNum;i++) { Q3CanvasItemList l=view->mainCanvas->allItems(); for (Q3CanvasItemList::Iterator it = l.begin (); it != l.end ();++it) { if ((*it)->rtti () == 666 || (*it)->rtti () == 667) { //should not be output object types. continue; } switch((*it)->rtti()) { case Q3CanvasItem::Rtti_Ellipse: { CCanvasEllipse *oval=(CCanvasEllipse*)(*it); if(oval->animationX>=i)continue; FSShapeConstructor* path = ShapeConstructor(); //buundan circle cikar //path->COORDINATES_ARE_PIXELS = true; int width = oval->width(); int height = oval->height(); int identifier = movie.newIdentifier(); QColor PenColor=oval->pen().color(); QColor BrushColor=oval->brush().color(); FSSolidLine* lineStyle = new FSSolidLine(1, FSColor(PenColor.red(),PenColor.green(),PenColor.blue())); FSSolidFill* fillStyle =new FSSolidFill(FSColor(BrushColor.red(),BrushColor.green(),BrushColor.blue())); path->addLineStyle(lineStyle); path->addFillStyle(fillStyle); //delete lineStyle; //delete fillStyle; //path->newPath(); // start a new path //path->selectStyle(1, 1); // select the first line and fill style objects //path->move(-width/2, -height/2); //path->closePath(); path->ellipse(-width/2, -height/2, width/2, height/2); movie.add(path->defineShape(identifier)); movie.add(new FSPlaceObject(identifier, oval->Row, oval->x(), oval->y())); movie.add(new FSShowFrame()); } break; case Q3CanvasItem::Rtti_Line: { CCanvasLine *line=(CCanvasLine*)(*it); //qDebug("frame %d",i); if(line->animationX>=i)continue; int identifier = movie.newIdentifier(); int width = (line->startPoint().x()-line->endPoint().x()); int height = (line->startPoint().y()-line->endPoint().y()); //qDebug("startX: %d height: %d",line->startPoint().x(),line->endPoint().x()); FSBounds bounds(-width, -height, width, height); //qDebug("width: %d height: %d",width,height); FSVector<FSLineStyle*> lineStyles(1); FSVector<FSFillStyle*> fillStyles(1); QColor PenColor=line->pen().color(); QColor BrushColor=line->brush().color(); //qDebug("renk ismi %d %d %d",BrushColor.red(),BrushColor.green(),BrushColor.blue()); lineStyles[0] = new FSSolidLine(1, FSColor(PenColor.red(),PenColor.green(),PenColor.blue())); fillStyles[0] = new FSSolidFill( FSColor(BrushColor.red(),BrushColor.green(),BrushColor.blue())); FSShape shape; shape.add(new FSShapeStyle(1, 1, 0,-width/2,-height/2)); //shape.add(new FSShapeStyle(line->startPoint().x(), line->startPoint().y())); //shape.add(new FSLine(line->startPoint().x(),line->startPoint().y())); //shape.add(new FSLine(line->endPoint().x(),line->endPoint().y())); shape.add(new FSLine(-width, -height)); shape.add(new FSLine(width, height)); /*shape.add(new FSLine(-width, 0)); shape.add(new FSLine(0, -height));*/ FSDefineShape* Line = new FSDefineShape(identifier, bounds, fillStyles, lineStyles, shape); movie.add(Line); movie.add(new FSPlaceObject(identifier, line->Row, line->startPoint().x(), line->startPoint().y())); movie.add(new FSShowFrame()); } break; case Q3CanvasItem::Rtti_Polygon: break; case Q3CanvasItem::Rtti_PolygonalItem: { CPencilLine *poly=(CPencilLine*)(*it); } break; case Q3CanvasItem::Rtti_Rectangle: { CCanvasRectangle *rect=(CCanvasRectangle*)(*it); //qDebug("rect animx : %d colon numaramiz: %d",rect->animationX,i); if(rect->animationX>=i)continue; int identifier = movie.newIdentifier(); int width = rect->width(); int height =rect->height(); FSBounds bounds(-width,-height, width, height); FSVector<FSLineStyle*> lineStyles(1); FSVector<FSFillStyle*> fillStyles(1); QColor PenColor=rect->pen().color(); QColor BrushColor=rect->brush().color(); lineStyles[0] = new FSSolidLine(1, FSColor(PenColor.red(),PenColor.green(),PenColor.blue())); fillStyles[0] = new FSSolidFill( FSColor(BrushColor.red(),BrushColor.green(),BrushColor.blue())); /* * Create the outline of the shape. All drawing is performed using a series * of line an curve objects. The FSShapeStyle class is used to select the * current line and fill styles and to perform absolute moves within the * coordinate space of the shape (relative moves can be performed by drawing * line when no line style is selected - set the line style to 0). */ FSShape shape; shape.add(new FSShapeStyle(0, 1, 0,-width/2,-height/2)); //qDebug("width %d height %d baslangicX:%d baslangicY:%d",width,height,rect->rect().x() - view->defSceneWidth,rect->rect().y()-view->defSceneHeight); //shape.add(new FSShapeStyle(0,0)); shape.add(new FSLine(width, 0)); shape.add(new FSLine(0, height)); shape.add(new FSLine(-width, 0)); shape.add(new FSLine(0, -height)); /*shape.add(new FSShapeStyle(1, 1, 0,-50,-50)); shape.add(new FSLine(100,0)); shape.add(new FSLine(0,100)); shape.add(new FSLine(-100,0)); shape.add(new FSLine(0,-100));*/ FSDefineShape* rectangle = new FSDefineShape(identifier, bounds, fillStyles, lineStyles, shape); /* * Add the rectangle to the movie. All shapes and objects must be defined before * they can be placed on the display list and rendered on the Flash Player's * screen. */ movie.add(rectangle); /* * for layers and object place. */ movie.add(new FSPlaceObject(identifier, rect->Row, rect->rect().x(), rect->rect().y())); /* * Show the contents of the display list. Frames are delimited by successive * FSShowFrame objects. */ movie.add(new FSShowFrame()); } break; case Q3CanvasItem::Rtti_Spline: break; case Q3CanvasItem::Rtti_Sprite: { Q3CanvasSprite *sprite=(Q3CanvasSprite*)(*it); QByteArray ba; QBuffer buffer( &ba ); buffer.open( QIODevice::WriteOnly ); sprite->image()->convertToImage().save( &buffer, "BMP" ); // writes image into ba in BMP format FSImageConstructor* imageGenerator = ImageConstructor(); int status = TransformUtil::OK; int boyutu=ba.size(); qDebug("%d",boyutu); //if ((status = imageGenerator->setImageFromFile(imageFile.c_str())) != TransformUtil::OK)( const unsigned char *) //if ((status = imageGenerator->setImage(sprite->image()->convertToImage ().bits(),sizeof(sprite->image()->convertToImage ().bits()))) != TransformUtil::OK) if ((status = imageGenerator->setImage((const unsigned char*)buffer.buffer().data(),sizeof(char)*boyutu)) != TransformUtil::OK) { switch (status) { case TransformUtil::FileNotFound: cout << "Could not find image" << endl; break; case TransformUtil::ReadError: cout << "Could not read image" << endl; break; case TransformUtil::FormatError: cout << "Could not read image" << endl; break; } } if (status == TransformUtil::OK) { /* * Create the FSImageConstructor object used to generate the object * containing the image definition. Initialize it using the name of * the image file passed on the command line when the example was run. */ int imageId = movie.newIdentifier(); int shapeId = movie.newIdentifier(); int xOrigin = imageGenerator->getWidth()/2; int yOrigin = imageGenerator->getHeight()/2; FSDefineObject* image = imageGenerator->defineImage(imageId); /* * All images must be displayed as a bitmap fill inside a shape. The * FSImageConstructor class generates the shape enclosing the image. * If no border is required then the line style may be set to null. */ int borderWidth = 20; FSColor black = FSColorTable::black(); FSDefineShape3* shape = imageGenerator->defineShape(shapeId, imageId, -xOrigin, -yOrigin, borderWidth, &black); /* * Add all the objects together to create the movie. */ movie.setFrameRate(1.0f); movie.setFrameSize(shape->getBounds()); movie.add(image); movie.add(shape); movie.add(new FSPlaceObject2(shapeId, 1, 0, 0)); movie.add(new FSShowFrame()); } } break; case Q3CanvasItem::Rtti_Text: { CCanvasText *canvasText=(CCanvasText*)(*it); if(canvasText->animationX>=i)continue; FSTextConstructor* textGenerator = TextConstructor(); int status = TransformUtil::OK; proc = new Q3Process(); proc->addArgument( "locate"); proc->addArgument("*.ttf"); QString buf; //proc->launch(buf); connect( proc, SIGNAL(readyReadStdout()), this, SLOT(readFromStdout()) ); if ( !proc->start() ) { // error handling qDebug("process could not started."); return; } while(proc->isRunning()==TRUE){qApp->processEvents();} /*QByteArray bufByte=proc->readStdout(); if(!proc->normalExit()) qDebug("%d",proc->exitStatus ()); QString sttir(bufByte); QStringList sittirList;*/ QString ttfFileName=""; qDebug(canvasText->font().family().stripWhiteSpace ()); procOut = procOut.split("\n",procOut.join("\n")); qDebug("%d",procOut.count()); for(int ttfIndis=0;ttfIndis<procOut.count();ttfIndis++) { if(procOut[ttfIndis].right(4)==".ttf") { //qDebug(procOut[ttfIndis]); if(procOut[ttfIndis].contains(canvasText->font().family().stripWhiteSpace (),false)) { //qDebug("burasi ana yer"); ttfFileName=procOut[ttfIndis]; break; } } //qDebug("%d",ttfIndis); //qDebug(procOut[ttfIndis]); } if(ttfFileName=="") { qDebug("we could not find ttf file."); //TODO: for default font make an options dialog. qDebug("Default Font Selected."); for(int ttfIndis=0;ttfIndis<procOut.count();ttfIndis++) { if(procOut[ttfIndis].right(4)==".ttf") { //qDebug(procOut[ttfIndis]); //TODO:when you done option dialog for default font change the "arial" from down line. if(procOut[ttfIndis].contains("arial",false)) { ttfFileName=procOut[ttfIndis]; break; } } } } qDebug(ttfFileName); if ((status = textGenerator->setFontFromFile(ttfFileName)) != TransformUtil::OK) { switch (status) { case TransformUtil::FileNotFound: cout << "Could not find font file" << endl; break; case TransformUtil::ReadError: cout << "Could not read font file" << endl; break; case TransformUtil::FormatError: cout << "Could not read font file" << endl; break; } } int layer = 0; // Starting layer for objects in the display list. int fontSize = canvasText->boundingRect().height(); // 280; // Font size in twips 1 point = 20 twips int lineSpacing = fontSize; // The font size defines a suitable line spacing /* * The movie will be sized to match the block of text generated. * The margins are defined so the text is displayed without touching * the edge of the Flash Player screen. */ int leftMargin = fontSize; int rightMargin = fontSize; int topMargin = fontSize; int bottomMargin = fontSize; FSColor textColor(canvasText->color().red(),canvasText->color().green(),canvasText->color().blue()); textGenerator->setIdentifier(movie.newIdentifier()); textGenerator->setSize(fontSize); textGenerator->setColor(&textColor); /* * The block of text is generated before the font definition. This ensures * that only the characters displayed will be included in the font. Unused * characters will be omitted, greatly reducing the size of the Flash file * generated. Once the FSDefineFont2 object has been generated any text * objects created with characters not previously used, will not be * displayed correctly - a new font definition would need to be generated * to include the new characters. * * The FSDefineText2 object contains an array of FSText objects, each * specifying an offset relative to the origin of the entire block. These * can easily be changed if a line needs to be indented or the line spacing * adjusted. */ //FSDefineText2* text = textGenerator->defineWideTextBlock(movie.newIdentifier(), // (const wchar_t **)lines, 32, lineSpacing); FSDefineText2* text = textGenerator->defineText(movie.newIdentifier(),canvasText->text()); FSDefineFont2* font = textGenerator->defineFont(); /* * Define the size of the Flash Player screen using the bounding * rectangle defined for the block of text plus a suitable margin so * the text does not touch the edge of the screen. */ int screenWidth = text->getBounds().getWidth() + leftMargin + rightMargin; int screenHeight = text->getBounds().getHeight() + topMargin + bottomMargin; movie.add(font); movie.add(text); movie.add(new FSPlaceObject2(text->getIdentifier(), canvasText->Row, canvasText->boundingRect ().x() , canvasText->boundingRect ().y())); movie.add(new FSShowFrame()); } break; } } } try { QString fileName = Q3FileDialog::getSaveFileName( ); movie.encodeToFile(fileName); } catch (FSException e) { /* * Several exceptions could be thrown to get to this point. FSMovie will * throw an FSFileOpenException, FSAccessException or FSFormatException * if the file cannot be opened for writing, an error occurs while writing * to the file or if an error occurs while encoding the Flash data, respectively. * * All the exceptions thrown contain a message which describes why the * exception was thrown so handling them all in the same way is sufficient * for the purposes of the examples. */ cerr << e.what(); } }