OpenToonz - An open-source full-featured 2D animation creation software
C
Fixes
janimatic037be87ba196
diff --git a/toonz/sources/toonz/ocaio.cpp b/toonz/sources/toonz/ocaio.cppindex f66253e49..64c0ec580 100644--- a/toonz/sources/toonz/ocaio.cpp+++ b/toonz/sources/toonz/ocaio.cpp@@ -531,7 +531,7 @@ void ExportOCACommand::execute() {/// <summary>/// OCA importer/// Roadmap:-/// - finish this basic importer+/// - test the case of child layer, add progress bar/// - add the option to update the current scene from OCA, importing only the missing layers/// (example : import a krita paint layer, but keep the tlv with their palette as smart rasters...)/// - keyframe animation transfert for camera, pegs, etc...@@ -569,7 +569,7 @@ void ImportOCACommand::execute() {}QString ocafile = fp.getQString();- OCAInputData ocaInputData = OCAInputData();+ OCAInputData ocaInputData = OCAInputData(0, true, false);QJsonObject ocaObject;if (!ocaInputData.load(ocafile, ocaObject)) {DVGui::warning(QObject::tr("Failed to load OCA file: ") +@@ -585,10 +585,14 @@ void ImportOCACommand::execute() {TApp::instance()->getCurrentScene()->notifySceneChanged();}-OCAIo::OCAInputData::OCAInputData() {- m_scene = TApp::instance()->getCurrentScene()->getScene();- m_xsheet = TApp::instance()->getCurrentXsheet()->getXsheet();- m_oprop = m_scene->getProperties()->getOutputProperties();+OCAIo::OCAInputData::OCAInputData(float antialiasSoftness, bool whiteTransp,+ bool doPremultiply) {+ m_antialiasSoftness = antialiasSoftness;+ m_whiteTransp = whiteTransp;+ m_doPremultiply = doPremultiply;+ m_scene = TApp::instance()->getCurrentScene()->getScene();+ m_xsheet = TApp::instance()->getCurrentXsheet()->getXsheet();+ m_oprop = m_scene->getProperties()->getOutputProperties();}bool OCAIo::OCAInputData::load(QString path, QJsonObject &json) {@@ -681,6 +685,10 @@ void OCAIo::OCAInputData::setSceneData() {size.ly = resolution.ly / m_dpi;m_scene->getCurrentCamera()->setSize(size, false, false);}+ //else {+ // TDimensionD size(16, 9);+ // m_scene->getCurrentCamera()->setSize(size, false, false);+ //}m_xsheet->updateFrameCount();m_oprop->setRange(m_startTime, m_endTime, 1);TPixel32 color = TPixel32(m_bgRed * 255.0, m_bgGreen * 255.0,@@ -693,10 +701,16 @@ void OCAIo::OCAInputData::setSceneData() {// TRenderSettings renderSettings = m_scene->getProperties()->getOutputProperties()->getRenderSettings(); // incomplete type ?// renderSettings.m_bpp...// https://github.com/RxLaboratory/OCA/blob/master/src-docs/docs/specs/color-depth.md- if (m_colorDepth == "U8") m_oprop->setNonlinearBpp(32);- else if (m_colorDepth == "U16") m_oprop->setNonlinearBpp(64);- else if (m_colorDepth == "F16") m_oprop->setNonlinearBpp(64);- else if (m_colorDepth == "U32") m_oprop->setNonlinearBpp(128);+ // only raises nonlinearBpp, never make it lower than it is... (the levels could be 8 bit but comp output higher)+ int nonlinearBpp = m_oprop->getNonlinearBpp();+ if (m_colorDepth == "U8" && nonlinearBpp < 32)+ m_oprop->setNonlinearBpp(32);+ else if (m_colorDepth == "U16" && nonlinearBpp < 64)+ m_oprop->setNonlinearBpp(64);+ else if (m_colorDepth == "F16" && nonlinearBpp < 64)+ m_oprop->setNonlinearBpp(64);+ else if (m_colorDepth == "U32" && nonlinearBpp < 128)+ m_oprop->setNonlinearBpp(128);}/// <summary>@@ -736,13 +750,47 @@ void OCAIo::OCAInputData::importOcaLayer(const QJsonObject &jsonLayer) {TXshLevel *level = m_scene->createNewLevel(levelType, jsonLayer["name"].toString().toStdWString(), resolution,m_dpi);+TXshSimpleLevel *sl = dynamic_cast<TXshSimpleLevel *>(level);- // we filmmakers don't use dpi ??- sl->getProperties()->setDpi(m_dpi);- sl->getProperties()->setDpiPolicy( LevelProperties::DP_CustomDpi);- sl->getProperties()->setWhiteTransp(m_whiteTransp);- sl->getProperties()->setDoPremultiply(m_doPremultiply);- sl->getProperties()->setDoAntialias(m_antialiasSoftness);+ // TXshLevel *ToonzScene::createNewLevel(int type, std::wstring levelName, const TDimension &dim, double dpi, TFilePath fp)+ // ignores the resolution argument !+ sl->getProperties()->setImageRes(resolution);++ // lookup the first frame to eventually load image format loading preferences which is based on frame extention+ // seeTXshLevel *ToonzScene::loadLevel+ // the problem is tahomastuff/profiles/users/[username]/preferences.ini doesn't add new image fomats to the list...+ auto frames = jsonLayer["frames"].toArray();+ bool formatSpecified = false;+ LevelProperties *lp = sl->getProperties();+ if (frames.size() > 0) {+ auto jsonFrame = frames[0].toObject();+ auto levelPath = TFilePath(m_parentDir.getQString() + "/" ++ jsonFrame["fileName"].toString());++ const Preferences &prefs = *Preferences::instance();+ int formatIdx = prefs.matchLevelFormat(levelPath);+ if (formatIdx >= 0) {+ lp->options() = prefs.levelFormat(formatIdx).m_options;+ formatSpecified = true;+ }+ }+ if (formatSpecified) {+ sl->getProperties()->setWhiteTransp(lp->whiteTransp());+ sl->getProperties()->setDoPremultiply(lp->doPremultiply());+ sl->getProperties()->setDoAntialias(lp->antialiasSoftness());+ sl->getProperties()->setDpi(lp->getDpi());+ sl->getProperties()->setDpiPolicy(lp->getDpiPolicy());+ // sl->getProperties()->setImageDpi(lp->getImageDpi()); //?+ sl->getProperties()->setSubsampling(lp->getSubsampling());+ sl->getProperties()->setColorSpaceGamma(lp->colorSpaceGamma());+ } else {+ sl->getProperties()->setWhiteTransp(m_whiteTransp);+ sl->getProperties()->setDoPremultiply(m_doPremultiply);+ sl->getProperties()->setDoAntialias(m_antialiasSoftness);+ // we filmmakers don't use dpi ??+ sl->getProperties()->setDpi(m_dpi);+ sl->getProperties()->setDpiPolicy(LevelProperties::DP_CustomDpi);+ }// float colorSpaceGamma = 2.2;// we don't need to touch this...@@ -766,29 +814,36 @@ void OCAIo::OCAInputData::importOcaLayer(const QJsonObject &jsonLayer) {fids.push_back(fid);}- // A comment about the current api : exposeLevel should be fixed to use fids :- // insert column just creates an empty column :- // m_xsheet->insertColumn(m_xsheet->getColumnCount(), TXshColumn::ColumnType::eLevelType);- // But how to fill the xsheet column ? looking at :- // Looking in LoadLevelPopup::execute().- // This works but exposes in 1's :- // IoCmd::exposeLevel(sl, 0, m_xsheet->getColumnCount(), true, true);- // ok but, strangely, even the following methods, with fids argument, don't expose with correct timing ! (exposes in 1's too) :- // fids are only used for source time, not destination time (even when isAnimationSheetEnabled is true)- // IoCmd::exposeLevel( sl, 0, m_xsheet->getColumnCount(), fids, true, true);- // IoCmd::exposeLevel( sl, 0, m_xsheet->getColumnCount(), fids);- // m_xsheet->exposeLevel(0, m_xsheet->getFirstFreeColumnIndex(), sl, fids, true);- // I think this method should be fixed to use the fids for destination time in the column- // (eventually adding an optional bool argument timingUseFids,- // but i don't get why we pass fids if we're not using those ??)...-- // that's the very simple solution...+ // Shouldn't api provide a simple method to expose the level using fids in xsheet timing ?int emptyColumnIndex = m_xsheet->getFirstFreeColumnIndex();- for (auto fid : fids)- m_xsheet->setCell(fid.getNumber(), emptyColumnIndex, TXshCell(sl, fid));+ int frameOffset = 0;+ if (m_startTime < 1) { // prevent crash if startTime is less than 1 : offset the timing...+ frameOffset = -m_startTime + 1;+ }+ for (auto fid : fids) {+ if (fid.getNumber() <= 0) {+ DVGui::warning(+ QObject::tr("importOcaLayer : skipping frame -1! ") ++ jsonLayer["name"].toString());+ continue;+ }+ // -1 converts framenumber to index, frameOffset moves the frame range above 0...+ m_xsheet->setCell(fid.getNumber() - 1 + frameOffset, emptyColumnIndex,+ TXshCell(sl, fid));+ }+ // Note about drawing numbering : I personally frame number as drawing number,+ // following richard william's animator's survival kit ("The best numbering system", page 76)+ // In toonz, this means : preference>Drawing>Numbering system = Animation sheet (isAnimationSheetEnabled == true)+ // + Autorenumber+ // That way, I can define the timing on paper while numbering drawings+ // (i write barsheets with music and avoid the computer as much as i can)// column propertiesauto column = m_xsheet->getColumn(emptyColumnIndex);+ TStageObject *stageColumn =+ m_xsheet->getStageObject(TStageObjectId::ColumnId(emptyColumnIndex));+ stageColumn->setName(jsonLayer["name"].toString().toStdString());+ //std::string str = m_columnName.toStdString();column->setOpacity(byteFromFloat(jsonLayer["opacity"].toDouble() *255.0)); // not sure if byteFromFloat is really necessary...@@ -872,16 +927,30 @@ void OCAIo::OCAInputData::importOcaLayer(const QJsonObject &jsonLayer) {void OCAIo::OCAInputData::importOcaFrame(const QJsonObject &jsonFrame,TXshSimpleLevel *sl) {- // see LoadLevelPopup, TImageP TImageReader::load(), ResourceImportDialog+ // doesExists (QFileInfo.exists()) should skip empty frames ! but...TFrameId fid(jsonFrame["frameNumber"].toInt());- // sl->setFrame(fid, TImageP());+ if (jsonFrame["name"].toString() == "_blank" ||+ jsonFrame["fileName"].toString() == "") {+ TImageP img = sl->createEmptyFrame();+ sl->setFrame(fid, img);+ return;+ }auto path = TFilePath(m_parentDir.getQString() + "/" +jsonFrame["fileName"].toString());bool fileExists = TFileStatus(path).doesExist();TImageP img;if (fileExists) {auto imageReader = TImageReaderP(path);- img = imageReader->load();+ try {+ img = imageReader->load();+ if (img.getPointer() == 0) img = sl->createEmptyFrame();+ } catch (const std::string &msg)+ {+ DVGui::error(QObject::tr("importOcaFrame load failed : ") ++ path.getQString());+ img = sl->createEmptyFrame();+ throw TException(msg);+ }if (img->getType() != TImage::RASTER) {DVGui::warning(QObject::tr("importOcaFrame skipping unimplemented image type : ") +diff --git a/toonz/sources/toonz/ocaio.h b/toonz/sources/toonz/ocaio.hindex 5b795e816..9f78411a6 100644--- a/toonz/sources/toonz/ocaio.h+++ b/toonz/sources/toonz/ocaio.h@@ -81,13 +81,13 @@ class OCAInputData : public OCAData {TOutputProperties *m_oprop;TFilePath m_parentDir;// hardcoded...- int m_dpi = 0;+ int m_dpi = 120; // this should match default m_dpi set in startuppopup.cpp@588 !?float m_antialiasSoftness = 0.0;bool m_whiteTransp = true;bool m_doPremultiply = false;public:- OCAInputData();+ OCAInputData(float antialiasSoftness, bool whiteTransp, bool doPremultiply);bool load(QString path, QJsonObject &json);void getSceneData();void read(const QJsonObject &json);diff --git a/toonz/sources/toonzlib/preferences.cpp b/toonz/sources/toonzlib/preferences.cppindex 80f95a06d..ac247db8c 100644--- a/toonz/sources/toonzlib/preferences.cpp+++ b/toonz/sources/toonzlib/preferences.cpp@@ -91,7 +91,8 @@ inline bool formatLess(const Preferences::LevelFormat &a,//=================================================================void getDefaultLevelFormats(LevelFormatVector &lfv) {- lfv.resize(2);+ //lfv.resize(2);+ lfv.resize(5);{LevelFormat &lf = lfv[0];@@ -110,6 +111,27 @@ void getDefaultLevelFormats(LevelFormatVector &lfv) {// lfv[2].m_name = Preferences::tr("PNG");// lfv[2].m_pathFormat = QRegExp("..*\\.png",// Qt::CaseInsensitive); lfv[2].m_options.m_premultiply = true;++ // for all PNG files, set premultiply by default+ lfv[2].m_name = Preferences::tr("PNG");+ lfv[2].m_pathFormat = QRegExp("..*\\.png", Qt::CaseInsensitive);+ lfv[2].m_options.m_premultiply = true;+ lfv[2].m_options.m_whiteTransp = true;+ //lfv[2].m_options.m_antialias = 70;++ // for all TIF files, set premultiply by default+ lfv[3].m_name = Preferences::tr("TIF");+ lfv[3].m_pathFormat = QRegExp("..*\\.tif", Qt::CaseInsensitive);+ lfv[3].m_options.m_premultiply = true;+ lfv[3].m_options.m_whiteTransp = true;+ //lfv[3].m_options.m_antialias = 70;++ // for all EXR files, set premultiply by default+ lfv[4].m_name = Preferences::tr("EXR");+ lfv[4].m_pathFormat = QRegExp("..*\\.exr", Qt::CaseInsensitive);+ lfv[4].m_options.m_premultiply = true;+ lfv[4].m_options.m_whiteTransp = true;+ //lfv[4].m_options.m_antialias = 70;}}