Ejemplo n.º 1
0
void LevelCreatePopup::update() {
  updatePath();
  Preferences *pref = Preferences::instance();
  if (pref->isNewLevelSizeToCameraSizeEnabled()) {
    TCamera *currCamera =
        TApp::instance()->getCurrentScene()->getScene()->getCurrentCamera();
    TDimensionD camSize = currCamera->getSize();
    m_widthFld->setValue(camSize.lx);
    m_heightFld->setValue(camSize.ly);
    m_dpiFld->setValue(currCamera->getDpi().x);
  } else {
    m_widthFld->setValue(pref->getDefLevelWidth());
    m_heightFld->setValue(pref->getDefLevelHeight());
    m_dpiFld->setValue(pref->getDefLevelDpi());
  }

  int levelType = pref->getDefLevelType();
  int index     = -1;
  switch (levelType) {
  case TZI_XSHLEVEL:
    index = m_levelTypeOm->findText(ScanLevel);
    break;
  case PLI_XSHLEVEL:
    index = m_levelTypeOm->findText(VectorLevel);
    break;
  case TZP_XSHLEVEL:
    index = m_levelTypeOm->findText(ToonzLevel);
    break;
  case OVL_XSHLEVEL:
    index = m_levelTypeOm->findText(RasterLevel);
    break;
  }
  if (index >= 0) m_levelTypeOm->setCurrentIndex(index);

  /*
(old behaviour)
TCamera* camera = scene->getCurrentCamera();
  TDimensionD cameraSize = camera->getSize();
  m_widthFld->setValue(cameraSize.lx);
  m_heightFld->setValue(cameraSize.ly);
if(camera->isXPrevalence())
m_dpiFld->setValue(camera->getDpi().x);
else
m_dpiFld->setValue(camera->getDpi().y);
*/
}
Ejemplo n.º 2
0
Preferences::Preferences()
	: m_units("mm"), m_cameraUnits("inch"), m_scanLevelType("tif"), m_defLevelWidth(0.0), m_defLevelHeight(0.0), m_defLevelDpi(0.0), m_iconSize(160, 120), m_blankColor(TPixel32::White), m_frontOnionColor(TPixel::Black), m_backOnionColor(TPixel::Black), m_transpCheckBg(TPixel::White), m_transpCheckInk(TPixel::Black), m_transpCheckPaint(TPixel(127, 127, 127)), m_autosavePeriod(15), m_chunkSize(10), m_rasterOptimizedMemory(0), m_shrink(1), m_step(1), m_blanksCount(0), m_keyframeType(3), m_animationStep(1), m_textureSize(0), m_xsheetStep(10), m_shmmax(-1), m_shmseg(-1), m_shmall(-1), m_shmmni(-1), m_onionPaperThickness(50), m_currentLanguage(0), m_currentStyleSheet(0), m_undoMemorySize(100), m_dragCellsBehaviour(0), m_lineTestFpsCapture(25), m_defLevelType(0), m_autocreationType(1), m_autoExposeEnabled(true), m_autoCreateEnabled(true), m_subsceneFolderEnabled(true), m_generatedMovieViewEnabled(true), m_xsheetAutopanEnabled(true), m_ignoreAlphaonColumn1Enabled(false), m_rewindAfterPlaybackEnabled(true), m_fitToFlipbookEnabled(false), m_previewAlwaysOpenNewFlipEnabled(false), m_autosaveEnabled(false), m_defaultViewerEnabled(false), m_saveUnpaintedInCleanup(true), m_askForOverrideRender(true), m_automaticSVNFolderRefreshEnabled(true), m_SVNEnabled(false), m_minimizeSaveboxAfterEditing(true), m_levelsBackupEnabled(false), m_sceneNumberingEnabled(false), m_animationSheetEnabled(false), m_inksOnly(false), m_fillOnlySavebox(false), m_show0ThickLines(true), m_regionAntialias(false), m_viewerBGColor(128, 128, 128, 255), m_previewBGColor(64, 64, 64, 255), m_chessboardColor1(180, 180, 180), m_chessboardColor2(230, 230, 230), m_showRasterImagesDarkenBlendedInViewer(false), m_actualPixelViewOnSceneEditingMode(false), m_viewerZoomCenter(0), m_initialLoadTlvCachingBehavior(0), m_removeSceneNumberFromLoadedLevelName(false), m_replaceAfterSaveLevelAs(true), m_showFrameNumberWithLetters(false), m_levelNameOnEachMarker(false), m_columnIconLoadingPolicy((int)LoadAtOnce), m_moveCurrentFrameByClickCellArea(true), m_onionSkinEnabled(false), m_multiLayerStylePickerEnabled(false), m_paletteTypeOnLoadRasterImageAsColorModel(0), m_showKeyframesOnXsheetCellArea(true)
{
	TCamera camera;
	m_defLevelType = PLI_XSHLEVEL;
	m_defLevelWidth = camera.getSize().lx;
	m_defLevelHeight = camera.getSize().ly;
	m_defLevelDpi = camera.getDpi().x;

	TFilePath layoutDir = ToonzFolder::getMyModuleDir();
	TFilePath savePath = layoutDir + TFilePath("preferences.ini");

	m_settings.reset(new QSettings(QString::fromStdWString(savePath.getWideString()),
								   QSettings::IniFormat));

	getValue(*m_settings, "autoExposeEnabled", m_autoExposeEnabled);
	getValue(*m_settings, "autoCreateEnabled", m_autoCreateEnabled);
	getValue(*m_settings, "subsceneFolderEnabled", m_subsceneFolderEnabled);
	getValue(*m_settings, "generatedMovieViewEnabled", m_generatedMovieViewEnabled);
	getValue(*m_settings, "xsheetAutopanEnabled", m_xsheetAutopanEnabled);
	getValue(*m_settings, "ignoreAlphaonColumn1Enabled", m_ignoreAlphaonColumn1Enabled);
	getValue(*m_settings, "rewindAfterPlayback", m_rewindAfterPlaybackEnabled);
	getValue(*m_settings, "previewAlwaysOpenNewFlip", m_previewAlwaysOpenNewFlipEnabled);
	getValue(*m_settings, "fitToFlipbook", m_fitToFlipbookEnabled);
	getValue(*m_settings, "automaticSVNFolderRefreshEnabled", m_automaticSVNFolderRefreshEnabled);
	getValue(*m_settings, "SVNEnabled", m_SVNEnabled);
	getValue(*m_settings, "minimizeSaveboxAfterEditing", m_minimizeSaveboxAfterEditing);
	getValue(*m_settings, "levelsBackupEnabled", m_levelsBackupEnabled);
	getValue(*m_settings, "sceneNumberingEnabled", m_sceneNumberingEnabled);
	getValue(*m_settings, "animationSheetEnabled", m_animationSheetEnabled);
	getValue(*m_settings, "autosaveEnabled", m_autosaveEnabled);
	getValue(*m_settings, "defaultViewerEnabled", m_defaultViewerEnabled);
	getValue(*m_settings, "rasterOptimizedMemory", m_rasterOptimizedMemory);
	getValue(*m_settings, "saveUnpaintedInCleanup", m_saveUnpaintedInCleanup);
	getValue(*m_settings, "autosavePeriod", m_autosavePeriod);
	getValue(*m_settings, "taskchunksize", m_chunkSize);
	getValue(*m_settings, "xsheetStep", m_xsheetStep);

	int r = 0, g = 0, b = 0;
	getValue(*m_settings, "frontOnionColor.r", r);
	getValue(*m_settings, "frontOnionColor.g", g);
	getValue(*m_settings, "frontOnionColor.b", b);
	m_frontOnionColor = TPixel32(r, g, b);

	getValue(*m_settings, "onionPaperThickness", m_onionPaperThickness);

	r = 0, g = 0, b = 0;
	getValue(*m_settings, "backOnionColor.r", r);
	getValue(*m_settings, "backOnionColor.g", g);
	getValue(*m_settings, "backOnionColor.b", b);
	m_backOnionColor = TPixel32(r, g, b);

	r = m_transpCheckBg.r, g = m_transpCheckBg.g, b = m_transpCheckBg.b;
	getValue(*m_settings, "transpCheckInkOnBlack.r", r);
	getValue(*m_settings, "transpCheckInkOnBlack.g", g);
	getValue(*m_settings, "transpCheckInkOnBlack.b", b);
	m_transpCheckBg = TPixel32(r, g, b);

	r = m_transpCheckInk.r, g = m_transpCheckInk.g, b = m_transpCheckInk.b;
	getValue(*m_settings, "transpCheckInkOnWhite.r", r);
	getValue(*m_settings, "transpCheckInkOnWhite.g", g);
	getValue(*m_settings, "transpCheckInkOnWhite.b", b);
	m_transpCheckInk = TPixel32(r, g, b);
	r = m_transpCheckPaint.r, g = m_transpCheckPaint.g, b = m_transpCheckPaint.b;
	getValue(*m_settings, "transpCheckPaint.r", r);
	getValue(*m_settings, "transpCheckPaint.g", g);
	getValue(*m_settings, "transpCheckPaint.b", b);
	m_transpCheckPaint = TPixel32(r, g, b);

	getValue(*m_settings, "onionInksOnly", m_inksOnly);
	getValue(*m_settings, "iconSizeX", m_iconSize.lx);
	getValue(*m_settings, "iconSizeY", m_iconSize.ly);
	getValue(*m_settings, s_show0ThickLines, m_show0ThickLines);
	getValue(*m_settings, s_regionAntialias, m_regionAntialias);
	getValue(*m_settings, "viewShrink", m_shrink);
	getValue(*m_settings, "viewStep", m_step);
	getValue(*m_settings, "blanksCount", m_blanksCount);
	getValue(*m_settings, "askForOverrideRender", m_askForOverrideRender);
	r = 255, g = 255, b = 255;
	getValue(*m_settings, "blankColor.r", r);
	getValue(*m_settings, "blankColor.g", g);
	getValue(*m_settings, "blankColor.b", b);
	getValue(*m_settings, "undoMemorySize", m_undoMemorySize);
	setUndoMemorySize(m_undoMemorySize);
	m_blankColor = TPixel32(r, g, b);

	QString units;
	units = m_settings->value("linearUnits").toString();
	if (units != "")
		m_units = units;
	setUnits(m_units.toStdString());

	units = m_settings->value("cameraUnits").toString();
	if (units != "")
		m_cameraUnits = units;
	setCameraUnits(m_cameraUnits.toStdString());

	getValue(*m_settings, "keyframeType", m_keyframeType);

	getValue(*m_settings, "animationStep", m_animationStep);

	getValue(*m_settings, "textureSize", m_textureSize);
	QString scanLevelType;
	scanLevelType = m_settings->value("scanLevelType").toString();
	if (scanLevelType != "")
		m_scanLevelType = scanLevelType;
	setScanLevelType(m_scanLevelType.toStdString());

	getValue(*m_settings, "shmmax", m_shmmax);
	getValue(*m_settings, "shmseg", m_shmseg);
	getValue(*m_settings, "shmall", m_shmall);
	getValue(*m_settings, "shmmni", m_shmmni);

	// Load level formats
	getDefaultLevelFormats(m_levelFormats);
	getValue(*m_settings, m_levelFormats);
	std::sort(m_levelFormats.begin(), m_levelFormats.end(), // Format sorting must be
			  formatLess);									// enforced

	TFilePath lang_path = TEnv::getConfigDir() + "loc";
	TFilePathSet lang_fpset;
	m_languageMaps[0] = "english";
	//m_currentLanguage=0;
	try {
		TFileStatus langPathFs(lang_path);

		if (langPathFs.doesExist() && langPathFs.isDirectory()) {
			TSystem::readDirectory(lang_fpset, lang_path, true, false);
		} else {
		}
		TFilePathSet::iterator it = lang_fpset.begin();

		int i = 1;
		for (it; it != lang_fpset.end(); it++, i++) {
			TFilePath newPath = *it;
			if (newPath == lang_path)
				continue;
			if (TFileStatus(newPath).isDirectory()) {
				QString string = QString::fromStdWString(newPath.getWideName());
				m_languageMaps[i] = string;
			}
		}
	} catch (...) {
	}

	TFilePath path(TEnv::getConfigDir() + "qss");
	TFilePathSet fpset;
	try {
		TSystem::readDirectory(fpset, path, true, false);
		TFilePathSet::iterator it = fpset.begin();
		int i = 0;
		for (it; it != fpset.end(); it++, i++) {
			TFilePath newPath = *it;
			if (newPath == path)
				continue;
			QString fpName = QString::fromStdWString(newPath.getWideName());
#ifdef MACOSX
			QString string = fpName + QString("/") + fpName + QString("_mac.qss");
#else
			QString string = fpName + QString("/") + fpName + QString(".qss");
#endif
			if (fpName == QString("standard"))
				m_currentStyleSheet = i;
			m_styleSheetMaps[i] = "file:///" + path.getQString() + "/" + string;
		}
	} catch (...) {
	}

	getValue(*m_settings, "CurrentLanguage", m_currentLanguage);
	getValue(*m_settings, "CurrentStyleSheet", m_currentStyleSheet);
	getValue(*m_settings, "DragCellsBehaviour", m_dragCellsBehaviour);

	getValue(*m_settings, "LineTestFpsCapture", m_lineTestFpsCapture);
	getValue(*m_settings, "FillOnlysavebox", m_fillOnlySavebox);
	getValue(*m_settings, "AutocreationType", m_autocreationType);
	getValue(*m_settings, "DefLevelType", m_defLevelType);
	getValue(*m_settings, "DefLevelWidth", m_defLevelWidth);
	getValue(*m_settings, "DefLevelHeight", m_defLevelHeight);
	getValue(*m_settings, "DefLevelDpi", m_defLevelDpi);

	getValue(*m_settings, "viewerBGColor", m_viewerBGColor);
	getValue(*m_settings, "previewBGColor", m_previewBGColor);
	getValue(*m_settings, "chessboardColor1", m_chessboardColor1);
	getValue(*m_settings, "chessboardColor2", m_chessboardColor2);
	getValue(*m_settings, "showRasterImagesDarkenBlendedInViewer", m_showRasterImagesDarkenBlendedInViewer);
	getValue(*m_settings, "actualPixelViewOnSceneEditingMode", m_actualPixelViewOnSceneEditingMode);
	getValue(*m_settings, "viewerZoomCenter", m_viewerZoomCenter);
	getValue(*m_settings, "initialLoadTlvCachingBehavior", m_initialLoadTlvCachingBehavior);
	getValue(*m_settings, "removeSceneNumberFromLoadedLevelName", m_removeSceneNumberFromLoadedLevelName);
	getValue(*m_settings, "replaceAfterSaveLevelAs", m_replaceAfterSaveLevelAs);
	getValue(*m_settings, "showFrameNumberWithLetters", m_showFrameNumberWithLetters);
	getValue(*m_settings, "levelNameOnEachMarkerEnabled", m_levelNameOnEachMarker);
	getValue(*m_settings, "columnIconLoadingPolicy", m_columnIconLoadingPolicy);
	getValue(*m_settings, "moveCurrentFrameByClickCellArea", m_moveCurrentFrameByClickCellArea);
	getValue(*m_settings, "onionSkinEnabled", m_onionSkinEnabled);
	getValue(*m_settings, "multiLayerStylePickerEnabled", m_multiLayerStylePickerEnabled);
	getValue(*m_settings, "paletteTypeOnLoadRasterImageAsColorModel", m_paletteTypeOnLoadRasterImageAsColorModel);
	getValue(*m_settings, "showKeyframesOnXsheetCellArea", m_showKeyframesOnXsheetCellArea);
}
Q_INVOKABLE QScriptValue Rasterizer::rasterize(QScriptValue arg) {
  Image *img        = qscriptvalue_cast<Image *>(arg);
  Level *level      = qscriptvalue_cast<Level *>(arg);
  TPalette *palette = 0;
  if (img) {
    if (img->getType() != "Vector")
      return context()->throwError(
          tr("Expected a vector image: %1").arg(arg.toString()));
    palette = !!img->getImg() ? img->getImg()->getPalette() : 0;
  } else if (level) {
    if (level->getType() != "Vector")
      return context()->throwError(
          tr("Expected a vector level: %1").arg(arg.toString()));
    palette =
        level->getSimpleLevel() ? level->getSimpleLevel()->getPalette() : 0;
  } else {
    return context()->throwError(
        tr("Argument must be a vector level or image : ").arg(arg.toString()));
  }
  if (!palette) {
    return context()->throwError(tr("%1 has no palette").arg(arg.toString()));
  }

  TDimension res(m_xres, m_yres);
  TCamera camera;
  camera.setRes(res);
  camera.setSize(TDimensionD(m_xres / m_dpi, m_yres / m_dpi));
  TPointD dpi = camera.getDpi();
  TAffine aff = camera.getStageToCameraRef();

  QScriptValue result;
  int n               = 0;
  TXshSimpleLevel *sl = 0;
  if (level) {
    result = create(engine(), new Level());
    n      = level->getFrameCount();
    sl     = level->getSimpleLevel();
  }

  if (m_colorMapped) {
    // vector -> toonz image
    if (img) {
      TImageP outImg = vectorToToonzRaster(img->getImg(), res, aff, dpi);
      result         = create(engine(), new Image(outImg));
    } else {
      for (int i = 0; i < n; i++) {
        TFrameId fid    = sl->index2fid(i);
        TImageP drawing = sl->getFrame(fid, false);
        TImageP outImg  = vectorToToonzRaster(drawing, res, aff, dpi);
        setFrame(engine(), result, fid, outImg);
      }
    }
  } else {
    // vector -> full color
    TPixel32 bgColor = TPixel32::White;

    TOfflineGL *glContext = new TOfflineGL(res);
    glContext->makeCurrent();

    TVectorRenderData rd(TVectorRenderData::ProductionSettings(), aff, TRect(),
                         palette);
    rd.m_antiAliasing = m_antialiasing;

    if (img) {
      TImageP outImg =
          renderVectorImage(glContext, rd, dpi, img->getImg(), bgColor);
      result = create(engine(), new Image(outImg));
    } else {
      for (int i = 0; i < n; i++) {
        TFrameId fid    = sl->index2fid(i);
        TImageP drawing = sl->getFrame(fid, false);
        glContext->clear(TPixel32::White);
        TImageP outImg =
            renderVectorImage(glContext, rd, dpi, drawing, bgColor);
        setFrame(engine(), result, fid, outImg);
      }
    }
    delete glContext;
  }

  return result;
}