void FunctionViewer::refreshModel() { TXsheet *xsh = m_xshHandle ? m_xshHandle->getXsheet() : 0; m_functionGraph->getModel()->refreshData(xsh); if (xsh) { int rowCount = xsh->getFrameCount(); m_numericalColumns->setRowCount(rowCount); m_numericalColumns->updateAll(); ToonzScene *scene = xsh->getScene(); if (!scene) // This seems wrong. It should rather be return; // asserted - though I'm not touching it now... TFilePath scenePath = scene->getScenePath().getParentDir(); if (scene->isUntitled()) scenePath = TProjectManager::instance()->getCurrentProject()->getScenesPath(); m_treeView->setCurrentScenePath(scenePath); int distance, offset; scene->getProperties()->getMarkers(distance, offset); m_numericalColumns->setMarkRow(distance, offset); } m_treeView->updateAll(); m_toolbar->setCurve(0); }
void onDeliver() { if (m_error) { m_error = false; MsgBox(DVGui::CRITICAL, QObject::tr("There was an error saving frames for the %1 level.").arg(QString::fromStdWString(m_fp.withoutParentDir().getWideString()))); } bool isPreview = (m_fp.getType() == "noext"); TImageCache::instance()->remove(toString(m_fp.getWideString() + L".0")); TNotifier::instance()->notify(TSceneNameChange()); if (Preferences::instance()->isGeneratedMovieViewEnabled()) { if (!isPreview && (Preferences::instance()->isDefaultViewerEnabled()) && (m_fp.getType() == "mov" || m_fp.getType() == "avi" || m_fp.getType() == "3gp")) { QString name = QString::fromStdString(m_fp.getName()); int index; if ((index = name.indexOf("#RENDERID")) != -1) //!quite ugly I know.... m_fp = m_fp.withName(name.left(index).toStdWString()); if (!TSystem::showDocument(m_fp)) { QString msg(QObject::tr("It is not possible to display the file %1: no player associated with its format").arg(QString::fromStdWString(m_fp.withoutParentDir().getWideString()))); MsgBox(WARNING, msg); } } else { int r0, r1, step; TApp *app = TApp::instance(); ToonzScene *scene = app->getCurrentScene()->getScene(); TOutputProperties &outputSettings = isPreview ? *scene->getProperties()->getPreviewProperties() : *scene->getProperties()->getOutputProperties(); outputSettings.getRange(r0, r1, step); const TRenderSettings rs = outputSettings.getRenderSettings(); if (r0 == 0 && r1 == -1) r0 = 0, r1 = scene->getFrameCount() - 1; double timeStretchFactor = isPreview ? 1.0 : (double)outputSettings.getRenderSettings().m_timeStretchTo / outputSettings.getRenderSettings().m_timeStretchFrom; r0 = tfloor(r0 * timeStretchFactor); r1 = tceil((r1 + 1) * timeStretchFactor) - 1; TXsheet::SoundProperties *prop = new TXsheet::SoundProperties(); prop->m_frameRate = outputSettings.getFrameRate(); TSoundTrack *snd = app->getCurrentXsheet()->getXsheet()->makeSound(prop); if (outputSettings.getRenderSettings().m_stereoscopic) { assert(!isPreview); ::viewFile(m_fp.withName(m_fp.getName() + "_l"), r0 + 1, r1 + 1, step, isPreview ? rs.m_shrinkX : 1, snd, 0, false, true); ::viewFile(m_fp.withName(m_fp.getName() + "_r"), r0 + 1, r1 + 1, step, isPreview ? rs.m_shrinkX : 1, snd, 0, false, true); } else ::viewFile(m_fp, r0 + 1, r1 + 1, step, isPreview ? rs.m_shrinkX : 1, snd, 0, false, true); } } }
VectorizerParameters *VectorizerPopup::getParameters() const { assert(m_sceneHandle); ToonzScene *scene = m_sceneHandle->getScene(); assert(scene); TSceneProperties *sceneProp = scene->getProperties(); assert(sceneProp); assert(sceneProp->getVectorizerParameters()); return sceneProp->getVectorizerParameters(); }
void start(const ToonzScene &scene) { m_status = 3; m_alphaNeeded = scene.getProperties()->getBgColor().m < 255; assert(m_started == false); m_started = true; if (TSystem::doesExistFileOrLevel(m_filepath)) TSystem::removeFileOrLevel(m_filepath); m_lw = TLevelWriterP(m_filepath); m_lw->setFrameRate(m_fps); if (m_lw->getProperties() && m_fileOptions) m_lw->getProperties()->setProperties(m_fileOptions); if (m_st) m_lw->saveSoundTrack(m_st.getPointer()); }
void TApp::updateCurrentFrame() { ToonzScene *scene = m_currentScene->getScene(); m_currentFrame->setSceneFrameSize(scene->getFrameCount()); int f0, f1, step; scene->getProperties()->getPreviewProperties()->getRange(f0, f1, step); if (f0 > f1) { f0 = 0; f1 = scene->getFrameCount() - 1; } if (f0 != m_currentFrame->getStartFrame() || f1 != m_currentFrame->getEndFrame()) { m_currentFrame->setFrameRange(f0, f1); std::vector<TFrameId> fids; TXshSimpleLevel *sl = m_currentLevel->getSimpleLevel(); if (sl) { sl->getFids(fids); m_currentFrame->setFrameIds(fids); } } }
bool addFrame(ToonzScene &scene, int row, bool isLast) { TAffine cameraView = scene.getXsheet()->getPlacement(TStageObjectId::CameraId(0), row).inv(); TPixel32 bgColor = scene.getProperties()->getBgColor(); TStageObject *cameraPegbar = scene.getXsheet()->getStageObject(TStageObjectId::CameraId(0)); assert(cameraPegbar); TCamera *camera = cameraPegbar->getCamera(); assert(camera); TAffine dpiAff = getDpiAffine(camera).inv(); TAffine aff = cameraView * dpiAff; Stage::VisitArgs args; args.m_scene = &scene; args.m_xsh = scene.getXsheet(); args.m_row = row; args.m_col = m_columnIndex; args.m_osm = &m_osMask; ImagePainter::VisualSettings vs; FlashStagePainter painter(m_flash, aff, vs, bgColor); m_flash.beginFrame(++m_frameIndex); Stage::visit(painter, args); /* &scene, scene.getXsheet(), row, m_columnIndex, m_osMask, false, 0); */ m_frameIndex = m_flash.endFrame(isLast, m_frameCountLoader, (m_sceneCount == m_sceneIndex)); return true; }
static void printCurrentFrame() { QPrinter printer; QPrintDialog dialog(&printer, 0); if (!dialog.exec()) return; ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); int frame = TApp::instance()->getCurrentFrame()->getFrame(); int lx = TApp::instance() ->getCurrentScene() ->getScene() ->getCurrentCamera() ->getRes() .lx; int ly = TApp::instance() ->getCurrentScene() ->getScene() ->getCurrentCamera() ->getRes() .ly; TRaster32P raster(lx, ly); if (scene->getFrameCount() <= 0) { // Ricordarsi di usare DvMsgBox !! (se si decommenta questo codice :) ) // QMessageBox::warning(0,"Print",tr("It is not possible to generate an // animation\nbecause the scene is empty.", "WARNING")); return; } raster->fill(scene->getProperties()->getBgColor()); scene->renderFrame(raster, frame, TApp::instance()->getCurrentXsheet()->getXsheet()); QImage img = rasterToQImage(raster); QPainter painter(&printer); QRect rect = painter.viewport(); QSize size = img.size(); size.scale(rect.size(), Qt::KeepAspectRatio); painter.setViewport(rect.x(), rect.y(), size.width(), size.height()); painter.setWindow(img.rect()); painter.drawImage(0, 0, img); }
//!Specialized render invocation for multimedia rendering. Flash rendering //!is currently not supported in this mode. void RenderCommand::multimediaRender() { ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); string ext = m_fp.getType(); #ifdef WIN32 if (ext == "avi") { TPropertyGroup *props = scene->getProperties()->getOutputProperties()->getFileFormatProperties(ext); string codecName = props->getProperty(0)->getValueAsString(); TDimension res = scene->getCurrentCamera()->getRes(); if (!AviCodecRestrictions::canWriteMovie(toWideString(codecName), res)) { QString msg(QObject::tr("The resolution of the output camera does not fit with the options chosen for the output file format.")); MsgBox(WARNING, msg); return; } } #endif; TOutputProperties *prop = scene->getProperties()->getOutputProperties(); //Build thread count int index = prop->getThreadIndex(); const int procCount = TSystem::getProcessorCount(); const int threadCounts[3] = {1, procCount / 2, procCount}; int threadCount = threadCounts[index]; //Build raster granularity size index = prop->getMaxTileSizeIndex(); const int maxTileSizes[4] = { (std::numeric_limits<int>::max)(), TOutputProperties::LargeVal, TOutputProperties::MediumVal, TOutputProperties::SmallVal}; TRenderSettings rs = prop->getRenderSettings(); rs.m_maxTileSize = maxTileSizes[index]; MultimediaRenderer multimediaRenderer(scene, m_fp, prop->getMultimediaRendering(), threadCount); multimediaRenderer.setRenderSettings(rs); #ifdef BRAVODEMO rs.m_mark = loadBravo(scene->getCurrentCamera()->getRes()); #endif TPointD cameraDpi = scene->getCurrentCamera()->getDpi(); multimediaRenderer.setDpi(cameraDpi.x, cameraDpi.y); multimediaRenderer.enablePrecomputing(true); for (int i = 0; i < m_numFrames; ++i, m_r += m_stepd) multimediaRenderer.addFrame(m_r); MultimediaProgressBar *listener = new MultimediaProgressBar(&multimediaRenderer); QObject::connect(listener, SIGNAL(canceled()), &multimediaRenderer, SLOT(onCanceled())); multimediaRenderer.addListener(listener); multimediaRenderer.start(); }
void RenderCommand::rasterRender(bool isPreview) { ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); if (isPreview) { //Let the PreviewFxManager own the rest. Just pass him the current output node. PreviewFxManager::instance()->showNewPreview((TFx *)scene->getXsheet()->getFxDag()->getCurrentOutputFx()); return; } string ext = m_fp.getType(); #ifdef WIN32 if (ext == "avi" && !isPreview) { TPropertyGroup *props = scene->getProperties()->getOutputProperties()->getFileFormatProperties(ext); string codecName = props->getProperty(0)->getValueAsString(); TDimension res = scene->getCurrentCamera()->getRes(); if (!AviCodecRestrictions::canWriteMovie(toWideString(codecName), res)) { QString msg(QObject::tr("The resolution of the output camera does not fit with the options chosen for the output file format.")); MsgBox(WARNING, msg); return; } } #endif; //Extract output properties TOutputProperties *prop = isPreview ? scene->getProperties()->getPreviewProperties() : scene->getProperties()->getOutputProperties(); //Build thread count /*-- Dedicated CPUs のコンボボックス (Single, Half, All) --*/ int index = prop->getThreadIndex(); const int procCount = TSystem::getProcessorCount(); const int threadCounts[3] = {1, procCount / 2, procCount}; int threadCount = threadCounts[index]; /*-- MovieRendererを作る。Previewの場合はファイルパスは空 --*/ MovieRenderer movieRenderer(scene, isPreview ? TFilePath() : m_fp, threadCount, isPreview); TRenderSettings rs = prop->getRenderSettings(); //Build raster granularity size index = prop->getMaxTileSizeIndex(); const int maxTileSizes[4] = { (std::numeric_limits<int>::max)(), TOutputProperties::LargeVal, TOutputProperties::MediumVal, TOutputProperties::SmallVal}; rs.m_maxTileSize = maxTileSizes[index]; //Build #ifdef BRAVODEMO rs.m_mark = loadBravo(scene->getCurrentCamera()->getRes()); #endif /*-- RenderSettingsをセット --*/ movieRenderer.setRenderSettings(rs); /*-- カメラDPIの取得、セット --*/ TPointD cameraDpi = isPreview ? scene->getCurrentPreviewCamera()->getDpi() : scene->getCurrentCamera()->getDpi(); movieRenderer.setDpi(cameraDpi.x, cameraDpi.y); movieRenderer.enablePrecomputing(true); /*-- プログレス ダイアログの作成 --*/ RenderListener *listener = new RenderListener(movieRenderer.getTRenderer(), m_fp, ((m_numFrames - 1) / m_step) + 1, isPreview); QObject::connect(listener, SIGNAL(canceled()), &movieRenderer, SLOT(onCanceled())); movieRenderer.addListener(listener); bool fieldRendering = rs.m_fieldPrevalence != TRenderSettings::NoField; /*-- buildSceneFxの進行状況を表示するプログレスバー --*/ QProgressBar *buildSceneProgressBar = new QProgressBar(TApp::instance()->getMainWindow()); buildSceneProgressBar->setAttribute(Qt::WA_DeleteOnClose); buildSceneProgressBar->setWindowFlags(Qt::SubWindow | Qt::Dialog | Qt::WindowStaysOnTopHint); buildSceneProgressBar->setMinimum(0); buildSceneProgressBar->setMaximum(m_numFrames - 1); buildSceneProgressBar->setValue(0); buildSceneProgressBar->move(600, 500); buildSceneProgressBar->setWindowTitle("Building Schematic..."); buildSceneProgressBar->show(); for (int i = 0; i < m_numFrames; ++i, m_r += m_stepd) { buildSceneProgressBar->setValue(i); if (rs.m_stereoscopic) scene->shiftCameraX(-rs.m_stereoscopicShift / 2); TFxPair fx; fx.m_frameA = buildSceneFx(scene, m_r, rs.m_shrinkX, isPreview); if (fieldRendering && !isPreview) fx.m_frameB = buildSceneFx(scene, m_r + 0.5 / m_timeStretchFactor, rs.m_shrinkX, isPreview); else if (rs.m_stereoscopic) { scene->shiftCameraX(rs.m_stereoscopicShift); fx.m_frameB = buildSceneFx(scene, m_r + 0.5 / m_timeStretchFactor, rs.m_shrinkX, isPreview); scene->shiftCameraX(-rs.m_stereoscopicShift / 2); } else fx.m_frameB = TRasterFxP(); /*-- movieRendererにフレーム毎のFxを登録 --*/ movieRenderer.addFrame(m_r, fx); } /*-- プログレスバーを閉じる --*/ buildSceneProgressBar->close(); //resetViewer(); //TODO cancella le immagini dell'eventuale render precedente //FileViewerPopupPool::instance()->getCurrent()->onClose(); movieRenderer.start(); }
void RenderCommand::flashRender() { ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); TSceneProperties *sprop = scene->getProperties(); FILE *fileP = fopen(m_fp, "wb"); if (!fileP) return; ProgressDialog pb("rendering " + toQString(m_fp), "Cancel", 0, m_numFrames); pb.show(); TDimension cameraSize = scene->getCurrentCamera()->getRes(); double frameRate = sprop->getOutputProperties()->getFrameRate(); TFlash flash( cameraSize.lx, cameraSize.ly, m_numFrames, frameRate, sprop->getOutputProperties()->getFileFormatProperties("swf")); flash.setBackgroundColor(sprop->getBgColor()); std::vector<TXshSoundColumn *> columns; scene->getSoundColumns(columns); if (!columns.empty()) { TXsheet::SoundProperties *prop = new TXsheet::SoundProperties(); prop->m_frameRate = frameRate; TSoundTrack *st = scene->getXsheet()->makeSound(prop); if (st) flash.putSound(st, 0); } int i = 0; for (i = 0; i < m_numFrames; ++i, m_r += m_stepd) { flash.beginFrame(m_step * i + 1); TRasterFxP rfx = buildSceneFx(scene, m_r, 0, false); assert(rfx); rfx->compute(flash, tround(m_r)); // WARNING: This should accept a DOUBLE... #ifdef BRAVODEMO TRasterImageP ri(loadBravo(scene->getCurrentCamera()->getRes())); int lx = ri->getRaster()->getLx(); int ly = ri->getRaster()->getLx(); flash.pushMatrix(); int dx = tround(0.1 * (cameraSize.lx - lx)); int dy = tround(0.1 * (cameraSize.ly - ly)); flash.multMatrix(TTranslation((cameraSize.lx - lx) / 2 - (dx > 0 ? dx : 0), -(cameraSize.ly - ly) / 2 + (dy > 0 ? dy : 0))); flash.draw(ri, 0); flash.popMatrix(); #endif flash.endFrame(i == m_numFrames - 1, 0, true); if (pb.wasCanceled()) break; pb.setValue(i + 1); } flash.writeMovie(fileP); fclose(fileP); TSystem::showDocument(m_fp); //QDesktopServices::openUrl(QUrl(toQString(m_fp))); TImageCache::instance()->remove(toString(m_fp.getWideString() + L".0")); TNotifier::instance()->notify(TSceneNameChange()); }
bool RenderCommand::init(bool isPreview) { ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); TSceneProperties *sprop = scene->getProperties(); /*-- Preview/Renderに応じてそれぞれのSettingを取得 --*/ TOutputProperties &outputSettings = isPreview ? *sprop->getPreviewProperties() : *sprop->getOutputProperties(); outputSettings.getRange(m_r0, m_r1, m_step); /*-- シーン全体のレンダリングの場合、m_r1をScene長に設定 --*/ if (m_r0 == 0 && m_r1 == -1) { m_r0 = 0; m_r1 = scene->getFrameCount() - 1; } if (m_r0 < 0) m_r0 = 0; if (m_r1 >= scene->getFrameCount()) m_r1 = scene->getFrameCount() - 1; if (m_r1 < m_r0) { MsgBox(WARNING, QObject::tr("The command cannot be executed because the scene is empty.")); return false; // throw TException("empty scene"); // non so perche', ma termina il programma // nonostante il try all'inizio } // Initialize the preview case /*TRenderSettings rs = sprop->getPreviewProperties()->getRenderSettings(); TRenderSettings rso = sprop->getOutputProperties()->getRenderSettings(); rs.m_stereoscopic=true; rs.m_stereoscopicShift=0.05; rso.m_stereoscopic=true; rso.m_stereoscopicShift=0.05; sprop->getPreviewProperties()->setRenderSettings(rs); sprop->getOutputProperties()->setRenderSettings(rso);*/ if (isPreview) { /*-- PreviewではTimeStretchを考慮しないので、そのままフレーム値を格納してゆく --*/ m_numFrames = (int)(m_r1 - m_r0 + 1); m_r = m_r0; m_stepd = m_step; m_multimediaRender = 0; return true; } // Full render case // Read the output filepath TFilePath fp = outputSettings.getPath(); /*-- ファイル名が指定されていない場合は、シーン名を出力ファイル名にする --*/ if (fp.getWideName() == L"") fp = fp.withName(scene->getScenePath().getName()); /*-- ラスタ画像の場合、ファイル名にフレーム番号を追加 --*/ if (TFileType::getInfo(fp) == TFileType::RASTER_IMAGE || fp.getType() == "pct" || fp.getType() == "pic" || fp.getType() == "pict") //pct e' un formato"livello" (ha i settings di quicktime) ma fatto di diversi frames fp = fp.withFrame(TFrameId::EMPTY_FRAME); fp = scene->decodeFilePath(fp); if (!TFileStatus(fp.getParentDir()).doesExist()) { try { TFilePath parent = fp.getParentDir(); TSystem::mkDir(parent); DvDirModel::instance()->refreshFolder(parent.getParentDir()); } catch (TException &e) { MsgBox(WARNING, QObject::tr("It is not possible to create folder : %1").arg(QString::fromStdString(toString(e.getMessage())))); return false; } catch (...) { MsgBox(WARNING, QObject::tr("It is not possible to create a folder.")); return false; } } m_fp = fp; // Retrieve camera infos const TCamera *camera = isPreview ? scene->getCurrentPreviewCamera() : scene->getCurrentCamera(); TDimension cameraSize = camera->getRes(); TPointD cameraDpi = camera->getDpi(); // Retrieve render interval/step/times double stretchTo = (double)outputSettings.getRenderSettings().m_timeStretchTo; double stretchFrom = (double)outputSettings.getRenderSettings().m_timeStretchFrom; m_timeStretchFactor = stretchTo / stretchFrom; m_stepd = m_step / m_timeStretchFactor; int stretchedR0 = tfloor(m_r0 * m_timeStretchFactor); int stretchedR1 = tceil((m_r1 + 1) * m_timeStretchFactor) - 1; m_r = stretchedR0 / m_timeStretchFactor; m_numFrames = (stretchedR1 - stretchedR0) / m_step + 1; // Update the multimedia render switch m_multimediaRender = outputSettings.getMultimediaRendering(); return true; }
bool VectorizerPopup::apply() { std::set<TXshLevel *> levels; ToonzScene *scene = m_sceneHandle->getScene(); if (!scene) { assert(scene); return false; } TSceneProperties *sceneProp = scene->getProperties(); if (!sceneProp) return false; VectorizerParameters *vectorizerParameters = sceneProp->getVectorizerParameters(); if (!vectorizerParameters) return false; int r0 = 0; int c0 = 0; int r1 = 0; int c1 = 0; bool isCellSelection = getSelectedLevels(levels, r0, c0, r1, c1); if (levels.empty()) { error(tr("The current selection is invalid.")); return false; } //Initialize Progress bar m_progressDialog = new DVGui::ProgressDialog("", "Cancel", 0, 1); m_progressDialog->setWindowFlags(Qt::Dialog | Qt::WindowTitleHint); //Don't show ? and X buttons m_progressDialog->setWindowTitle(QString("Convert To Vector...")); m_progressDialog->setAttribute(Qt::WA_DeleteOnClose); m_progressDialog->setWindowModality(Qt::WindowModal); //No user interaction is allowed during vectorization m_progressDialog->setFixedSize(200, 100); //Initialize vectorizer m_vectorizer = new Vectorizer; m_vectorizer->setParameters(*vectorizerParameters); connect(m_vectorizer, SIGNAL(frameName(QString)), this, SLOT(onFrameName(QString)), Qt::QueuedConnection); connect(m_vectorizer, SIGNAL(frameDone(int)), this, SLOT(onFrameDone(int)), Qt::QueuedConnection); connect(m_vectorizer, SIGNAL(partialDone(int, int)), this, SLOT(onPartialDone(int, int)), Qt::QueuedConnection); //We DON'T want the progress bar to be hidden at cancel press - since its modal //behavior prevents the user to interfere with a possibly still active vectorization. disconnect(m_progressDialog, SIGNAL(canceled()), m_progressDialog, SLOT(onCancel())); //We first inform the vectorizer of a cancel press; bool ret = connect(m_progressDialog, SIGNAL(canceled()), m_vectorizer, SLOT(cancel())); //which eventually transmits the command to vectorization core, allowing full-time cancels ret = ret && connect(m_progressDialog, SIGNAL(canceled()), m_vectorizer, SIGNAL(transmitCancel())); //Only after the vectorizer has terminated its process - or got cancelled, we are allowed //to proceed here. ret = ret && connect(m_vectorizer, SIGNAL(finished()), this, SLOT(onFinished()), Qt::QueuedConnection); assert(ret); int newIndexColumn = c1 + 1; std::set<TXshLevel *>::iterator it = levels.begin(); for (it; it != levels.end(); it++) { TXshSimpleLevel *sl = dynamic_cast<TXshSimpleLevel *>(*it); if (!sl || !sl->getSimpleLevel() || !isLevelToConvert(sl)) { QString levelName = tr(toString(sl->getName()).c_str()); QString errorMsg = tr("Cannot convert to vector the current selection.") + levelName; error(errorMsg); continue; } std::vector<TFrameId> fids; if (isCellSelection) getSelectedFids(fids, sl, r0, c0, r1, c1); else sl->getFids(fids); assert(fids.size() > 0); close(); // Re-initialize progress Bar m_progressDialog->setMaximum(fids.size() * 100); m_progressDialog->setValue(0); m_currFrame = 0; // Re-initialize vectorizer m_vectorizer->setLevel(sl); m_vectorizer->setFids(fids); // Start vectorizing m_vectorizer->start(); m_progressDialog->show(); // Wait the vectorizer... while (!l_quitLoop) QCoreApplication::processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents); l_quitLoop = false; // Assign output X-sheet cells TXshSimpleLevel *vl = m_vectorizer->getVectorizedLevel(); if (isCellSelection && vl) { TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet(); xsheet->insertColumn(newIndexColumn); int r, c; for (c = c0; c <= c1; c++) { for (r = r0; r <= r1; r++) { TXshCell cell = xsheet->getCell(r, c); TXshSimpleLevel *level = (!cell.isEmpty()) ? cell.getSimpleLevel() : 0; if (level != sl) continue; TFrameId curFid = cell.getFrameId(); std::vector<TFrameId> newFids; vl->getFids(newFids); std::vector<TFrameId>::iterator it1 = newFids.begin(); for (it1; it1 != newFids.end(); it1++) { TFrameId id = *it1; if (id.getNumber() == curFid.getNumber() || // Hanno stesso numero di frame (id.getNumber() == 1 && curFid.getNumber() == -2)) // La vecchia cella non ha numero di frame xsheet->setCell(r, newIndexColumn, TXshCell(vl, id)); } } } newIndexColumn += 1; } else if (vl) { std::vector<TFrameId> gomi; scene->getXsheet()->exposeLevel(0, scene->getXsheet()->getFirstFreeColumnIndex(), vl, gomi); } if (m_vectorizer->isCanceled()) break; } m_progressDialog->close(); delete m_vectorizer; TApp::instance()->getCurrentScene()->notifyCastChange(); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); return true; }
bool IoCmd::exportLevel(const TFilePath &path, TXshSimpleLevel *sl, ExportLevelOptions opts, OverwriteCallbacks *overwriteCB, ProgressCallbacks *progressCB) { struct Locals { const TFilePath &m_path; TXshSimpleLevel *m_sl; const ExportLevelOptions &m_opts; OverwriteCallbacks *m_overwriteCB; ProgressCallbacks *m_progressCB; bool exportToMultifile() { ImageExporter exporter(*m_sl, m_opts); TXshLevelType outputLevelType = (m_path.getType() == "tlv") ? TZP_TYPE : OVL_TYPE; bool firstTime = true; for (int i = 0; i < m_sl->getFrameCount(); ++i) { if (m_progressCB->canceled()) return false; // Prepare frame export path TFilePath fpout; if (m_opts.m_forRetas) { QString pathOut = QString::fromStdWString(m_path.getParentDir().getWideString()) + "\\" + QString::fromStdString(m_path.getName()) + QString::fromStdString(m_sl->index2fid(i).expand()) + "." + QString::fromStdString(m_path.getType()); fpout = TFilePath(pathOut.toStdString()); } else fpout = TFilePath(m_path.withFrame(m_sl->index2fid(i))); // Ask for overwrite permission in case a level with the built path already exists if (firstTime) { firstTime = false; if (TSystem::doesExistFileOrLevel(fpout)) { QApplication::restoreOverrideCursor(); bool overwrite = m_overwriteCB->overwriteRequest(fpout); QApplication::setOverrideCursor(Qt::WaitCursor); if (!overwrite) return false; } } // Retrieve the image to export at current frame TImageP img = exporter.exportedImage(m_sl->index2fid(i), outputLevelType); assert(img); // Save the prepared fullcolor image to file TImageWriter iw(fpout); iw.setProperties(m_opts.m_props); iw.save(img); m_progressCB->setValue(i + 1); } return true; } bool exportToTlv() { TFilePath fp(m_path.withNoFrame()); // Remove any existing level if (TSystem::doesExistFileOrLevel(fp)) { bool overwrite = m_overwriteCB->overwriteRequest(fp); if (!overwrite) return false; TSystem::deleteFile(fp); } TSystem::removeFileOrLevel(fp.withType("tpl")); // Export level TLevelWriterP lw(fp); ImageExporter exporter(*m_sl, m_opts); for (int i = 0; i < m_sl->getFrameCount(); ++i) { if (m_progressCB->canceled()) return false; const TFrameId &fid = m_sl->index2fid(i); TImageP img = exporter.exportedImage(fid, TZP_TYPE); assert(img); lw->getFrameWriter(fid)->save(img); m_progressCB->setValue(i + 1); } return true; } }; // Locals // Use default values in case some were not specified by input // Level if (!sl) { sl = TApp::instance()->getCurrentLevel()->getSimpleLevel(); if (!sl) { DVGui::error(QObject::tr("No level selected!")); return false; } } if (sl->isEmpty()) return false; // Output properties if (!opts.m_props) { ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); opts.m_props = scene->getProperties()->getOutputProperties()->getFileFormatProperties(path.getType()); } // Camera (todo) assert(opts.m_camera.getRes().lx > 0 && opts.m_camera.getRes().ly > 0); // Callbacks std::auto_ptr<OverwriteCallbacks> overwriteDefault( overwriteCB ? 0 : (overwriteCB = new ExportOverwriteCB())); std::auto_ptr<ProgressCallbacks> progressDefault( progressCB ? 0 : (progressCB = new ExportProgressCB())); // Initialize variables Locals locals = {path, sl, opts, overwriteCB, progressCB}; progressCB->setProcessedName(QString::fromStdWString(path.getWideString())); progressCB->setRange(0, sl->getFrameCount()); // Export level BusyCursorOverride cursorOverride; QCoreApplication::processEvents(); // Refresh screen. ...But WHY is this // necessary? try { return (path.getType() == "tlv") ? assert(sl->getType() == PLI_XSHLEVEL), locals.exportToTlv() : locals.exportToMultifile(); } catch (...) { return false; } }
bool addFrame(ToonzScene &scene, int row, bool isLast) { assert(m_status == 3); if (!m_started) start(scene); TDimension cameraRes = scene.getCurrentCamera()->getRes(); TDimensionD cameraSize = scene.getCurrentCamera()->getSize(); TPointD center(0.5 * cameraSize.lx, 0.5 * cameraSize.ly); double sx = (double)m_offlineGlContext.getLx() / (double)cameraRes.lx; double sy = (double)m_offlineGlContext.getLy() / (double)cameraRes.ly; double sc = std::min(sx, sy); // TAffine cameraAff = // scene.getXsheet()->getPlacement(TStageObjectId::CameraId(0), row); TAffine cameraAff = scene.getXsheet()->getCameraAff(row); double dpiScale = (1.0 / Stage::inch) * (double)cameraRes.lx / cameraSize.lx; // TAffine viewAff = TScale(dpiScale*sc) * TTranslation(center)* // cameraAff.inv(); TAffine viewAff = TTranslation(0.5 * cameraRes.lx, 0.5 * cameraRes.ly) * TScale(dpiScale * sc) * cameraAff.inv(); TRect clipRect(m_offlineGlContext.getBounds()); TPixel32 bgColor = scene.getProperties()->getBgColor(); m_offlineGlContext.makeCurrent(); TPixel32 bgClearColor = m_bgColor; if (m_alphaEnabled && m_alphaNeeded) { const double maxValue = 255.0; double alpha = (double)bgClearColor.m / maxValue; bgClearColor.r *= alpha; bgClearColor.g *= alpha; bgClearColor.b *= alpha; } m_offlineGlContext.clear(bgClearColor); Stage::VisitArgs args; args.m_scene = &scene; args.m_xsh = scene.getXsheet(); args.m_row = row; args.m_col = m_columnIndex; args.m_osm = &m_osMask; ImagePainter::VisualSettings vs; Stage::OpenGlPainter painter(viewAff, clipRect, vs, false, true); Stage::visit(painter, args); /* painter, &scene, scene.getXsheet(), row, m_columnIndex, m_osMask, false,0); */ TImageWriterP writer = m_lw->getFrameWriter(m_frameIndex++); if (!writer) return false; #ifdef MACOSX glFinish(); // per fissare il bieco baco su Mac/G3 #endif TRaster32P raster = m_offlineGlContext.getRaster(); #ifdef MACOSX if (m_alphaEnabled && m_alphaNeeded) checkAndCorrectPremultipliedImage(raster); #endif if (Preferences::instance()->isSceneNumberingEnabled()) TRasterImageUtils::addSceneNumbering(TRasterImageP(raster), m_frameIndex - 1, scene.getSceneName(), row + 1); TRasterImageP img(raster); writer->save(img); return true; }