示例#1
0
	void undo() const
	{
		TXshSimpleLevel *sl = getLevel();
		if (!sl)
			return;
		TRasterImageP ri = sl->getFrame(m_fid, true);
		if (!ri)
			return;

		TRasterImageP oldRaster = TImageCache::instance()->get(m_rasId, false);
		ri->getRaster()->copy(oldRaster->getRaster());
		notify(sl);
	}
示例#2
0
	void redo() const
	{
		TXshSimpleLevel *sl = getLevel();
		if (!sl)
			return;
		TRasterImageP ri = sl->getFrame(m_fid, true);
		if (!ri)
			return;
		TRaster32P ras = ri->getRaster();
		if (!ras)
			return;
		TBinarizer binarizer;
		binarizer.enableAlpha(m_alphaEnabled);
		binarizer.process(ras);
		notify(sl);
	}
示例#3
0
int BinarizePopup::getSelectedFrames()
{
	m_frames.clear();
	TSelection *selection = TSelection::getCurrent();
	TCellSelection *cellSelection;
	TFilmstripSelection *filmstripSelection;
	int count = 0;
	if ((cellSelection = dynamic_cast<TCellSelection *>(selection))) {
		std::set<TRasterImage *> images;
		int r0, c0, r1, c1;
		cellSelection->getSelectedCells(r0, c0, r1, c1);
		TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet();
		int c, r;
		for (c = c0; c <= c1; c++) {
			for (r = r0; r <= r1; r++) {
				TXshCell cell = xsheet->getCell(r, c);
				TRasterImageP rasImage = cell.getImage(false);
				if (!rasImage || !rasImage->getRaster())
					continue;
				Frames::value_type item(cell.getSimpleLevel(), cell.getFrameId());
				Frames::iterator it;
				it = std::lower_bound(m_frames.begin(), m_frames.end(), item);
				if (it == m_frames.end() || *it != item) {
					m_frames.insert(it, item);
					count++;
				}
			}
		}
	} else if ((filmstripSelection = dynamic_cast<TFilmstripSelection *>(selection))) {
		TXshSimpleLevel *sl = TApp::instance()->getCurrentLevel()->getSimpleLevel();
		if (sl) {
			std::set<TFrameId> fids = filmstripSelection->getSelectedFids();
			std::set<TFrameId>::iterator it;
			for (it = fids.begin(); it != fids.end(); ++it) {
				TRasterImageP rasImage = sl->getFrame(*it, false);
				if (!!rasImage && !!rasImage->getRaster()) {
					m_frames.push_back(std::make_pair(sl, *it));
					count++;
				}
			}
		}
	} else {
	}
	m_frameIndex = 0;
	return count;
}
示例#4
0
void BinarizePopup::apply()
{
	if (getSelectedFrames() <= 0) {
		DVGui::error(tr("No raster frames selected"));
		return;
	}

	DVGui::ProgressDialog pd(tr("Binarizing images"), tr("Cancel"), 0, (int)m_frames.size(), 0);
	pd.show();
	qApp->processEvents();

	TBinarizer binarizer;
	binarizer.enableAlpha(!!m_alphaChk->checkState());

	TUndoManager::manager()->beginBlock();
	int count = 0;
	Frames::iterator it;
	for (it = m_frames.begin(); it != m_frames.end(); ++it) {
		TXshSimpleLevel *sl = it->first;
		if (!!m_alphaChk->checkState())
			sl->getProperties()->setHasAlpha(true);
		TFrameId fid = it->second;
		TBinarizeUndo *undo = new TBinarizeUndo(sl, fid, binarizer.isAlphaEnabled());
		TUndoManager::manager()->add(undo);
		TRasterImageP ri = sl->getFrame(fid, true);
		if (!ri)
			continue; // should never happen
		TRaster32P ras32 = ri->getRaster();
		if (!ras32)
			continue; // not yet handled
		binarizer.process(ras32);
		pd.setValue(count++);
		qApp->processEvents();
		sl->touchFrame(fid);
		sl->setDirtyFlag(true);
		IconGenerator::instance()->invalidate(sl, fid);
	}
	TUndoManager::manager()->endBlock();
	TApp::instance()->getCurrentLevel()->notifyLevelChange();
	TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
}
void AntialiasPopup::setCurrentSampleRaster()
{
	TRasterP sampleRas;

	m_startRas = TRasterP();
	TSelection *selection = TApp::instance()->getCurrentSelection()->getSelection();
	TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(selection);
	TFilmstripSelection *filmstripSelection = dynamic_cast<TFilmstripSelection *>(selection);
	TImageP image;
	if (cellSelection) {
		TApp *app = TApp::instance();
		TXsheet *xsh = app->getCurrentXsheet()->getXsheet();
		TXshCell cell = xsh->getCell(app->getCurrentFrame()->getFrameIndex(), app->getCurrentColumn()->getColumnIndex());
		TImageP aux = cell.getImage(true);
		if (aux)
			image = aux->cloneImage();
	} else if (filmstripSelection) {
		TApp *app = TApp::instance();
		TXshSimpleLevel *simpleLevel = app->getCurrentLevel()->getSimpleLevel();
		if (simpleLevel) {
			TImageP imageAux = simpleLevel->getFrame(app->getCurrentFrame()->getFid(), true);
			if (imageAux)
				image = imageAux->cloneImage();
		}
	}

	if (!image || !(sampleRas = image->raster())) {
		m_viewer->setImage(TImageP());
		m_viewer->update();
		m_okBtn->setEnabled(false);
		return;
	}

	m_okBtn->setEnabled(true);
	m_startRas = sampleRas->clone();
	onChange(m_startRas, sampleRas, m_thresholdField->getValue(), m_softnessField->getValue());

	m_viewer->setImage(image);
	m_viewer->update();
}
void AdjustLevelsPopup::acquireRaster()
{
	//Retrieve current selection
	TApp *app = TApp::instance();
	TSelection *selection = app->getCurrentSelection()->getSelection();
	TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(selection);
	TFilmstripSelection *filmstripSelection = dynamic_cast<TFilmstripSelection *>(selection);

	//Retrieve the input raster
	m_inputRas = TRasterP();
	if (cellSelection) {
		TXsheet *xsh = app->getCurrentXsheet()->getXsheet();
		TXshCell cell = xsh->getCell(app->getCurrentFrame()->getFrameIndex(), app->getCurrentColumn()->getColumnIndex());
		TRasterImageP rasImage = cell.getImage(true);
		if (rasImage && rasImage->getRaster())
			m_inputRas = rasImage->getRaster();
	} else if (filmstripSelection) {
		TXshSimpleLevel *simpleLevel = app->getCurrentLevel()->getSimpleLevel();
		if (simpleLevel) {
			TRasterImageP rasImage = (TRasterImageP)simpleLevel->getFrame(app->getCurrentFrame()->getFid(), true);
			if (rasImage && rasImage->getRaster())
				m_inputRas = rasImage->getRaster();
		}
	}

	if (m_inputRas) {
		m_threshold = m_inputRas->getLx() * m_inputRas->getLy() * m_thresholdD;
		m_okBtn->setEnabled(true);
	} else {
		m_inputRas = TRasterP();
		m_okBtn->setEnabled(false);
	}

	//Build histograms
	m_histogram->setRaster(m_inputRas);

	//Update the corresponding processed image in the viewer
	updateProcessedImage();
}
示例#7
0
void BinarizePopup::fetchSample()
{
	TApp *app = TApp::instance();
	TImageP img;
	if (app->getCurrentFrame()->isEditingLevel()) {
		TXshLevel *xshLevel = app->getCurrentLevel()->getLevel();
		if (xshLevel && xshLevel->getSimpleLevel()) {
			TXshSimpleLevel *sl = xshLevel->getSimpleLevel();
			img = sl->getFrame(app->getCurrentFrame()->getFid(), false);
		}
	} else {
		TXsheet *xsh = app->getCurrentScene()->getScene()->getXsheet();
		TXshCell cell = xsh->getCell(app->getCurrentFrame()->getFrame(), app->getCurrentColumn()->getColumnIndex());
		img = cell.getImage(false);
	}
	TRasterImageP ri = img;
	if (ri) {
		setSample(ri->getRaster());
	} else {
		setSample(TRasterP());
	}
}
void BrightnessAndContrastPopup::setCurrentSampleRaster()
{
	TRasterP sampleRas;

	m_startRas = TRasterP();
	TSelection *selection = TApp::instance()->getCurrentSelection()->getSelection();
	TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(selection);
	TFilmstripSelection *filmstripSelection = dynamic_cast<TFilmstripSelection *>(selection);
	if (cellSelection) {
		TApp *app = TApp::instance();
		TXsheet *xsh = app->getCurrentXsheet()->getXsheet();
		TXshCell cell = xsh->getCell(app->getCurrentFrame()->getFrameIndex(), app->getCurrentColumn()->getColumnIndex());
		TRasterImageP rasImage = cell.getImage(true);
		if (rasImage && rasImage->getRaster())
			sampleRas = rasImage->getRaster()->clone();
	} else if (filmstripSelection) {
		TApp *app = TApp::instance();
		TXshSimpleLevel *simpleLevel = app->getCurrentLevel()->getSimpleLevel();
		if (simpleLevel) {
			TRasterImageP rasImage = (TRasterImageP)simpleLevel->getFrame(app->getCurrentFrame()->getFid(), true);
			if (rasImage && rasImage->getRaster())
				sampleRas = rasImage->getRaster()->clone();
		}
	}
	if (!sampleRas) {
		m_viewer->raster() = TRasterP();
		m_viewer->update();
		m_okBtn->setEnabled(false);
		return;
	}

	m_okBtn->setEnabled(true);
	m_startRas = sampleRas->clone();
	onChange(m_startRas, sampleRas, m_contrastField->getValue(), m_brightnessField->getValue());

	m_viewer->raster() = sampleRas;
	m_viewer->update();
}
void AntialiasPopup::apply()
{
	TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(TSelection::getCurrent());
	int threshold = m_thresholdField->getValue();
	int softness = m_softnessField->getValue();
	if (cellSelection) {
		std::set<TImage *> images;
		int r0, c0, r1, c1;
		cellSelection->getSelectedCells(r0, c0, r1, c1);
		TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet();
		bool oneImageChanged = false;
		int c, r;
		TUndoManager::manager()->beginBlock();
		for (c = c0; c <= c1; c++)
			for (r = r0; r <= r1; r++) {
				TXshCell cell = xsheet->getCell(r, c);
				TImageP image = cell.getImage(true);
				if (!image)
					continue;
				if (images.find(image.getPointer()) != images.end())
					continue;
				TRasterP ras = image->raster();
				if (!ras)
					continue;
				images.insert(image.getPointer());
				oneImageChanged = true;
				TUndoManager::manager()->add(new TRasterAntialiasUndo(threshold, softness, r, c, ras->clone()));
				onChange(ras, threshold, softness);
				TXshSimpleLevel *simpleLevel = cell.getSimpleLevel();
				assert(simpleLevel);
				simpleLevel->touchFrame(cell.getFrameId());
				simpleLevel->setDirtyFlag(true);
				IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId());
			}
		TUndoManager::manager()->endBlock();
		if (oneImageChanged) {
			close();
			return;
		}
	}
	TFilmstripSelection *filmstripSelection = dynamic_cast<TFilmstripSelection *>(TSelection::getCurrent());
	if (filmstripSelection) {
		TXshSimpleLevel *simpleLevel = TApp::instance()->getCurrentLevel()->getSimpleLevel();
		if (simpleLevel) {
			std::set<TFrameId> fids = filmstripSelection->getSelectedFids();
			std::set<TFrameId>::iterator it = fids.begin();
			bool oneImageChanged = false;
			for (it; it != fids.end(); it++) {
				TImageP image = simpleLevel->getFrame(*it, true);
				if (!image)
					continue;
				TRasterP ras = image->raster();
				if (!ras)
					continue;
				oneImageChanged = true;
				onChange(ras, threshold, softness);
				simpleLevel->touchFrame(*it);
				simpleLevel->setDirtyFlag(true);
				IconGenerator::instance()->invalidate(simpleLevel, *it);
			}
			if (oneImageChanged) {
				close();
				return;
			}
		}
	}

	DVGui::error(QObject::tr("The current selection is invalid."));
	return;
}
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;
}
void AdjustLevelsPopup::apply()
{
	//Retrieve parameters
	int in0[5], in1[5], out0[5], out1[5];
	getParameters(in0, in1, out0, out1);

	//Operate depending on the selection kind
	TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(TSelection::getCurrent());
	if (cellSelection) {
		std::set<TRasterImage *> images; //Multiple cells may yield the same image...

		int r0, c0, r1, c1;
		cellSelection->getSelectedCells(r0, c0, r1, c1);
		TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet();
		bool oneImageChanged = false;

		TUndoManager::manager()->beginBlock();
		{
			int c, r;
			for (c = c0; c <= c1; c++) {
				for (r = r0; r <= r1; r++) {
					const TXshCell &cell = xsheet->getCell(r, c);

					TRasterImageP rasImage = (TRasterImageP)cell.getImage(true);
					if (!rasImage)
						continue;

					if (images.find(rasImage.getPointer()) != images.end())
						continue;

					TRasterP ras = rasImage->getRaster();
					if (!ras)
						continue;

					images.insert(rasImage.getPointer());
					oneImageChanged = true;

					TUndoManager::manager()->add(new AdjustLevelsUndo(in0, in1, out0, out1, r, c, ras->clone()));
					TRop::rgbmAdjust(ras, ras, in0, in1, out0, out1);

					TXshSimpleLevel *simpleLevel = cell.getSimpleLevel();
					assert(simpleLevel);
					simpleLevel->touchFrame(cell.getFrameId());
					simpleLevel->setDirtyFlag(true);

					IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId());
				}
			}
		}
		TUndoManager::manager()->endBlock();

		if (oneImageChanged) {
			close();
			return;
		}
	}

	TFilmstripSelection *filmstripSelection = dynamic_cast<TFilmstripSelection *>(TSelection::getCurrent());
	if (filmstripSelection) {
		TXshSimpleLevel *simpleLevel = TApp::instance()->getCurrentLevel()->getSimpleLevel();
		if (simpleLevel) {
			std::set<TFrameId> fids = filmstripSelection->getSelectedFids();
			bool oneImageChanged = false;

			std::set<TFrameId>::iterator it = fids.begin();
			for (it; it != fids.end(); it++) {
				TRasterImageP rasImage = (TRasterImageP)simpleLevel->getFrame(*it, true);
				if (!rasImage)
					continue;

				TRasterP ras = rasImage->getRaster();
				if (!ras)
					continue;

				oneImageChanged = true;
				TRop::rgbmAdjust(ras, ras, in0, in1, out0, out1);

				simpleLevel->touchFrame(*it);
				simpleLevel->setDirtyFlag(true);

				IconGenerator::instance()->invalidate(simpleLevel, *it);
			}

			if (oneImageChanged) {
				close();
				return;
			}
		}
	}

	DVGui::error(QObject::tr("The current selection is invalid."));
	return;
}
示例#12
0
void LinesFadePopup::apply()
{
	TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(TSelection::getCurrent());
	TPixel32 color = m_linesColorField->getColor();
	int intensity = m_intensity->getValue();

	if (cellSelection) {
		std::set<TRasterImage *> images;
		int r0, c0, r1, c1;
		cellSelection->getSelectedCells(r0, c0, r1, c1);
		TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet();
		bool oneImageChanged = false;
		int c, r;
		TUndoManager::manager()->beginBlock();
		for (c = c0; c <= c1; c++)
			for (r = r0; r <= r1; r++) {
				TXshCell cell = xsheet->getCell(r, c);
				TRasterImageP rasImage = (TRasterImageP)cell.getImage(true);
				if (!rasImage)
					continue;
				if (images.find(rasImage.getPointer()) != images.end())
					continue;
				TRaster32P ras = rasImage->getRaster();
				if (!ras)
					continue;
				images.insert(rasImage.getPointer());
				TUndoManager::manager()->add(new TLineFadeUndo(color, intensity, r, c, ras->clone()));
				oneImageChanged = true;
				onChange(ras, ras, color, intensity);
				TXshSimpleLevel *simpleLevel = cell.getSimpleLevel();
				assert(simpleLevel);
				simpleLevel->touchFrame(cell.getFrameId());
				simpleLevel->setDirtyFlag(true);
				IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId());
			}
		TUndoManager::manager()->endBlock();
		images.clear();
		if (oneImageChanged) {
			close();
			return;
		}
	}
	TFilmstripSelection *filmstripSelection = dynamic_cast<TFilmstripSelection *>(TSelection::getCurrent());
	if (filmstripSelection) {
		TXshSimpleLevel *simpleLevel = TApp::instance()->getCurrentLevel()->getSimpleLevel();
		if (simpleLevel) {
			std::set<TFrameId> fids = filmstripSelection->getSelectedFids();
			bool oneImageChanged = false;
			for (auto const& fid : fids) {
				TRasterImageP rasImage = (TRasterImageP)simpleLevel->getFrame(fid, true);
				;
				if (!rasImage)
					continue;
				TRaster32P ras = rasImage->getRaster();
				if (!ras)
					continue;
				oneImageChanged = true;
				onChange(ras, ras, color, intensity);
				simpleLevel->touchFrame(fid);
				simpleLevel->setDirtyFlag(true);
				IconGenerator::instance()->invalidate(simpleLevel, fid);
			}
			if (oneImageChanged) {
				close();
				return;
			}
		}
	}

	DVGui::error(QObject::tr("The current selection is invalid."));
	return;
}
示例#13
0
TImage *TTool::touchImage() {
  if (!m_application) return 0;

  m_cellsData.clear();

  m_isLevelCreated  = false;
  m_isFrameCreated  = false;
  Preferences *pref = Preferences::instance();

  bool isAutoCreateEnabled   = pref->isAutoCreateEnabled();
  bool animationSheetEnabled = pref->isAnimationSheetEnabled();
  bool isAutoStretchEnabled  = pref->isAutoStretchEnabled();

  TFrameHandle *currentFrame    = m_application->getCurrentFrame();
  TXshLevelHandle *currentLevel = m_application->getCurrentLevel();

  if (currentFrame->isEditingLevel()) {
    // Editing level

    // no level => return 0
    TXshLevel *xl = currentLevel->getLevel();
    if (!xl) return 0;
    TXshSimpleLevel *sl = xl->getSimpleLevel();
    if (!sl || sl->isEmpty()) return 0;

    TFrameId fid = currentFrame->getFid();
    TImageP img  = sl->getFrame(fid, true);
    if (!img) {
      // no drawing found
      if (sl->isSubsequence() || sl->isReadOnly() || !isAutoCreateEnabled)
        return 0;

      // create a new drawing
      img = sl->createEmptyFrame();
      sl->setFrame(fid, img);
      currentLevel->notifyLevelChange();
      m_isFrameCreated = true;
    }
    return img.getPointer();
  } else {
    // editing xsheet
    if (m_application->getCurrentObject()->isSpline()) return 0;

    TSceneHandle *currentScene = m_application->getCurrentScene();
    ToonzScene *scene          = currentScene->getScene();
    int row                    = currentFrame->getFrame();
    int col = m_application->getCurrentColumn()->getColumnIndex();
    if (col < 0) return 0;

    TXsheetHandle *currentXsheet = m_application->getCurrentXsheet();
    TXsheet *xsh                 = currentXsheet->getXsheet();
    if (!xsh) return 0;

    TXshCell cell       = xsh->getCell(row, col);
    TXshSimpleLevel *sl = cell.getSimpleLevel();

    if (sl != 0) {
      // current cell is not empty
      if (isAutoCreateEnabled && animationSheetEnabled && row > 0 &&
          xsh->getCell(row - 1, col) == xsh->getCell(row, col)) {
        // animationSheet is enabled and the current cell is a "hold". We must
        // create a new drawing.
        // measure the hold length (starting from the current row) : r0-r1
        int r0 = row, r1 = row;
        if (isAutoStretchEnabled)
          while (xsh->getCell(r1 + 1, col) == cell) r1++;
        // find the proper frameid (possibly addisng suffix, in order to avoid a
        // fid already used)
        TFrameId fid = getNewFrameId(sl, row);
        // create the new drawing
        TImageP img      = sl->createEmptyFrame();
        m_isFrameCreated = true;
        // insert the drawing in the level
        sl->setFrame(fid, img);
        // update the cell
        cell = TXshCell(sl, fid);
        // update the xsheet (change the current cell and possibly all the
        // following "hold")
        for (int r = r0; r <= r1; r++) xsh->setCell(r, col, cell);
        // notify
        currentXsheet->notifyXsheetChanged();
        currentScene->notifyCastChange();
        currentLevel->notifyLevelChange();
        m_cellsData.push_back(r0);
        m_cellsData.push_back(r1);
        m_cellsData.push_back(0);
      }
      // we've found the image. return it.
      return cell.getImage(true).getPointer();
    }

    // current cell is empty.
    if (!isAutoCreateEnabled) return 0;

    // get the column range
    int r0, r1;
    xsh->getCellRange(col, r0, r1);

    if (animationSheetEnabled && r0 <= r1) {
      // animation sheet enabled and not empty column. We must create a new
      // drawing in the column level and possibly add "holds"

      // find the last not-empty cell before the current one (a) and the first
      // after (b)
      int a = row - 1, b = row + 1;
      while (a >= r0 && xsh->getCell(a, col).isEmpty()) a--;
      while (b <= r1 && xsh->getCell(b, col).isEmpty()) b++;

      // find the level we must attach to
      if (a >= r0) {
        // there is a not-emtpy cell before the current one
        sl = xsh->getCell(a, col).getSimpleLevel();
      } else if (b <= r1) {
        sl = xsh->getCell(b, col).getSimpleLevel();
      }
      if (sl) {
        // note: sl should be always !=0 (the column is not empty)
        // if - for some reason - it is ==0 then we skip to the standard (i.e.
        // !animationSheetEnabled) beahviour

        // create the drawing
        // find the proper frameid (possibly addisng suffix, in order to avoid a
        // fid already used)
        TFrameId fid = getNewFrameId(sl, row);
        // create the new drawing
        TImageP img      = sl->createEmptyFrame();
        m_isFrameCreated = true;
        // insert the drawing in the level
        sl->setFrame(fid, img);
        // update the cell
        cell = TXshCell(sl, fid);
        xsh->setCell(row, col, cell);

        // create holds
        if (!isAutoStretchEnabled) {
          m_cellsData.push_back(row);
          m_cellsData.push_back(row);
          m_cellsData.push_back(2);  // vuoto => nuovo
        } else {
          if (a >= r0) {
            // create a hold before : [a+1, row-1]
            TXshCell aCell = xsh->getCell(a, col);
            for (int i = a + 1; i < row; i++) xsh->setCell(i, col, aCell);
            m_cellsData.push_back(a + 1);
            m_cellsData.push_back(row - 1);
            m_cellsData.push_back(1);  // vuoto => vecchio

            if (b <= r1 && xsh->getCell(b, col).getSimpleLevel() == sl) {
              // create also a hold after
              for (int i = row + 1; i < b; i++) xsh->setCell(i, col, cell);
              m_cellsData.push_back(row);
              m_cellsData.push_back(b - 1);
              m_cellsData.push_back(2);  // vuoto => nuovo
            } else {
              m_cellsData.push_back(row);
              m_cellsData.push_back(row);
              m_cellsData.push_back(2);  // vuoto => nuovo
            }
          } else if (b <= r1) {
            // create a hold after
            for (int i = row + 1; i < b; i++) xsh->setCell(i, col, cell);
            m_cellsData.push_back(row);
            m_cellsData.push_back(b - 1);
            m_cellsData.push_back(2);  // vuoto => nuovo
          }
        }
      }
      // notify & return
      currentXsheet->notifyXsheetChanged();
      currentScene->notifyCastChange();
      currentLevel->notifyLevelChange();
      return cell.getImage(true).getPointer();
    }

    if (row > 0 && xsh->getCell(row - 1, col).getSimpleLevel() != 0 &&
        !animationSheetEnabled) {
      sl = xsh->getCell(row - 1, col).getSimpleLevel();
      if (sl->getType() != OVL_XSHLEVEL ||
          sl->getPath().getFrame() != TFrameId::NO_FRAME) {
        // la cella precedente contiene un drawing di un livello. animationSheet
        // e' disabilitato
        // creo un nuovo frame
        currentLevel->setLevel(sl);
        if (sl->isSubsequence() || sl->isReadOnly()) return 0;
        TFrameId fid     = sl->index2fid(sl->getFrameCount());
        TImageP img      = sl->createEmptyFrame();
        m_isFrameCreated = true;
        sl->setFrame(fid, img);
        cell = TXshCell(sl, fid);
        xsh->setCell(row, col, cell);
        currentXsheet->notifyXsheetChanged();
        currentScene->notifyCastChange();
        currentLevel->notifyLevelChange();
        return img.getPointer();
      }
    }

    // animation sheet disabled or empty column. autoCreate is enabled: we must
    // create a new level
    int levelType    = pref->getDefLevelType();
    TXshLevel *xl    = scene->createNewLevel(levelType);
    sl               = xl->getSimpleLevel();
    m_isLevelCreated = true;

    // create the drawing
    TFrameId fid = animationSheetEnabled ? getNewFrameId(sl, row) : TFrameId(1);
    TImageP img  = sl->createEmptyFrame();
    m_isFrameCreated = true;
    sl->setFrame(fid, img);
    cell = TXshCell(sl, fid);
    xsh->setCell(row, col, cell);
    if (animationSheetEnabled) {
      m_cellsData.push_back(row);
      m_cellsData.push_back(row);
      m_cellsData.push_back(2);  // vuoto => nuovo
    }

    currentXsheet->notifyXsheetChanged();
    currentScene->notifyCastChange();
    currentLevel->notifyLevelChange();
    return img.getPointer();
  }
}