OpenToonz - An open-source full-featured 2D animation creation software
C
allow no trim on spritesheet (#1022)
Jeremy Bullock6f319437ddf1
diff --git a/toonz/sources/image/sprite/tiio_sprite.cpp b/toonz/sources/image/sprite/tiio_sprite.cppindex 6f839de41..f1b6d22b3 100644--- a/toonz/sources/image/sprite/tiio_sprite.cpp+++ b/toonz/sources/image/sprite/tiio_sprite.cpp@@ -66,7 +66,9 @@ TLevelWriterSprite::TLevelWriterSprite(const TFilePath &path,m_rightPadding = QString::fromStdString(rightPadding).toInt();m_format = QString::fromStdWString(((TEnumProperty *)(m_properties->getProperty("Format")))->getValue());-+ TBoolProperty *trim =+ (TBoolProperty *)m_properties->getProperty("Trim Empty Space");+ m_trim = trim->getValue();if (TSystem::doesExistFileOrLevel(m_path)) TSystem::deleteFile(m_path);}@@ -218,23 +220,30 @@ void TLevelWriterSprite::save(const TImageP &img, int frameIndex) {QImage *qi = new QImage((uint8_t *)buffer, m_lx, m_ly, QImage::Format_ARGB32);int l = qi->width(), r = 0, t = qi->height(), b = 0;- for (int y = 0; y < qi->height(); ++y) {- QRgb *row = (QRgb *)qi->scanLine(y);- bool rowFilled = false;- for (int x = 0; x < qi->width(); ++x) {- if (qAlpha(row[x])) {- rowFilled = true;- r = std::max(r, x);- if (l > x) {- l = x;- x = r;+ if (m_trim) {+ for (int y = 0; y < qi->height(); ++y) {+ QRgb *row = (QRgb *)qi->scanLine(y);+ bool rowFilled = false;+ for (int x = 0; x < qi->width(); ++x) {+ if (qAlpha(row[x])) {+ rowFilled = true;+ r = std::max(r, x);+ if (l > x) {+ l = x;+ x = r;+ }}}+ if (rowFilled) {+ t = std::min(t, y);+ b = y;+ }}- if (rowFilled) {- t = std::min(t, y);- b = y;- }+ } else {+ l = 0;+ r = qi->width() - 1;+ t = 0;+ b = qi->height() - 1;}if (m_firstPass) {m_firstPass = false;@@ -264,7 +273,8 @@ Tiio::SpriteWriterProperties::SpriteWriterProperties(), m_leftPadding("Left Padding", 0, 100, 0), m_rightPadding("Right Padding", 0, 100, 0), m_scale("Scale", 1, 100, 100)- , m_format("Format") {+ , m_format("Format")+ , m_trim("Trim Empty Space", true) {m_format.addValue(L"Grid");m_format.addValue(L"Vertical");m_format.addValue(L"Horizontal");@@ -275,6 +285,7 @@ Tiio::SpriteWriterProperties::SpriteWriterProperties()bind(m_leftPadding);bind(m_rightPadding);bind(m_scale);+ bind(m_trim);}// Tiio::Reader* Tiio::makeSpriteReader(){ return nullptr; }diff --git a/toonz/sources/image/sprite/tiio_sprite.h b/toonz/sources/image/sprite/tiio_sprite.hindex 623363e3f..5bbd83828 100644--- a/toonz/sources/image/sprite/tiio_sprite.h+++ b/toonz/sources/image/sprite/tiio_sprite.h@@ -38,6 +38,7 @@ private:std::vector<QImage *> m_images;std::vector<QImage> m_imagesResized;bool m_firstPass = true;+ bool m_trim = true;QString m_format;// void *m_buffer;};@@ -53,6 +54,7 @@ public:TEnumProperty m_format;TIntProperty m_topPadding, m_bottomPadding, m_leftPadding, m_rightPadding;TIntProperty m_scale;+ TBoolProperty m_trim;SpriteWriterProperties();};diff --git a/toonz/sources/toonz/startuppopup.cpp b/toonz/sources/toonz/startuppopup.cppindex bf8c375ea..3a5d84814 100644--- a/toonz/sources/toonz/startuppopup.cpp+++ b/toonz/sources/toonz/startuppopup.cpp@@ -400,13 +400,13 @@ void StartupPopup::onCreateButton() {return;}- if (m_widthFld->getValue() < 1) {- DVGui::warning(tr("The width must be 1 or more."));+ if (m_widthFld->getValue() <= 0) {+ DVGui::warning(tr("The width must be greater than zero."));m_widthFld->setFocus();return;}- if (m_heightFld->getValue() < 1) {- DVGui::warning(tr("The height must be 1 or more."));+ if (m_heightFld->getValue() <= 0) {+ DVGui::warning(tr("The height must be greater than zero."));m_heightFld->setFocus();return;}