From 2e93e48297ba8b9ee38df66b8f0467ef1644f7a1 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Thu, 17 Jan 2019 18:59:10 +0100 Subject: [PATCH 001/100] Opens scans and makes tranparent above a threshold --- app/src/mainwindow2.cpp | 1 + core_lib/src/graphics/bitmap/bitmapimage.cpp | 5 + core_lib/src/graphics/bitmap/bitmapimage.h | 1 + core_lib/src/interface/editor.cpp | 1 + core_lib/src/managers/layermanager.cpp | 11 ++ core_lib/src/managers/layermanager.h | 1 + core_lib/src/structure/layerbitmap.cpp | 165 +++++++++++++++++++ core_lib/src/structure/layerbitmap.h | 11 +- 8 files changed, 195 insertions(+), 1 deletion(-) diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index 828d5cd144..3703087b21 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -768,6 +768,7 @@ void MainWindow2::importImage() return; } + ui->scribbleArea->updateCurrentFrame(); mTimeLine->updateContent(); } diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 79e5683760..5c7fa12916 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -649,6 +649,11 @@ void BitmapImage::drawPath(QPainterPath path, QPen pen, QBrush brush, modification(); } +void BitmapImage::setBounds(QRect rect) +{ + updateBounds(rect); +} + Status BitmapImage::writeFile(const QString& filename) { if (mImage && !mImage->isNull()) diff --git a/core_lib/src/graphics/bitmap/bitmapimage.h b/core_lib/src/graphics/bitmap/bitmapimage.h index d01c87b5d0..38016491c8 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.h +++ b/core_lib/src/graphics/bitmap/bitmapimage.h @@ -92,6 +92,7 @@ class BitmapImage : public KeyFrame QSize size() { autoCrop(); return mBounds.size(); } QRect& bounds() { autoCrop(); return mBounds; } + void setBounds(QRect rect); /** Determines if the BitmapImage is minimally bounded. * diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 75c3c02cc6..9c96f8faf5 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -771,6 +771,7 @@ bool Editor::importBitmapImage(QString filePath, int space) BitmapImage importedBitmapImage(mScribbleArea->getCentralPoint().toPoint() - QPoint(img.width() / 2, img.height() / 2), img); bitmapImage->paste(&importedBitmapImage); + layer->toTransparentScan(currentFrame()); if (space > 1) { scrubTo(currentFrame() + space); diff --git a/core_lib/src/managers/layermanager.cpp b/core_lib/src/managers/layermanager.cpp index ac3ea2782d..f548032a04 100644 --- a/core_lib/src/managers/layermanager.cpp +++ b/core_lib/src/managers/layermanager.cpp @@ -154,6 +154,17 @@ LayerBitmap* LayerManager::createBitmapLayer(const QString& strLayerName) return layer; } +LayerBitmap *LayerManager::createBitmapColorLayer(const QString &strLayerName) +{ + LayerBitmap* layer = object()->addNewBitmapLayer(); + layer->setName(strLayerName); + layer->setIsColorLayer(true); + + Q_EMIT layerCountChanged(count()); + + return layer; +} + LayerVector* LayerManager::createVectorLayer(const QString& strLayerName) { LayerVector* layer = object()->addNewVectorLayer(); diff --git a/core_lib/src/managers/layermanager.h b/core_lib/src/managers/layermanager.h index 886818536a..14142bb789 100644 --- a/core_lib/src/managers/layermanager.h +++ b/core_lib/src/managers/layermanager.h @@ -57,6 +57,7 @@ class LayerManager : public BaseManager void gotoPreviouslayer(); LayerBitmap* createBitmapLayer(const QString& strLayerName); + LayerBitmap* createBitmapColorLayer(const QString& strLayerName); LayerVector* createVectorLayer(const QString& strLayerName); LayerCamera* createCameraLayer(const QString& strLayerName); LayerSound* createSoundLayer(const QString& strLayerName); diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index adb00cd401..79444633ae 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -19,6 +19,7 @@ GNU General Public License for more details. #include #include #include +#include #include "keyframe.h" #include "bitmapimage.h" @@ -45,6 +46,170 @@ BitmapImage* LayerBitmap::getLastBitmapImageAtFrame(int frameNumber, int increme return static_cast(getLastKeyFrameAtPosition(frameNumber + increment)); } +QRect LayerBitmap::getUpdatedBounds(int frame) +{ + BitmapImage* img = static_cast(getKeyFrameAt(frame)); + qDebug() << "L: " << img->left() << ", R: " << img->right() << ", T: " << img->top() << ", B: " << img->bottom(); + if (img == nullptr) return QRect(0, 0, 0, 0); + int aleft = 0, aright = 0, atop = 0, abottom = 0; + + bool cont = true; + // find aleft + for (int x = img->left(); x < img->right(); x++) + { + if (!cont) + break; + for (int y = img->top(); y < img->bottom(); y++) + { + QColor c = img->pixel(x, y); + if (c.value() < 211) + { + aleft = x; + cont = false; +// qDebug() << aleft; + } + } + } + cont = true; + + // find aright + for (int x = img->right(); x > img->left(); x--) + { + if (!cont) + break; + for (int y = img->top(); y < img->bottom(); y++) + { + QColor c = img->pixel(x, y); + if (c.value() < 211) + { + aright = x; + cont = false; +// qDebug() << aright; + } + } + } + cont = true; + + // find atop + for (int y = img->top(); y < img->bottom(); y++) + { + if (!cont) + break; + for (int x = img->left(); x < img->right(); x++) + { + QColor c = img->pixel(x, y); + if (c.value() < 211) + { + atop = y; + cont = false; +// qDebug() << atop; + } + } + } + cont = true; + + // find abottom + for (int y = img->bottom(); y > img->top(); y--) + { + if (!cont) + break; + for (int x = img->left(); x < img->right(); x++) + { + QColor c = img->pixel(x, y); + if (c.value() < 211) + { + abottom = y; + cont = false; +// qDebug() << abottom; + } + } + } + return QRect(aleft, atop, aright - aleft, abottom - atop); +} + +BitmapImage *LayerBitmap::toTransparentScan(int frame) +{ + BitmapImage* img = static_cast(getKeyFrameAt(frame)); + qDebug() << "OLD bounds: " << img->bounds(); + img->setBounds(getUpdatedBounds(frame)); + Q_ASSERT(img != nullptr); + qDebug() << "New bounds: " << img->bounds(); + + int xOffset = img->left(); + int yOffset = img->top(); + QRgb transp = qRgba(0, 0, 0, 0); + for (int x = 0; x < img->width(); x++) + { + for (int y = 0; y < img->height(); y++) + { + QColor c = img->pixel(x + xOffset, y + yOffset); + if (c.value() > 210) + img->setPixel(x + xOffset, y + yOffset, transp); +/* + if (c.value() > 50 && c.value() < 211) + { + QRgb color = qRgba(c.red(), c.green(), c.blue(), 255 - (c.value() - 50) * 255 / 160); + img->setPixel(x + xOffset, y + yOffset, color); + } +*/ + } + } + return img; +} + +void LayerBitmap::toBlackLine(int frame, int area = 5) +{ + BitmapImage* img = static_cast(getKeyFrameAt(frame)); + int xOffset = img->left(); + int yOffset = img->top(); + QRgb black = qRgba(0, 1, 0, 255); + + // make line black (0, 1, 0, 255) + for (int x = 0; x < img->width(); x++) + { + for (int y = 0; y < img->height(); y++) + { + QColor c = img->pixel(x + xOffset, y + yOffset); + if (c.value() < 211) + img->setPixel(x + xOffset, y + yOffset, black); + } + } + + // fill areas size 5 or less with black + QVector points; + points.clear(); + for (int x = 0; x < img->width(); x++) + { + for (int y = 0; y < img->height(); y++) + { + if (qAlpha(img->pixel(x,y)) == 255) + { + points.append(QPoint(x + xOffset, y + yOffset)); + // hold øje med om det er et hul osv... + } + } + } +} + +void LayerBitmap::toThinBlackLine(int frame) +{ + BitmapImage* img = static_cast(getKeyFrameAt(frame)); + int xOffset = img->left(); + int yOffset = img->top(); + QRgb thinline = qRgba(0, 1, 0, 255); + for (int x = 0; x < img->width(); x++) + { + for (int y = 0; y < img->height(); y++) + { + QColor c = img->pixel(x + xOffset, y + yOffset); + if (c.value() > 210) + { + + } + } + } +} + void LayerBitmap::loadImageAtFrame(QString path, QPoint topLeft, int frameNumber) { BitmapImage* pKeyFrame = new BitmapImage(topLeft, path); diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index d380f8c4d7..6959bd3645 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -28,7 +28,7 @@ class LayerBitmap : public Layer public: LayerBitmap(Object* object); - ~LayerBitmap(); + ~LayerBitmap() override; QDomElement createDomElement(QDomDocument& doc) override; void loadDomElement(QDomElement element, QString dataDirPath, ProgressCallback progressStep) override; @@ -36,6 +36,14 @@ class LayerBitmap : public Layer BitmapImage* getBitmapImageAtFrame(int frameNumber); BitmapImage* getLastBitmapImageAtFrame(int frameNumber, int increment = 0); + QRect getUpdatedBounds(int frame); + + // color layer methods + void setIsColorLayer(bool value) { mIsColorLayer = value; } + bool getIsColorLayer() { return mIsColorLayer; } + BitmapImage* toTransparentScan(int frame); + void toBlackLine(int frame, int area); + void toThinBlackLine(int frame); protected: Status saveKeyFrameFile(KeyFrame*, QString strPath) override; @@ -46,6 +54,7 @@ class LayerBitmap : public Layer QString filePath(KeyFrame* key, const QDir& dataFolder) const; QString fileName(KeyFrame* key) const; bool needSaveFrame(KeyFrame* key, const QString& strSavePath); + bool mIsColorLayer = false; }; #endif From 96f2efc649cbff5e6d9e853ff752f5bcde7b8076 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Fri, 18 Jan 2019 15:43:26 +0100 Subject: [PATCH 002/100] added mThreshold variable --- core_lib/src/structure/layerbitmap.cpp | 15 ++------------- core_lib/src/structure/layerbitmap.h | 2 ++ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index 79444633ae..02e4c2863a 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -49,7 +49,7 @@ BitmapImage* LayerBitmap::getLastBitmapImageAtFrame(int frameNumber, int increme QRect LayerBitmap::getUpdatedBounds(int frame) { BitmapImage* img = static_cast(getKeyFrameAt(frame)); - qDebug() << "L: " << img->left() << ", R: " << img->right() << ", T: " << img->top() << ", B: " << img->bottom(); +// qDebug() << "L: " << img->left() << ", R: " << img->right() << ", T: " << img->top() << ", B: " << img->bottom(); if (img == nullptr) return QRect(0, 0, 0, 0); int aleft = 0, aright = 0, atop = 0, abottom = 0; @@ -66,7 +66,6 @@ QRect LayerBitmap::getUpdatedBounds(int frame) { aleft = x; cont = false; -// qDebug() << aleft; } } } @@ -84,7 +83,6 @@ QRect LayerBitmap::getUpdatedBounds(int frame) { aright = x; cont = false; -// qDebug() << aright; } } } @@ -102,7 +100,6 @@ QRect LayerBitmap::getUpdatedBounds(int frame) { atop = y; cont = false; -// qDebug() << atop; } } } @@ -120,7 +117,6 @@ QRect LayerBitmap::getUpdatedBounds(int frame) { abottom = y; cont = false; -// qDebug() << abottom; } } } @@ -143,15 +139,8 @@ BitmapImage *LayerBitmap::toTransparentScan(int frame) for (int y = 0; y < img->height(); y++) { QColor c = img->pixel(x + xOffset, y + yOffset); - if (c.value() > 210) + if (c.value() > mThreshold) img->setPixel(x + xOffset, y + yOffset, transp); -/* - if (c.value() > 50 && c.value() < 211) - { - QRgb color = qRgba(c.red(), c.green(), c.blue(), 255 - (c.value() - 50) * 255 / 160); - img->setPixel(x + xOffset, y + yOffset, color); - } -*/ } } return img; diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index 6959bd3645..be972b2d09 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -54,6 +54,8 @@ class LayerBitmap : public Layer QString filePath(KeyFrame* key, const QDir& dataFolder) const; QString fileName(KeyFrame* key) const; bool needSaveFrame(KeyFrame* key, const QString& strSavePath); + + int mThreshold = 200; bool mIsColorLayer = false; }; From 4ad76c0a3b3f059e875de40524e8dab2b8a88830 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Fri, 18 Jan 2019 21:01:00 +0100 Subject: [PATCH 003/100] Dock created but hidden --- app/app.pro | 6 ++++-- app/src/bitmapcoloring.cpp | 18 ++++++++++++++++++ app/src/bitmapcoloring.h | 21 +++++++++++++++++++++ app/src/mainwindow2.cpp | 12 ++++++++++-- app/src/mainwindow2.h | 2 ++ 5 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 app/src/bitmapcoloring.cpp create mode 100644 app/src/bitmapcoloring.h diff --git a/app/app.pro b/app/app.pro index e92f201f66..bafad9fdff 100644 --- a/app/app.pro +++ b/app/app.pro @@ -60,7 +60,8 @@ HEADERS += \ src/spinslider.h \ src/doubleprogressdialog.h \ src/colorslider.h \ - src/checkupdatesdialog.h + src/checkupdatesdialog.h \ + src/bitmapcoloring.h SOURCES += \ src/main.cpp \ @@ -89,7 +90,8 @@ SOURCES += \ src/spinslider.cpp \ src/doubleprogressdialog.cpp \ src/colorslider.cpp \ - src/checkupdatesdialog.cpp + src/checkupdatesdialog.cpp \ + src/bitmapcoloring.cpp FORMS += \ ui/mainwindow2.ui \ diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp new file mode 100644 index 0000000000..9bec419e11 --- /dev/null +++ b/app/src/bitmapcoloring.cpp @@ -0,0 +1,18 @@ +#include "bitmapcoloring.h" + +BitmapColoring::BitmapColoring(QWidget *parent) : + BaseDockWidget(parent) + +{ + setWindowTitle(tr("Bitmap Coloring")); +} + +void BitmapColoring::initUI() +{ + +} + +void BitmapColoring::updateUI() +{ + +} diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h new file mode 100644 index 0000000000..31d98244ab --- /dev/null +++ b/app/src/bitmapcoloring.h @@ -0,0 +1,21 @@ +#ifndef BITMAPCOLORING_H +#define BITMAPCOLORING_H + +#include +#include "basedockwidget.h" + +class BitmapColoring : public BaseDockWidget +{ + Q_OBJECT +public: + explicit BitmapColoring(QWidget *parent = nullptr); + + void initUI() override; + void updateUI() override; + +signals: + +public slots: +}; + +#endif // BITMAPCOLORING_H diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index 3703087b21..bbddc8b432 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -61,6 +61,7 @@ GNU General Public License for more details. #include "preferencesdialog.h" #include "timeline.h" #include "toolbox.h" +#include "bitmapcoloring.h" //#include "preview.h" #include "timeline2.h" @@ -161,6 +162,9 @@ void MainWindow2::createDockWidgets() mToolBox = new ToolBoxWidget(this); mToolBox->setObjectName("ToolBox"); + mBitmapColoring = new BitmapColoring(this); + mBitmapColoring->setObjectName("BitmapColoring"); + /* mTimeline2 = new Timeline2; mTimeline2->setObjectName( "Timeline2" ); @@ -174,7 +178,8 @@ void MainWindow2::createDockWidgets() << mColorPalette << mDisplayOptionWidget << mToolOptions - << mToolBox; + << mToolBox + << mBitmapColoring; mStartIcon = QIcon(":icons/controls/play.png"); mStopIcon = QIcon(":icons/controls/stop.png"); @@ -194,6 +199,8 @@ void MainWindow2::createDockWidgets() addDockWidget(Qt::RightDockWidgetArea, mColorBox); addDockWidget(Qt::RightDockWidgetArea, mColorInspector); addDockWidget(Qt::RightDockWidgetArea, mColorPalette); + addDockWidget(Qt::RightDockWidgetArea, mBitmapColoring); + mBitmapColoring->hide(); addDockWidget(Qt::LeftDockWidgetArea, mToolBox); addDockWidget(Qt::LeftDockWidgetArea, mToolOptions); addDockWidget(Qt::LeftDockWidgetArea, mDisplayOptionWidget); @@ -345,7 +352,8 @@ void MainWindow2::createMenus() mColorPalette->toggleViewAction(), mTimeLine->toggleViewAction(), mDisplayOptionWidget->toggleViewAction(), - mColorInspector->toggleViewAction() + mColorInspector->toggleViewAction(), + mBitmapColoring->toggleViewAction() }; for (QAction* action : actions) diff --git a/app/src/mainwindow2.h b/app/src/mainwindow2.h index cfa5485395..881b2af628 100644 --- a/app/src/mainwindow2.h +++ b/app/src/mainwindow2.h @@ -29,6 +29,7 @@ class Editor; class ScribbleArea; class BaseDockWidget; class ColorPaletteWidget; +class BitmapColoring; class DisplayOptionWidget; class ToolOptionWidget; class TimeLine; @@ -143,6 +144,7 @@ private slots: //PreviewWidget* mPreview = nullptr; TimeLine* mTimeLine = nullptr; // be public temporary ColorInspector* mColorInspector = nullptr; + BitmapColoring* mBitmapColoring = nullptr; // backup BackupElement* mBackupAtSave = nullptr; From e25586a260877387bda5d07e4850ef784442b00e Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Wed, 23 Jan 2019 22:53:23 +0100 Subject: [PATCH 004/100] changes in crop function --- core_lib/src/interface/editor.cpp | 1 + core_lib/src/structure/layerbitmap.cpp | 30 ++++++++++++++------------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 9c96f8faf5..8aa0244b71 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -533,6 +533,7 @@ void Editor::paste() BitmapImage tobePasted = g_clipboardBitmapImage.copy(); qDebug() << "to be pasted --->" << tobePasted.image()->size(); + qDebug() << "to be pasted --->" << tobePasted.image()->offset(); if (mScribbleArea->isSomethingSelected()) { QRectF selection = mScribbleArea->getSelection(); diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index 02e4c2863a..20b25b69cc 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -24,7 +24,6 @@ GNU General Public License for more details. #include "bitmapimage.h" - LayerBitmap::LayerBitmap(Object* object) : Layer(object, Layer::BITMAP) { setName(tr("Bitmap Layer")); @@ -61,10 +60,11 @@ QRect LayerBitmap::getUpdatedBounds(int frame) break; for (int y = img->top(); y < img->bottom(); y++) { - QColor c = img->pixel(x, y); - if (c.value() < 211) + QRgb c = img->pixel(x, y); + if (qAlpha(c) != 0) { aleft = x; + qDebug() << "aleft " << aleft; cont = false; } } @@ -78,10 +78,11 @@ QRect LayerBitmap::getUpdatedBounds(int frame) break; for (int y = img->top(); y < img->bottom(); y++) { - QColor c = img->pixel(x, y); - if (c.value() < 211) + QRgb c = img->pixel(x, y); + if (qAlpha(c) != 0) { aright = x; + qDebug() << "aright " << aright; cont = false; } } @@ -95,10 +96,13 @@ QRect LayerBitmap::getUpdatedBounds(int frame) break; for (int x = img->left(); x < img->right(); x++) { - QColor c = img->pixel(x, y); - if (c.value() < 211) +// QColor c = img->pixel(x, y); +// if (c.value() < mThreshold) + QRgb c = img->pixel(x, y); + if (qAlpha(c) != 0) { atop = y; + qDebug() << "atop " << atop; cont = false; } } @@ -112,10 +116,11 @@ QRect LayerBitmap::getUpdatedBounds(int frame) break; for (int x = img->left(); x < img->right(); x++) { - QColor c = img->pixel(x, y); - if (c.value() < 211) + QRgb c = img->pixel(x, y); + if (qAlpha(c) != 0) { abottom = y; + qDebug() << "abottom " << abottom; cont = false; } } @@ -126,11 +131,6 @@ QRect LayerBitmap::getUpdatedBounds(int frame) BitmapImage *LayerBitmap::toTransparentScan(int frame) { BitmapImage* img = static_cast(getKeyFrameAt(frame)); - qDebug() << "OLD bounds: " << img->bounds(); - img->setBounds(getUpdatedBounds(frame)); - Q_ASSERT(img != nullptr); - qDebug() << "New bounds: " << img->bounds(); - int xOffset = img->left(); int yOffset = img->top(); QRgb transp = qRgba(0, 0, 0, 0); @@ -143,6 +143,8 @@ BitmapImage *LayerBitmap::toTransparentScan(int frame) img->setPixel(x + xOffset, y + yOffset, transp); } } + img->setBounds(getUpdatedBounds(frame)); + qDebug() << img->bounds(); return img; } From 184bf80cc696f93588ed0ed03d135a621a203a00 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Thu, 24 Jan 2019 21:20:06 +0100 Subject: [PATCH 005/100] Copy from scan and Next is working --- app/app.pro | 3 +- app/src/bitmapcoloring.cpp | 32 ++- app/src/bitmapcoloring.h | 16 +- app/src/mainwindow2.cpp | 2 +- app/ui/bitmapcoloringwidget.ui | 342 +++++++++++++++++++++++++ core_lib/src/interface/editor.cpp | 20 +- core_lib/src/interface/editor.h | 1 + core_lib/src/structure/layerbitmap.cpp | 84 ------ core_lib/src/structure/layerbitmap.h | 1 - 9 files changed, 410 insertions(+), 91 deletions(-) create mode 100644 app/ui/bitmapcoloringwidget.ui diff --git a/app/app.pro b/app/app.pro index bafad9fdff..598ddc7d3e 100644 --- a/app/app.pro +++ b/app/app.pro @@ -113,7 +113,8 @@ FORMS += \ ui/timelinepage.ui \ ui/filespage.ui \ ui/toolspage.ui \ - ui/toolboxwidget.ui + ui/toolboxwidget.ui \ + ui/bitmapcoloringwidget.ui diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 9bec419e11..5a3b99d0c5 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -1,10 +1,40 @@ +/* + +Pencil - Traditional Animation Software +Copyright (C) 2012-2018 Matthew Chiawen Chang + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +*/ #include "bitmapcoloring.h" +#include "ui_bitmapcoloringwidget.h" + -BitmapColoring::BitmapColoring(QWidget *parent) : +BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : BaseDockWidget(parent) { + QWidget* innerWidget = new QWidget; setWindowTitle(tr("Bitmap Coloring")); + + ui = new Ui::BitmapColoringWidget; + ui->setupUi(innerWidget); + setWidget(innerWidget); + mEditor = editor; + connect(ui->btn1Select, &QPushButton::clicked, mEditor, &Editor::copyFromScan); + connect(ui->btn1Next, &QPushButton::clicked, mEditor, &Editor::scrubNextKeyFrame); +} + +BitmapColoring::~BitmapColoring() +{ + delete ui; } void BitmapColoring::initUI() diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 31d98244ab..4aaa3f60ef 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -1,14 +1,21 @@ #ifndef BITMAPCOLORING_H #define BITMAPCOLORING_H -#include #include "basedockwidget.h" +#include "editor.h" + +namespace Ui +{ +class BitmapColoringWidget; +} class BitmapColoring : public BaseDockWidget { Q_OBJECT + public: - explicit BitmapColoring(QWidget *parent = nullptr); + explicit BitmapColoring(Editor* editor, QWidget *parent); + ~BitmapColoring() override; void initUI() override; void updateUI() override; @@ -16,6 +23,11 @@ class BitmapColoring : public BaseDockWidget signals: public slots: + +private: + Ui::BitmapColoringWidget* ui = nullptr; + Editor* mEditor; + }; #endif // BITMAPCOLORING_H diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index bbddc8b432..c869937496 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -162,7 +162,7 @@ void MainWindow2::createDockWidgets() mToolBox = new ToolBoxWidget(this); mToolBox->setObjectName("ToolBox"); - mBitmapColoring = new BitmapColoring(this); + mBitmapColoring = new BitmapColoring(mEditor, this); mBitmapColoring->setObjectName("BitmapColoring"); /* diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui new file mode 100644 index 0000000000..d003ee3dd0 --- /dev/null +++ b/app/ui/bitmapcoloringwidget.ui @@ -0,0 +1,342 @@ + + + BitmapColoringWidget + + + + 0 + 0 + 270 + 447 + + + + Form + + + + + 9 + 9 + 252 + 121 + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">1. Select from scan (optional)</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">2. Clean up drawings (optional)</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">3. Threshold and transparency</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">4. Remove white areas</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">5. Thin black line to 1 pixel</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">6. Colorize with fills</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">7. Remove/replace 1 pixel line</p></body></html> + + + + + + 10 + 170 + 251 + 251 + + + + 0 + + + + 1 + + + + + 1 + 1 + 241 + 221 + + + + + + + Select coloring area. + + + + + + + Only if you work with scans + + + + + + + Qt::Horizontal + + + + + + + Use select tool! + + + + + + + + + Select + + + + + + + Next + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Done + + + + + + + + + + + 2 + + + + + 0 + 11 + 241 + 201 + + + + + + + Clean up if necessary + + + + + + + Use normal tools + + + + + + + Finish all drawings + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Done + + + + + + + + + + + 3 + + + + + 10 + 0 + 231 + 221 + + + + + + + + + Choose threshold + + + + + + + 150 + + + 250 + + + 200 + + + + + + + + + Apply active drawing + + + + + + + Apply all drawings + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Done + + + + + + + + + + + 4 + + + + + 5 + + + + + 6 + + + + + 7 + + + + + + + diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 8aa0244b71..98bdb48f06 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -522,6 +522,24 @@ void Editor::copy() } } +void Editor::copyFromScan() +{ + Layer* layer = mObject->getLayer(layers()->currentLayerIndex()); + if (layer == nullptr) { return; } + + if (!layer->keyExists(currentFrame())) { return; } + + LayerBitmap* layerBitmap = static_cast(layer); + if (layerBitmap->getIsColorLayer() && mScribbleArea->isSomethingSelected()) + { + copy(); + layer->removeKeyFrame(currentFrame()); + layer->addNewKeyFrameAt(currentFrame()); + paste(); + g_clipboardBitmapImage.clear(); + } +} + void Editor::paste() { Layer* layer = mObject->getLayer(layers()->currentLayerIndex()); @@ -772,7 +790,7 @@ bool Editor::importBitmapImage(QString filePath, int space) BitmapImage importedBitmapImage(mScribbleArea->getCentralPoint().toPoint() - QPoint(img.width() / 2, img.height() / 2), img); bitmapImage->paste(&importedBitmapImage); - layer->toTransparentScan(currentFrame()); +// layer->toTransparentScan(currentFrame()); if (space > 1) { scrubTo(currentFrame() + space); diff --git a/core_lib/src/interface/editor.h b/core_lib/src/interface/editor.h index 7269e5794e..419b410a74 100644 --- a/core_lib/src/interface/editor.h +++ b/core_lib/src/interface/editor.h @@ -145,6 +145,7 @@ class Editor : public QObject void undo(); void redo(); void copy(); + void copyFromScan(); void paste(); void clipboardChanged(); diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index 20b25b69cc..08c874139b 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -45,89 +45,6 @@ BitmapImage* LayerBitmap::getLastBitmapImageAtFrame(int frameNumber, int increme return static_cast(getLastKeyFrameAtPosition(frameNumber + increment)); } -QRect LayerBitmap::getUpdatedBounds(int frame) -{ - BitmapImage* img = static_cast(getKeyFrameAt(frame)); -// qDebug() << "L: " << img->left() << ", R: " << img->right() << ", T: " << img->top() << ", B: " << img->bottom(); - if (img == nullptr) return QRect(0, 0, 0, 0); - int aleft = 0, aright = 0, atop = 0, abottom = 0; - - bool cont = true; - // find aleft - for (int x = img->left(); x < img->right(); x++) - { - if (!cont) - break; - for (int y = img->top(); y < img->bottom(); y++) - { - QRgb c = img->pixel(x, y); - if (qAlpha(c) != 0) - { - aleft = x; - qDebug() << "aleft " << aleft; - cont = false; - } - } - } - cont = true; - - // find aright - for (int x = img->right(); x > img->left(); x--) - { - if (!cont) - break; - for (int y = img->top(); y < img->bottom(); y++) - { - QRgb c = img->pixel(x, y); - if (qAlpha(c) != 0) - { - aright = x; - qDebug() << "aright " << aright; - cont = false; - } - } - } - cont = true; - - // find atop - for (int y = img->top(); y < img->bottom(); y++) - { - if (!cont) - break; - for (int x = img->left(); x < img->right(); x++) - { -// QColor c = img->pixel(x, y); -// if (c.value() < mThreshold) - QRgb c = img->pixel(x, y); - if (qAlpha(c) != 0) - { - atop = y; - qDebug() << "atop " << atop; - cont = false; - } - } - } - cont = true; - - // find abottom - for (int y = img->bottom(); y > img->top(); y--) - { - if (!cont) - break; - for (int x = img->left(); x < img->right(); x++) - { - QRgb c = img->pixel(x, y); - if (qAlpha(c) != 0) - { - abottom = y; - qDebug() << "abottom " << abottom; - cont = false; - } - } - } - return QRect(aleft, atop, aright - aleft, abottom - atop); -} - BitmapImage *LayerBitmap::toTransparentScan(int frame) { BitmapImage* img = static_cast(getKeyFrameAt(frame)); @@ -143,7 +60,6 @@ BitmapImage *LayerBitmap::toTransparentScan(int frame) img->setPixel(x + xOffset, y + yOffset, transp); } } - img->setBounds(getUpdatedBounds(frame)); qDebug() << img->bounds(); return img; } diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index be972b2d09..df82cde52c 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -36,7 +36,6 @@ class LayerBitmap : public Layer BitmapImage* getBitmapImageAtFrame(int frameNumber); BitmapImage* getLastBitmapImageAtFrame(int frameNumber, int increment = 0); - QRect getUpdatedBounds(int frame); // color layer methods void setIsColorLayer(bool value) { mIsColorLayer = value; } From 8a7388a3976f2372970e92e52e8bbd84bfd9f509 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Thu, 24 Jan 2019 23:28:15 +0100 Subject: [PATCH 006/100] Finished designing Bitmap Color Process Dock --- app/ui/bitmapcoloringwidget.ui | 688 ++++++++++++++++++--------------- 1 file changed, 375 insertions(+), 313 deletions(-) diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index d003ee3dd0..f4342a0ba8 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -7,335 +7,397 @@ 0 0 270 - 447 + 608 Form - - - - 9 - 9 - 252 - 121 - - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">1. Select from scan (optional)</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">2. Clean up drawings (optional)</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">3. Threshold and transparency</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Process scanned drawings</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">1. Select from scan</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">2. Clean up drawings</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">3. Threshold and transparency</p></body></html> + + + + + + + 0 + + + + 1 + + + + + + Select coloring area. + + + + + + + Only if you work with scans + + + + + + + Use select tool! + + + + + + + + + Select + + + + + + + Next + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 2 + + + + + + Clean up if necessary + + + + + + + Use normal tools + + + + + + + Finish all drawings + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 3 + + + + + + + + Choose threshold + + + + + + + 150 + + + 250 + + + 200 + + + + + + + + + + + Apply + + + + + + + Next + + + + + + + + + Apply the rest... + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600; color:#204a87;">Bitmap coloring</span></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">4. Remove white areas</p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">5. Thin black line to 1 pixel</p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">6. Colorize with fills</p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">7. Remove/replace 1 pixel line</p></body></html> - - - - - - 10 - 170 - 251 - 251 - - - - 0 - - - - 1 - - - - - 1 - 1 - 241 - 221 - - - - - - - Select coloring area. - - - - - - - Only if you work with scans - - - - - - - Qt::Horizontal - - - - - - - Use select tool! - - - - - - - - - Select - - - - - - - Next - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Done - - - - - - - - - - - 2 - - - - - 0 - 11 - 241 - 201 - - - - - - Clean up if necessary - - - - - - - Use normal tools - - - - - - - Finish all drawings - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Done - - - - - - - - - - 3 - - - - - 10 - 0 - 231 - 221 - + + + + + 0 - - - - - - - Choose threshold - - - - - - - 150 - - - 250 - - - 200 - - - - - - - - - Apply active drawing - - - - - - - Apply all drawings - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Done - - - - - - + + + 4 + + + + + + + + Fill area: + + + + + + + px + + + 1 + + + 16 + + + 6 + + + + + + + + + + + Apply + + + + + + + Next + + + + + + + + + Apply the rest... + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 5 + + + + + + + + Thin line + + + + + + + Next + + + + + + + + + Thin rest... + + + + + + + Qt::Vertical + + + + 20 + 31 + + + + + + + + + 6 + + + + + + Colorize... + + + + + + + Qt::Vertical + + + + 20 + 70 + + + + + + + + + 7 + + + + + + Replace thin lines... + + + + + + + Qt::Vertical + + + + 20 + 62 + + + + + + - - - - 4 - - - - - 5 - - - - - 6 - - - - - 7 - - - + + From e0bf339616aed0ab56627d204d7a4e64b1db6d6d Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 27 Jan 2019 07:12:11 +0100 Subject: [PATCH 007/100] Add color layer and preprocess drawings --- app/src/actioncommands.cpp | 12 ++ app/src/actioncommands.h | 1 + app/src/bitmapcoloring.cpp | 25 ++++ app/src/bitmapcoloring.h | 7 +- app/src/mainwindow2.cpp | 11 ++ app/src/mainwindow2.h | 1 + app/ui/bitmapcoloringwidget.ui | 154 +++++++++++++++++++++---- app/ui/mainwindow2.ui | 7 ++ core_lib/src/interface/editor.cpp | 56 ++++++--- core_lib/src/interface/editor.h | 5 +- core_lib/src/managers/layermanager.cpp | 7 +- core_lib/src/managers/layermanager.h | 2 +- core_lib/src/structure/layer.cpp | 14 +++ core_lib/src/structure/layer.h | 2 +- core_lib/src/structure/layerbitmap.cpp | 102 ++++++++++++++-- core_lib/src/structure/layerbitmap.h | 16 ++- 16 files changed, 355 insertions(+), 67 deletions(-) diff --git a/app/src/actioncommands.cpp b/app/src/actioncommands.cpp index aff4fc18c0..20339eecf9 100644 --- a/app/src/actioncommands.cpp +++ b/app/src/actioncommands.cpp @@ -37,6 +37,7 @@ GNU General Public License for more details. #include "layercamera.h" #include "layersound.h" +#include "layerbitmap.h" #include "bitmapimage.h" #include "vectorimage.h" #include "soundclip.h" @@ -648,6 +649,17 @@ Status ActionCommands::addNewSoundLayer() return Status::OK; } +Status ActionCommands::addNewBitmapColorLayer() +{ + QString name = mEditor->layers()->currentLayer()->name() + "_C"; + if (!name.isEmpty()) + { + LayerBitmap* colorlayer = mEditor->layers()->createBitmapLayer(name); + colorlayer->initColorLayer(mEditor->layers()->currentLayer(), colorlayer); + } + return Status::OK; +} + Status ActionCommands::deleteCurrentLayer() { LayerManager* layerMgr = mEditor->layers(); diff --git a/app/src/actioncommands.h b/app/src/actioncommands.h index 3911ea8975..1f2bf681dc 100644 --- a/app/src/actioncommands.h +++ b/app/src/actioncommands.h @@ -72,6 +72,7 @@ class ActionCommands : public QObject Status addNewVectorLayer(); Status addNewCameraLayer(); Status addNewSoundLayer(); + Status addNewBitmapColorLayer(); Status deleteCurrentLayer(); QString nameSuggest(QString s); diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 5a3b99d0c5..d158aada21 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -15,6 +15,8 @@ GNU General Public License for more details. */ #include "bitmapcoloring.h" #include "ui_bitmapcoloringwidget.h" +#include "layermanager.h" +#include "qdebug.h" BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : @@ -27,9 +29,17 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : ui = new Ui::BitmapColoringWidget; ui->setupUi(innerWidget); setWidget(innerWidget); + mEditor = editor; + if (mEditor->layers()->currentLayer()->type() == Layer::BITMAP) + mLayerBitmap = static_cast(mEditor->layers()->currentLayer()); + connect(ui->btn1Select, &QPushButton::clicked, mEditor, &Editor::copyFromScan); connect(ui->btn1Next, &QPushButton::clicked, mEditor, &Editor::scrubNextKeyFrame); + connect(ui->sb2_Threshold, QOverload::of(&QSpinBox::valueChanged), mLayerBitmap, &LayerBitmap::setThreshold); + connect(ui->btn3_apply, &QPushButton::clicked, mEditor, &Editor::scanToTransparent); + connect(ui->btn3_Next, &QPushButton::clicked, mEditor, &Editor::scrubNextKeyFrame); + connect(ui->btn3_applyRest, &QPushButton::clicked, mEditor, &Editor::scanToTransparentRest); } BitmapColoring::~BitmapColoring() @@ -39,10 +49,25 @@ BitmapColoring::~BitmapColoring() void BitmapColoring::initUI() { + if (!isVisible()) { return; } + updateUI(); } void BitmapColoring::updateUI() { + Layer* layer = mEditor->layers()->currentLayer(); + if (layer->type() == Layer::BITMAP) + { + setEnabled(true); + } + else + { + setEnabled(false); + } +} +void BitmapColoring::scanToTransparent() +{ + mEditor->scanToTransparent(); } diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 4aaa3f60ef..182b1106a2 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -3,6 +3,9 @@ #include "basedockwidget.h" #include "editor.h" +#include "layerbitmap.h" + +class Layer; namespace Ui { @@ -23,10 +26,12 @@ class BitmapColoring : public BaseDockWidget signals: public slots: + void scanToTransparent(); private: Ui::BitmapColoringWidget* ui = nullptr; - Editor* mEditor; + Editor* mEditor = nullptr; + LayerBitmap* mLayerBitmap = nullptr; }; diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index c869937496..23c04cee40 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -276,6 +276,7 @@ void MainWindow2::createMenus() connect(ui->actionNew_Vector_Layer, &QAction::triggered, mCommands, &ActionCommands::addNewVectorLayer); connect(ui->actionNew_Sound_Layer, &QAction::triggered, mCommands, &ActionCommands::addNewSoundLayer); connect(ui->actionNew_Camera_Layer, &QAction::triggered, mCommands, &ActionCommands::addNewCameraLayer); + connect(ui->actionAdd_Bitmap_Color_Layer, &QAction::triggered, mCommands, &ActionCommands::addNewBitmapColorLayer); connect(ui->actionDelete_Current_Layer, &QAction::triggered, mCommands, &ActionCommands::deleteCurrentLayer); /// --- View Menu --- @@ -1330,6 +1331,8 @@ void MainWindow2::makeConnections(Editor* pEditor, TimeLine* pTimeline) connect(pEditor, &Editor::updateTimeLine, pTimeline, &TimeLine::updateUI); connect(pEditor->layers(), &LayerManager::currentLayerChanged, mToolOptions, &ToolOptionWidget::updateUI); + connect(pEditor->layers(), &LayerManager::currentLayerChanged, mBitmapColoring, &BitmapColoring::updateUI); + connect(pEditor->layers(), &LayerManager::currentLayerChanged, this, &MainWindow2::updateLayerMenu); } void MainWindow2::makeConnections(Editor*, DisplayOptionWidget*) @@ -1385,6 +1388,14 @@ void MainWindow2::updateZoomLabel() statusBar()->showMessage(QString("Zoom: %0%1").arg(static_cast(zoom), 0, 'f', 1).arg("%")); } +void MainWindow2::updateLayerMenu() +{ + if (mEditor->layers()->currentLayer()->type() == Layer::BITMAP) + ui->actionAdd_Bitmap_Color_Layer->setEnabled(true); + else + ui->actionAdd_Bitmap_Color_Layer->setEnabled(false); +} + void MainWindow2::changePlayState(bool isPlaying) { if (isPlaying) diff --git a/app/src/mainwindow2.h b/app/src/mainwindow2.h index 881b2af628..474f8b443b 100644 --- a/app/src/mainwindow2.h +++ b/app/src/mainwindow2.h @@ -112,6 +112,7 @@ private slots: void setupKeyboardShortcuts(); void clearKeyboardShortcuts(); void updateZoomLabel(); + void updateLayerMenu(); void importPalette(); void exportPalette(); diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index f4342a0ba8..a1fda8a76f 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -7,29 +7,78 @@ 0 0 270 - 608 + 649 Form - + - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Process scanned drawings</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">1. Select from scan</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">2. Clean up drawings</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">3. Threshold and transparency</p></body></html> + + + QFrame::StyledPanel + + QFrame::Raised + + + + + + + + + 75 + true + + + + Process scanned drawings + + + + + + + 1. Select from scan + + + + + + + 2. Clean up drawings + + + + + + + 3. Threshold and transparency + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + - + 0 @@ -205,22 +254,77 @@ p, li { white-space: pre-wrap; } - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600; color:#204a87;">Bitmap coloring</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">4. Remove white areas</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">5. Thin black line to 1 pixel</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">6. Colorize with fills</p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">7. Remove/replace 1 pixel line</p></body></html> + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + 75 + true + + + + Bitmap coloring + + + + + + + 4. Remove white areas + + + + + + + 5. Thin black line to 1 pixel + + + + + + + 6. Colorize with fills + + + + + + + 7. Remove/replace 1 pixel line + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + - + 0 diff --git a/app/ui/mainwindow2.ui b/app/ui/mainwindow2.ui index 30c35d39c1..530afde244 100644 --- a/app/ui/mainwindow2.ui +++ b/app/ui/mainwindow2.ui @@ -208,6 +208,8 @@ + + @@ -961,6 +963,11 @@ 100% + + + Add Bitmap Color Layer + + diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 98bdb48f06..1e96b44592 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -522,24 +522,6 @@ void Editor::copy() } } -void Editor::copyFromScan() -{ - Layer* layer = mObject->getLayer(layers()->currentLayerIndex()); - if (layer == nullptr) { return; } - - if (!layer->keyExists(currentFrame())) { return; } - - LayerBitmap* layerBitmap = static_cast(layer); - if (layerBitmap->getIsColorLayer() && mScribbleArea->isSomethingSelected()) - { - copy(); - layer->removeKeyFrame(currentFrame()); - layer->addNewKeyFrameAt(currentFrame()); - paste(); - g_clipboardBitmapImage.clear(); - } -} - void Editor::paste() { Layer* layer = mObject->getLayer(layers()->currentLayerIndex()); @@ -584,6 +566,44 @@ void Editor::flipSelection(bool flipVertical) mScribbleArea->flipSelection(flipVertical); } +/** + * @brief Editor::copyFromScan + * Selecting from a scanned drawing imported to Pencil2d. + * Can only be used by Layer::BITMAP type layers. + */ +void Editor::copyFromScan() +{ + Layer* layer = mObject->getLayer(layers()->currentLayerIndex()); + if (layer == nullptr) { return; } + + if (!layer->keyExists(currentFrame())) { return; } + + if (mScribbleArea->isSomethingSelected()) + { + copy(); + layer->removeKeyFrame(currentFrame()); + layer->addNewKeyFrameAt(currentFrame()); + paste(); + g_clipboardBitmapImage.clear(); + } +} + +void Editor::scanToTransparent() +{ + LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); + layerBitmap->scanToTransparent(currentFrame()); + mScribbleArea->updateFrame(currentFrame()); +} + +void Editor::scanToTransparentRest() +{ + LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); + while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()) { + scrubNextKeyFrame(); + layerBitmap->scanToTransparent(currentFrame()); + } +} + void Editor::clipboardChanged() { if (clipboardBitmapOk == false) diff --git a/core_lib/src/interface/editor.h b/core_lib/src/interface/editor.h index 419b410a74..a81a2c6668 100644 --- a/core_lib/src/interface/editor.h +++ b/core_lib/src/interface/editor.h @@ -145,13 +145,16 @@ class Editor : public QObject void undo(); void redo(); void copy(); - void copyFromScan(); void paste(); void clipboardChanged(); void toggleShowAllLayers(); void flipSelection(bool flipVertical); + void copyFromScan(); + void scanToTransparent(); + void scanToTransparentRest(); + void toogleOnionSkinType(); void settingUpdated(SETTING); diff --git a/core_lib/src/managers/layermanager.cpp b/core_lib/src/managers/layermanager.cpp index f548032a04..1baa8afb56 100644 --- a/core_lib/src/managers/layermanager.cpp +++ b/core_lib/src/managers/layermanager.cpp @@ -153,18 +153,17 @@ LayerBitmap* LayerManager::createBitmapLayer(const QString& strLayerName) return layer; } - -LayerBitmap *LayerManager::createBitmapColorLayer(const QString &strLayerName) +/* +LayerBitmap* LayerManager::createBitmapColorLayer(const QString& strLayerName) { LayerBitmap* layer = object()->addNewBitmapLayer(); layer->setName(strLayerName); - layer->setIsColorLayer(true); Q_EMIT layerCountChanged(count()); return layer; } - +*/ LayerVector* LayerManager::createVectorLayer(const QString& strLayerName) { LayerVector* layer = object()->addNewVectorLayer(); diff --git a/core_lib/src/managers/layermanager.h b/core_lib/src/managers/layermanager.h index 14142bb789..16bbca766a 100644 --- a/core_lib/src/managers/layermanager.h +++ b/core_lib/src/managers/layermanager.h @@ -57,7 +57,7 @@ class LayerManager : public BaseManager void gotoPreviouslayer(); LayerBitmap* createBitmapLayer(const QString& strLayerName); - LayerBitmap* createBitmapColorLayer(const QString& strLayerName); +// LayerBitmap* createBitmapColorLayer(const QString& strLayerName); LayerVector* createVectorLayer(const QString& strLayerName); LayerCamera* createCameraLayer(const QString& strLayerName); LayerSound* createSoundLayer(const QString& strLayerName); diff --git a/core_lib/src/structure/layer.cpp b/core_lib/src/structure/layer.cpp index d2af524094..d84ee6b72b 100644 --- a/core_lib/src/structure/layer.cpp +++ b/core_lib/src/structure/layer.cpp @@ -445,6 +445,20 @@ void Layer::setModified(int position, bool modified) } } +void Layer::copyFrame(Layer *fromLayer, Layer *toLayer, int frame) +{ + if (fromLayer->keyExists(frame)) + { + mObject->updateActiveFrames(frame); + KeyFrame* keyframe = fromLayer->getKeyFrameAt(frame); + KeyFrame* dupKey = keyframe->clone(); + if (toLayer->keyExists(frame)) + toLayer->removeKeyFrame(frame); + toLayer->addKeyFrame(frame, dupKey); + toLayer->setModified(frame, true); + } +} + bool Layer::isFrameSelected(int position) const { KeyFrame* keyFrame = getKeyFrameWhichCovers(position); diff --git a/core_lib/src/structure/layer.h b/core_lib/src/structure/layer.h index 2b076bd41c..91f5d239fd 100644 --- a/core_lib/src/structure/layer.h +++ b/core_lib/src/structure/layer.h @@ -97,7 +97,7 @@ class Layer : public QObject void foreachKeyFrame(std::function); void setModified(int position, bool isModified); - + void copyFrame(Layer *fromLayer, Layer *toLayer, int frame); // Handle selection bool isFrameSelected(int position) const; void setFrameSelected(int position, bool isSelected); diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index 08c874139b..9f6cda9053 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -22,6 +22,7 @@ GNU General Public License for more details. #include #include "keyframe.h" #include "bitmapimage.h" +#include LayerBitmap::LayerBitmap(Object* object) : Layer(object, Layer::BITMAP) @@ -45,44 +46,71 @@ BitmapImage* LayerBitmap::getLastBitmapImageAtFrame(int frameNumber, int increme return static_cast(getLastKeyFrameAtPosition(frameNumber + increment)); } -BitmapImage *LayerBitmap::toTransparentScan(int frame) +void LayerBitmap::initColorLayer(Layer *fromLayer, LayerBitmap *colorlayer) +{ + int max = fromLayer->getMaxKeyFramePosition(); + for (int i = 1; i <=max; i++) + { + colorlayer->copyFrame(fromLayer, colorlayer, i); + toBlackLine(i); + } +} + +BitmapImage* LayerBitmap::scanToTransparent(int frame) { BitmapImage* img = static_cast(getKeyFrameAt(frame)); int xOffset = img->left(); int yOffset = img->top(); - QRgb transp = qRgba(0, 0, 0, 0); for (int x = 0; x < img->width(); x++) { for (int y = 0; y < img->height(); y++) { QColor c = img->pixel(x + xOffset, y + yOffset); - if (c.value() > mThreshold) + if (c.value() >= mThreshold) + { img->setPixel(x + xOffset, y + yOffset, transp); + } + else if(c.value() > 99 && c.value() < mThreshold) + { + int alpha = static_cast(floor(255 - 255/(mThreshold - 100) * (c.value() - 100))); + QRgb rgba = qRgba(c.value(), c.value(), c.value(), alpha); + img->setPixel(x + xOffset, y + yOffset, rgba); + } } } qDebug() << img->bounds(); return img; } -void LayerBitmap::toBlackLine(int frame, int area = 5) +void LayerBitmap::toBlackLine(int frame) { + if (!keyExists(frame)) { return; } + BitmapImage* img = static_cast(getKeyFrameAt(frame)); int xOffset = img->left(); int yOffset = img->top(); - QRgb black = qRgba(0, 1, 0, 255); // make line black (0, 1, 0, 255) for (int x = 0; x < img->width(); x++) { for (int y = 0; y < img->height(); y++) { - QColor c = img->pixel(x + xOffset, y + yOffset); - if (c.value() < 211) - img->setPixel(x + xOffset, y + yOffset, black); + QRgb rgba = img->pixel(x + xOffset, y + yOffset); + if (rgba != transp) + img->setPixel(x + xOffset, y + yOffset, thinline); } } +} + +void LayerBitmap::fillWhiteAreas(int frame, int area) +{ + if (!keyExists(frame)) { return; } - // fill areas size 5 or less with black + BitmapImage* img = static_cast(getKeyFrameAt(frame)); + int xOffset = img->left(); + int yOffset = img->top(); + + // fill areas size 'area' or less with black QVector points; points.clear(); for (int x = 0; x < img->width(); x++) @@ -92,10 +120,20 @@ void LayerBitmap::toBlackLine(int frame, int area = 5) if (qAlpha(img->pixel(x,y)) == 255) { points.append(QPoint(x + xOffset, y + yOffset)); - // hold øje med om det er et hul osv... + int areaSize = fillWithColor(QPoint(x + xOffset, y + yOffset), transp, rosa, frame); + if (areaSize <= area) + { // replace rosa with thinline (black) + fillWithColor(QPoint(x + xOffset, y + yOffset), rosa, thinline, frame); + points.removeLast(); + } } } } + // replace rosa with trans + while (!points.isEmpty()) { + fillWithColor(points[0], rosa, transp, frame); + points.removeFirst(); + } } void LayerBitmap::toThinBlackLine(int frame) @@ -103,7 +141,6 @@ void LayerBitmap::toThinBlackLine(int frame) BitmapImage* img = static_cast(getKeyFrameAt(frame)); int xOffset = img->left(); int yOffset = img->top(); - QRgb thinline = qRgba(0, 1, 0, 255); for (int x = 0; x < img->width(); x++) { for (int y = 0; y < img->height(); y++) @@ -117,6 +154,49 @@ void LayerBitmap::toThinBlackLine(int frame) } } +int LayerBitmap::fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, int frame) +{ + BitmapImage* img = static_cast(getKeyFrameAt(frame)); + QList fillList; + fillList.clear(); + // fill first pixel + img->setPixel(point, newColor); + int pixels = 1; + fillList.append(point); + + QRect rect = img->bounds(); + while (!fillList.isEmpty()) + { + QPoint tmp = fillList.at(0); + if (rect.contains(QPoint(tmp.x() + 1, tmp.y())) && img->pixel(QPoint(tmp.x() + 1, tmp.y())) == orgColor) + { + img->setPixel(QPoint(tmp.x() + 1, tmp.y()), newColor); + fillList.append(QPoint(tmp.x() + 1, tmp.y())); + pixels++; + } + if (rect.contains(QPoint(tmp.x(), tmp.y() + 1)) && img->pixel(QPoint(tmp.x(), tmp.y() + 1)) == orgColor) + { + img->setPixel(QPoint(tmp.x(), tmp.y() + 1), newColor); + fillList.append(QPoint(tmp.x(), tmp.y() + 1)); + pixels++; + } + if (rect.contains(QPoint(tmp.x() - 1, tmp.y())) && img->pixel(QPoint(tmp.x() - 1, tmp.y())) == orgColor) + { + img->setPixel(QPoint(tmp.x() - 1, tmp.y()), newColor); + fillList.append(QPoint(tmp.x() - 1, tmp.y())); + pixels++; + } + if (rect.contains(QPoint(tmp.x(), tmp.y() - 1)) && img->pixel(QPoint(tmp.x(), tmp.y() - 1)) == orgColor) + { + img->setPixel(QPoint(tmp.x(), tmp.y() - 1), newColor); + fillList.append(QPoint(tmp.x(), tmp.y() - 1)); + pixels++; + } + fillList.removeFirst(); + } + return pixels; +} + void LayerBitmap::loadImageAtFrame(QString path, QPoint topLeft, int frameNumber) { BitmapImage* pKeyFrame = new BitmapImage(topLeft, path); diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index df82cde52c..099cb61646 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -27,6 +27,10 @@ class LayerBitmap : public Layer Q_OBJECT public: + const QRgb transp = qRgba(0, 0, 0, 0); + const QRgb thinline = qRgba(0, 1, 0, 255); + const QRgb rosa = qRgba(255,230,230,255); + LayerBitmap(Object* object); ~LayerBitmap() override; @@ -38,11 +42,14 @@ class LayerBitmap : public Layer BitmapImage* getLastBitmapImageAtFrame(int frameNumber, int increment = 0); // color layer methods - void setIsColorLayer(bool value) { mIsColorLayer = value; } - bool getIsColorLayer() { return mIsColorLayer; } - BitmapImage* toTransparentScan(int frame); - void toBlackLine(int frame, int area); + void initColorLayer(Layer* fromLayer, LayerBitmap* colorlayer); + int getThreshold() { return mThreshold; } + void setThreshold(int threshold) { mThreshold = threshold; } + BitmapImage* scanToTransparent(int frame); + void toBlackLine(int frame); + void fillWhiteAreas(int frame, int area); void toThinBlackLine(int frame); + int fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, int frame); protected: Status saveKeyFrameFile(KeyFrame*, QString strPath) override; @@ -55,7 +62,6 @@ class LayerBitmap : public Layer bool needSaveFrame(KeyFrame* key, const QString& strSavePath); int mThreshold = 200; - bool mIsColorLayer = false; }; #endif From 72481486068552762a7db10c667241c9be66e5d4 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 27 Jan 2019 12:35:46 +0100 Subject: [PATCH 008/100] WIP thin line not working --- app/src/bitmapcoloring.cpp | 12 +- app/src/bitmapcoloring.h | 1 - core_lib/src/interface/editor.cpp | 39 ++++++- core_lib/src/interface/editor.h | 4 + core_lib/src/structure/layerbitmap.cpp | 145 +++++++++++++++++++++++-- core_lib/src/structure/layerbitmap.h | 7 +- 6 files changed, 188 insertions(+), 20 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index d158aada21..63e078a95c 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -40,6 +40,13 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : connect(ui->btn3_apply, &QPushButton::clicked, mEditor, &Editor::scanToTransparent); connect(ui->btn3_Next, &QPushButton::clicked, mEditor, &Editor::scrubNextKeyFrame); connect(ui->btn3_applyRest, &QPushButton::clicked, mEditor, &Editor::scanToTransparentRest); + connect(ui->sb4_fillArea, QOverload::of(&QSpinBox::valueChanged), mLayerBitmap, &LayerBitmap::setWhiteArea); + connect(ui->btn4_apply, &QPushButton::clicked, mEditor, &Editor::fillWhiteAreas); + connect(ui->btn4_next, &QPushButton::clicked, mEditor, &Editor::scrubNextKeyFrame); + connect(ui->btn4_applyRest, &QPushButton::clicked, mEditor, &Editor::fillWhiteAreasRest); + connect(ui->btn5_thin, &QPushButton::clicked, mEditor, &Editor::toThinBlackLine); + connect(ui->btn5_next, &QPushButton::clicked, mEditor, &Editor::scrubNextKeyFrame); + connect(ui->btn5_thinRest, &QPushButton::clicked, mEditor, &Editor::toThinBlackLineRest); } BitmapColoring::~BitmapColoring() @@ -66,8 +73,3 @@ void BitmapColoring::updateUI() setEnabled(false); } } - -void BitmapColoring::scanToTransparent() -{ - mEditor->scanToTransparent(); -} diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 182b1106a2..505f7c1219 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -26,7 +26,6 @@ class BitmapColoring : public BaseDockWidget signals: public slots: - void scanToTransparent(); private: Ui::BitmapColoringWidget* ui = nullptr; diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 1e96b44592..cc384e0124 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -598,12 +598,49 @@ void Editor::scanToTransparent() void Editor::scanToTransparentRest() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); - while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()) { + while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()) + { scrubNextKeyFrame(); layerBitmap->scanToTransparent(currentFrame()); } } +void Editor::fillWhiteAreas() +{ + LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); + layerBitmap->fillWhiteAreas(currentFrame()); + mScribbleArea->updateFrame(currentFrame()); +} + +void Editor::fillWhiteAreasRest() +{ + LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); + while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()) + { + scrubNextKeyFrame(); + layerBitmap->fillWhiteAreas(currentFrame()); + } + mScribbleArea->updateFrame(currentFrame()); +} + +void Editor::toThinBlackLine() +{ + LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); + layerBitmap->toThinBlackLine(currentFrame()); + mScribbleArea->updateFrame(currentFrame()); +} + +void Editor::toThinBlackLineRest() +{ + LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); + while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()) + { + scrubNextKeyFrame(); + layerBitmap->toThinBlackLine(currentFrame()); + } + mScribbleArea->updateFrame(currentFrame()); +} + void Editor::clipboardChanged() { if (clipboardBitmapOk == false) diff --git a/core_lib/src/interface/editor.h b/core_lib/src/interface/editor.h index a81a2c6668..36d317b0cd 100644 --- a/core_lib/src/interface/editor.h +++ b/core_lib/src/interface/editor.h @@ -154,6 +154,10 @@ class Editor : public QObject void copyFromScan(); void scanToTransparent(); void scanToTransparentRest(); + void fillWhiteAreas(); + void fillWhiteAreasRest(); + void toThinBlackLine(); + void toThinBlackLineRest(); void toogleOnionSkinType(); diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index 9f6cda9053..8c5df28819 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -102,7 +102,7 @@ void LayerBitmap::toBlackLine(int frame) } } -void LayerBitmap::fillWhiteAreas(int frame, int area) +void LayerBitmap::fillWhiteAreas(int frame) { if (!keyExists(frame)) { return; } @@ -117,13 +117,13 @@ void LayerBitmap::fillWhiteAreas(int frame, int area) { for (int y = 0; y < img->height(); y++) { - if (qAlpha(img->pixel(x,y)) == 255) + if (qAlpha(img->pixel(x + xOffset, y + yOffset)) == 0) { points.append(QPoint(x + xOffset, y + yOffset)); int areaSize = fillWithColor(QPoint(x + xOffset, y + yOffset), transp, rosa, frame); - if (areaSize <= area) + if (areaSize <= mWhiteArea) { // replace rosa with thinline (black) - fillWithColor(QPoint(x + xOffset, y + yOffset), rosa, thinline, frame); + fillWithColor(points.last(), rosa, thinline, frame); points.removeLast(); } } @@ -139,19 +139,142 @@ void LayerBitmap::fillWhiteAreas(int frame, int area) void LayerBitmap::toThinBlackLine(int frame) { BitmapImage* img = static_cast(getKeyFrameAt(frame)); - int xOffset = img->left(); - int yOffset = img->top(); - for (int x = 0; x < img->width(); x++) + int teller = 0, infound = 0, inElse = 0; + bool N = true, E = true, S = true, W = true, black, search; + while (N || E || S || W) { - for (int y = 0; y < img->height(); y++) + if (N) // from NORTH { - QColor c = img->pixel(x + xOffset, y + yOffset); - if (c.value() > 210) + // set 'black' to false. 'black' is set to true whenever a black pixel is removed + black = false; + // 'search' is true while pixels are transparent + // when thinline pixel is found, 'search' is set to false until next transparent pixel + search = true; + for (int x = img->left(); x <= img->right(); x++) { - + for (int y = img->top(); y < img->bottom(); y++) + { + if (search && qAlpha(img->pixel(x, y)) > 0) + { + infound++; + qDebug() << "x,y+1: " << qAlpha(img->pixel(x, y+1)); + if (qAlpha(img->pixel(x, y+1) > 0) && + (qAlpha(img->pixel(x+1, y)) > 0 || qAlpha(img->pixel(x+1, y+1)) > 0 || + qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x-1, y+1)) > 0)) + { + img->setPixel(x, y, transp); + black = true; + search = false; + teller++; + } + } + else + { + inElse++; + if (qAlpha(img->pixel(x,y)) == 0) + search = true; + } + } + } + N = black; // if none 'black' is removed, N = false + } + if (E) // from EAST + { + black = false; + search = true; + for (int y = img->top(); y <= img->bottom(); y++) + { + for (int x = img->right(); x > img->left(); x--) + { + if (search && qAlpha(img->pixel(x, y)) > 0) + { + infound++; + if (qAlpha(img->pixel(x-1, y) > 0) && + (qAlpha(img->pixel(x-1, y-1)) > 0 || qAlpha(img->pixel(x, y-1)) > 0 || + qAlpha(img->pixel(x-1, y+1)) > 0 || qAlpha(img->pixel(x, y+1)) > 0)) + { + img->setPixel(x, y, transp); + black = true; + search = false; + teller++; + } + } + else + { + inElse++; + if (qAlpha(img->pixel(x,y)) == 0) + search = true; + } + } + } + E = black; // if none 'black' is removed, E = false + } + if (S) // from SOUTH + { + black = false; + search = true; + for (int x = img->left(); x <= img->right(); x++) + { + for (int y = img->bottom(); y > img->top(); y--) + { + if (search && qAlpha(img->pixel(x, y)) > 0) + { + infound++; + if (qAlpha(img->pixel(x, y-1) > 0) && + ((qAlpha(img->pixel(x-1, y-1)) > 0 || qAlpha(img->pixel(x-1, y)) > 0 || + qAlpha(img->pixel(x+1, y-1)) > 0 || qAlpha(img->pixel(x+1, y)) > 0))) + { + img->setPixel(x, y, transp); + black = true; + search = false; + teller++; + } + } + else + { + inElse++; + if (qAlpha(img->pixel(x,y)) == 0) + search = true; + } + } + } + S = black; // if none 'black' is removed, S = false + } + if (W) // from WEST + { + black = false; + search = true; + for (int y = img->top(); y <= img->bottom(); y++) + { + for (int x = img->left(); x < img->right(); x++) + { + if (search && qAlpha(img->pixel(x, y)) > 0) + { + infound++; + if (qAlpha(img->pixel(x+1, y) > 0) && + (qAlpha(img->pixel(x, y-1)) > 0 || qAlpha(img->pixel(x+1, y-1)) > 0 || + qAlpha(img->pixel(x, y+1)) > 0 || qAlpha(img->pixel(x+1, y+1)) > 0)) + { + img->setPixel(x, y, transp); + black = true; + search = false; + teller++; + } + else + { + inElse++; + if (qAlpha(img->pixel(x,y)) == 0) + search = true; + } + } + W = black; // if none 'black' is removed, E = false + } } } } + qDebug() << "Finished thin line. Replaced :" << teller; + qDebug() << "Finished thin line. In found :" << infound; + qDebug() << "Finished thin line. In else :" << inElse; } int LayerBitmap::fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, int frame) diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index 099cb61646..09f84ca729 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -28,7 +28,7 @@ class LayerBitmap : public Layer public: const QRgb transp = qRgba(0, 0, 0, 0); - const QRgb thinline = qRgba(0, 1, 0, 255); + const QRgb thinline = qRgba(0, 0, 0, 255); const QRgb rosa = qRgba(255,230,230,255); LayerBitmap(Object* object); @@ -45,9 +45,11 @@ class LayerBitmap : public Layer void initColorLayer(Layer* fromLayer, LayerBitmap* colorlayer); int getThreshold() { return mThreshold; } void setThreshold(int threshold) { mThreshold = threshold; } + int getWhiteArea() { return mWhiteArea; } + void setWhiteArea(int whiteArea) { mWhiteArea = whiteArea; } BitmapImage* scanToTransparent(int frame); void toBlackLine(int frame); - void fillWhiteAreas(int frame, int area); + void fillWhiteAreas(int frame); void toThinBlackLine(int frame); int fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, int frame); @@ -62,6 +64,7 @@ class LayerBitmap : public Layer bool needSaveFrame(KeyFrame* key, const QString& strSavePath); int mThreshold = 200; + int mWhiteArea = 6; }; #endif From 1c9e5463930d9a2007f487d994314e9b24954c57 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 27 Jan 2019 16:12:12 +0100 Subject: [PATCH 009/100] WIP small bug corrected --- core_lib/src/structure/layerbitmap.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index 8c5df28819..60d39b85a8 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -154,13 +154,13 @@ void LayerBitmap::toThinBlackLine(int frame) { for (int y = img->top(); y < img->bottom(); y++) { - if (search && qAlpha(img->pixel(x, y)) > 0) + if (search && qAlpha(img->pixel(x, y)) > 0 && qAlpha(img->pixel(x, y+1)) > 0) { infound++; - qDebug() << "x,y+1: " << qAlpha(img->pixel(x, y+1)); - if (qAlpha(img->pixel(x, y+1) > 0) && +// qDebug() << "x,y+1: " << qAlpha(img->pixel(x+1, y)) << qAlpha(img->pixel(x+1, y+1)) << qAlpha(img->pixel(x-1, y)) << qAlpha(img->pixel(x-1, y+1)); + if (qAlpha(img->pixel(x, y+1)) > 0 && (qAlpha(img->pixel(x+1, y)) > 0 || qAlpha(img->pixel(x+1, y+1)) > 0 || - qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x-1, y+1)) > 0)) + qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x-1, y+1)) > 0)) { img->setPixel(x, y, transp); black = true; @@ -189,7 +189,7 @@ void LayerBitmap::toThinBlackLine(int frame) if (search && qAlpha(img->pixel(x, y)) > 0) { infound++; - if (qAlpha(img->pixel(x-1, y) > 0) && + if (qAlpha(img->pixel(x-1, y)) > 0 && (qAlpha(img->pixel(x-1, y-1)) > 0 || qAlpha(img->pixel(x, y-1)) > 0 || qAlpha(img->pixel(x-1, y+1)) > 0 || qAlpha(img->pixel(x, y+1)) > 0)) { @@ -220,7 +220,7 @@ void LayerBitmap::toThinBlackLine(int frame) if (search && qAlpha(img->pixel(x, y)) > 0) { infound++; - if (qAlpha(img->pixel(x, y-1) > 0) && + if (qAlpha(img->pixel(x, y-1)) > 0 && ((qAlpha(img->pixel(x-1, y-1)) > 0 || qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x+1, y-1)) > 0 || qAlpha(img->pixel(x+1, y)) > 0))) { @@ -251,7 +251,7 @@ void LayerBitmap::toThinBlackLine(int frame) if (search && qAlpha(img->pixel(x, y)) > 0) { infound++; - if (qAlpha(img->pixel(x+1, y) > 0) && + if (qAlpha(img->pixel(x+1, y)) > 0 && (qAlpha(img->pixel(x, y-1)) > 0 || qAlpha(img->pixel(x+1, y-1)) > 0 || qAlpha(img->pixel(x, y+1)) > 0 || qAlpha(img->pixel(x+1, y+1)) > 0)) { From 80288764bd1e24f9f9cb97601e2d272c5f640cd7 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 27 Jan 2019 21:23:53 +0100 Subject: [PATCH 010/100] WIP still not working --- core_lib/src/structure/layerbitmap.cpp | 262 ++++++++++++++++++++----- 1 file changed, 209 insertions(+), 53 deletions(-) diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index 60d39b85a8..a73b45cd03 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -139,7 +139,6 @@ void LayerBitmap::fillWhiteAreas(int frame) void LayerBitmap::toThinBlackLine(int frame) { BitmapImage* img = static_cast(getKeyFrameAt(frame)); - int teller = 0, infound = 0, inElse = 0; bool N = true, E = true, S = true, W = true, black, search; while (N || E || S || W) { @@ -150,27 +149,32 @@ void LayerBitmap::toThinBlackLine(int frame) // 'search' is true while pixels are transparent // when thinline pixel is found, 'search' is set to false until next transparent pixel search = true; - for (int x = img->left(); x <= img->right(); x++) + for (int x = img->left(); x < img->right(); x++) { for (int y = img->top(); y < img->bottom(); y++) { - if (search && qAlpha(img->pixel(x, y)) > 0 && qAlpha(img->pixel(x, y+1)) > 0) + if (search) { - infound++; -// qDebug() << "x,y+1: " << qAlpha(img->pixel(x+1, y)) << qAlpha(img->pixel(x+1, y+1)) << qAlpha(img->pixel(x-1, y)) << qAlpha(img->pixel(x-1, y+1)); - if (qAlpha(img->pixel(x, y+1)) > 0 && - (qAlpha(img->pixel(x+1, y)) > 0 || qAlpha(img->pixel(x+1, y+1)) > 0 || - qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x-1, y+1)) > 0)) + if (qAlpha(img->pixel(x,y)) > 0) { - img->setPixel(x, y, transp); - black = true; - search = false; - teller++; + if (qAlpha(img->pixel(x,y+1)) > 0) + { + if (qAlpha(img->pixel(x-1,y-1)) == 0 && qAlpha(img->pixel(x+1,y-1)) == 0) + { + if (qAlpha(img->pixel(x+1, y)) > 0 || qAlpha(img->pixel(x+1, y+1)) > 0 || + qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x-1, y+1)) > 0) + { + img->setPixel(x, y, transp); + black = true; + search = false; + } + } + } } } else { - inElse++; + qDebug() << qAlpha(img->pixel(x,y)); if (qAlpha(img->pixel(x,y)) == 0) search = true; } @@ -182,26 +186,32 @@ void LayerBitmap::toThinBlackLine(int frame) { black = false; search = true; - for (int y = img->top(); y <= img->bottom(); y++) + for (int y = img->top(); y < img->bottom(); y++) { for (int x = img->right(); x > img->left(); x--) { - if (search && qAlpha(img->pixel(x, y)) > 0) + if (search) { - infound++; - if (qAlpha(img->pixel(x-1, y)) > 0 && - (qAlpha(img->pixel(x-1, y-1)) > 0 || qAlpha(img->pixel(x, y-1)) > 0 || - qAlpha(img->pixel(x-1, y+1)) > 0 || qAlpha(img->pixel(x, y+1)) > 0)) + if (qAlpha(img->pixel(x,y)) > 0) { - img->setPixel(x, y, transp); - black = true; - search = false; - teller++; + if (qAlpha(img->pixel(x-1,y)) > 0) + { + if (qAlpha(img->pixel(x+1,y-1)) == 0 && qAlpha(img->pixel(x+1,y+1)) == 0) + { + if (qAlpha(img->pixel(x-1, y-1)) > 0 || qAlpha(img->pixel(x, y-1)) > 0 || + qAlpha(img->pixel(x-1, y+1)) > 0 || qAlpha(img->pixel(x, y+1)) > 0) + { + img->setPixel(x, y, transp); + black = true; + search = false; + } + } + } } } else { - inElse++; + qDebug() << qAlpha(img->pixel(x,y)); if (qAlpha(img->pixel(x,y)) == 0) search = true; } @@ -215,24 +225,30 @@ void LayerBitmap::toThinBlackLine(int frame) search = true; for (int x = img->left(); x <= img->right(); x++) { - for (int y = img->bottom(); y > img->top(); y--) + for (int y = img->bottom(); y < img->top(); y--) { - if (search && qAlpha(img->pixel(x, y)) > 0) + if (search) { - infound++; - if (qAlpha(img->pixel(x, y-1)) > 0 && - ((qAlpha(img->pixel(x-1, y-1)) > 0 || qAlpha(img->pixel(x-1, y)) > 0 || - qAlpha(img->pixel(x+1, y-1)) > 0 || qAlpha(img->pixel(x+1, y)) > 0))) + if (qAlpha(img->pixel(x,y)) > 0) { - img->setPixel(x, y, transp); - black = true; - search = false; - teller++; + if (qAlpha(img->pixel(x,y-1)) > 0) + { + if (qAlpha(img->pixel(x-1,y+1)) == 0 && qAlpha(img->pixel(x+1,y+1)) == 0) + { + if (qAlpha(img->pixel(x+1, y)) > 0 || qAlpha(img->pixel(x+1, y-1)) > 0 || + qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x-1, y-1)) > 0) + { + img->setPixel(x, y, transp); + black = true; + search = false; + } + } + } } } else { - inElse++; + qDebug() << qAlpha(img->pixel(x,y)); if (qAlpha(img->pixel(x,y)) == 0) search = true; } @@ -248,35 +264,175 @@ void LayerBitmap::toThinBlackLine(int frame) { for (int x = img->left(); x < img->right(); x++) { - if (search && qAlpha(img->pixel(x, y)) > 0) + if (search) + { + if (qAlpha(img->pixel(x,y)) > 0) + { + if (qAlpha(img->pixel(x+1,y)) > 0) + { + if (qAlpha(img->pixel(x-1,y-1)) == 0 && qAlpha(img->pixel(x-1,y+1)) == 0) + { + if (qAlpha(img->pixel(x, y-1)) > 0 || qAlpha(img->pixel(x+1, y-1)) > 0 || + qAlpha(img->pixel(x, y+1)) > 0 || qAlpha(img->pixel(x+1, y+1)) > 0) + { + img->setPixel(x, y, transp); + black = true; + search = false; + } + } + } + } + } + else + { + qDebug() << qAlpha(img->pixel(x,y)); + if (qAlpha(img->pixel(x,y)) == 0) + search = true; + } + } + } + W = black; // if none 'black' is removed, E = false + } + } +} + +/* +void LayerBitmap::toThinBlackLine(int frame) +{ + BitmapImage* img = static_cast(getKeyFrameAt(frame)); + bool N = true, E = true, S = true, W = true, black, search; + while (N || E || S || W) + { + if (N) // from NORTH + { + // set 'black' to false. 'black' is set to true whenever a black pixel is removed + black = false; + // 'search' is true while pixels are transparent + // when thinline pixel is found, 'search' is set to false until next transparent pixel + search = true; + for (int x = img->left(); x <= img->right(); x++) + { + for (int y = img->top(); y < img->bottom(); y++) + { + if (search) + { + if (qAlpha(img->pixel(x, y)) > 0 && qAlpha(img->pixel(x, y+1)) > 0 && + qAlpha(img->pixel(x-1, y-1)) == 0 && qAlpha(img->pixel(x+1, y-1)) == 0) + { + if (qAlpha(img->pixel(x+1, y)) > 0 || qAlpha(img->pixel(x+1, y+1)) > 0 || + qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x-1, y+1)) > 0) + { + img->setPixel(x, y, transp); + black = true; + search = false; + } + } + } + else + { + if (qAlpha(img->pixel(x,y)) == 0) + search = true; + } + } + } + N = black; // if none 'black' is removed, N = false + } + if (E) // from EAST + { + black = false; + search = true; + for (int y = img->top(); y <= img->bottom(); y++) + { + for (int x = img->right(); x > img->left(); x--) + { + if (search) { - infound++; - if (qAlpha(img->pixel(x+1, y)) > 0 && - (qAlpha(img->pixel(x, y-1)) > 0 || qAlpha(img->pixel(x+1, y-1)) > 0 || - qAlpha(img->pixel(x, y+1)) > 0 || qAlpha(img->pixel(x+1, y+1)) > 0)) + if (qAlpha(img->pixel(x, y)) > 0 && qAlpha(img->pixel(x-1, y)) > 0 && + qAlpha(img->pixel(x+1, y-1)) == 0 && qAlpha(img->pixel(x+1, y+1)) == 0) { - img->setPixel(x, y, transp); - black = true; - search = false; - teller++; + if (qAlpha(img->pixel(x-1, y+1)) > 0 || qAlpha(img->pixel(x, y+1)) > 0 || + qAlpha(img->pixel(x, y-1)) > 0 || qAlpha(img->pixel(x-1, y-1)) > 0) + { + img->setPixel(x, y, transp); + black = true; + search = false; + } } - else + } + else + { + if (qAlpha(img->pixel(x,y)) == 0) + search = true; + } + } + } + E = black; // if none 'black' is removed, E = false + } + if (S) // from SOUTH + { + black = false; + search = true; + for (int x = img->left(); x <= img->right(); x++) + { + for (int y = img->bottom(); y < img->top(); y--) + { + if (search) + { + if (qAlpha(img->pixel(x, y)) > 0 && qAlpha(img->pixel(x, y-1)) > 0 && + qAlpha(img->pixel(x+1, y+1)) == 0 && qAlpha(img->pixel(x-1, y+1)) == 0) { - inElse++; - if (qAlpha(img->pixel(x,y)) == 0) - search = true; + if (qAlpha(img->pixel(x+1, y)) > 0 || qAlpha(img->pixel(x+1, y-1)) > 0 || + qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x-1, y-1)) > 0) + { + img->setPixel(x, y, transp); + black = true; + search = false; + } } } - W = black; // if none 'black' is removed, E = false + else + { + if (qAlpha(img->pixel(x,y)) == 0) + search = true; + } } } + S = black; // if none 'black' is removed, S = false + } + if (W) // from WEST + { + black = false; + search = true; + for (int y = img->top(); y <= img->bottom(); y++) + { + for (int x = img->left(); x < img->right(); x++) + { + if (search) + { + if (qAlpha(img->pixel(x, y)) > 0 && qAlpha(img->pixel(x+1, y)) > 0 && + qAlpha(img->pixel(x-1, y-1)) == 0 && qAlpha(img->pixel(x-1, y+1)) == 0) + { + if (qAlpha(img->pixel(x+1, y+1)) > 0 || qAlpha(img->pixel(x, y+1)) > 0 || + qAlpha(img->pixel(x, y-1)) > 0 || qAlpha(img->pixel(x+1, y-1)) > 0) + { + img->setPixel(x, y, transp); + black = true; + search = false; + } + } + } + else + { + if (qAlpha(img->pixel(x,y)) == 0) + search = true; + } + } + } + W = black; // if none 'black' is removed, E = false } } - qDebug() << "Finished thin line. Replaced :" << teller; - qDebug() << "Finished thin line. In found :" << infound; - qDebug() << "Finished thin line. In else :" << inElse; } - +*/ int LayerBitmap::fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, int frame) { BitmapImage* img = static_cast(getKeyFrameAt(frame)); From 7f9fc6c7644370f2b7c5f092ca80002c06911ff1 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 27 Jan 2019 22:12:11 +0100 Subject: [PATCH 011/100] WIP still not working --- core_lib/src/structure/layerbitmap.cpp | 38 ++++++++++++-------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index a73b45cd03..d336710d1f 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -174,7 +174,6 @@ void LayerBitmap::toThinBlackLine(int frame) } else { - qDebug() << qAlpha(img->pixel(x,y)); if (qAlpha(img->pixel(x,y)) == 0) search = true; } @@ -182,24 +181,24 @@ void LayerBitmap::toThinBlackLine(int frame) } N = black; // if none 'black' is removed, N = false } - if (E) // from EAST + if (S) // from SOUTH { black = false; search = true; - for (int y = img->top(); y < img->bottom(); y++) + for (int x = img->left(); x < img->right(); x++) { - for (int x = img->right(); x > img->left(); x--) + for (int y = img->bottom(); y > img->top(); y--) { if (search) { if (qAlpha(img->pixel(x,y)) > 0) { - if (qAlpha(img->pixel(x-1,y)) > 0) + if (qAlpha(img->pixel(x,y-1)) > 0) { - if (qAlpha(img->pixel(x+1,y-1)) == 0 && qAlpha(img->pixel(x+1,y+1)) == 0) + if (qAlpha(img->pixel(x-1,y+1)) == 0 && qAlpha(img->pixel(x+1,y+1)) == 0) { - if (qAlpha(img->pixel(x-1, y-1)) > 0 || qAlpha(img->pixel(x, y-1)) > 0 || - qAlpha(img->pixel(x-1, y+1)) > 0 || qAlpha(img->pixel(x, y+1)) > 0) + if (qAlpha(img->pixel(x+1, y)) > 0 || qAlpha(img->pixel(x+1, y-1)) > 0 || + qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x-1, y-1)) > 0) { img->setPixel(x, y, transp); black = true; @@ -211,32 +210,31 @@ void LayerBitmap::toThinBlackLine(int frame) } else { - qDebug() << qAlpha(img->pixel(x,y)); if (qAlpha(img->pixel(x,y)) == 0) search = true; } } } - E = black; // if none 'black' is removed, E = false + S = black; // if none 'black' is removed, S = false } - if (S) // from SOUTH + if (E) // from EAST { black = false; search = true; - for (int x = img->left(); x <= img->right(); x++) + for (int y = img->top(); y < img->bottom(); y++) { - for (int y = img->bottom(); y < img->top(); y--) + for (int x = img->right(); x > img->left(); x--) { if (search) { if (qAlpha(img->pixel(x,y)) > 0) { - if (qAlpha(img->pixel(x,y-1)) > 0) + if (qAlpha(img->pixel(x-1,y)) > 0) { - if (qAlpha(img->pixel(x-1,y+1)) == 0 && qAlpha(img->pixel(x+1,y+1)) == 0) + if (qAlpha(img->pixel(x+1,y-1)) == 0 && qAlpha(img->pixel(x+1,y+1)) == 0) { - if (qAlpha(img->pixel(x+1, y)) > 0 || qAlpha(img->pixel(x+1, y-1)) > 0 || - qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x-1, y-1)) > 0) + if (qAlpha(img->pixel(x-1, y-1)) > 0 || qAlpha(img->pixel(x, y-1)) > 0 || + qAlpha(img->pixel(x-1, y+1)) > 0 || qAlpha(img->pixel(x, y+1)) > 0) { img->setPixel(x, y, transp); black = true; @@ -248,13 +246,12 @@ void LayerBitmap::toThinBlackLine(int frame) } else { - qDebug() << qAlpha(img->pixel(x,y)); if (qAlpha(img->pixel(x,y)) == 0) search = true; } } } - S = black; // if none 'black' is removed, S = false + E = black; // if none 'black' is removed, E = false } if (W) // from WEST { @@ -285,13 +282,12 @@ void LayerBitmap::toThinBlackLine(int frame) } else { - qDebug() << qAlpha(img->pixel(x,y)); if (qAlpha(img->pixel(x,y)) == 0) search = true; } } } - W = black; // if none 'black' is removed, E = false + W = black; // if none 'black' is removed, W = false } } } From 27fd3346c23a92da54f4366bcbbe27f87ac5b648 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 27 Jan 2019 23:23:35 +0100 Subject: [PATCH 012/100] Thin line function works now --- core_lib/src/structure/layerbitmap.cpp | 145 +------------------------ 1 file changed, 4 insertions(+), 141 deletions(-) diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index d336710d1f..d3899e2d67 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -157,6 +157,7 @@ void LayerBitmap::toThinBlackLine(int frame) { if (qAlpha(img->pixel(x,y)) > 0) { + search = false; if (qAlpha(img->pixel(x,y+1)) > 0) { if (qAlpha(img->pixel(x-1,y-1)) == 0 && qAlpha(img->pixel(x+1,y-1)) == 0) @@ -166,7 +167,6 @@ void LayerBitmap::toThinBlackLine(int frame) { img->setPixel(x, y, transp); black = true; - search = false; } } } @@ -193,6 +193,7 @@ void LayerBitmap::toThinBlackLine(int frame) { if (qAlpha(img->pixel(x,y)) > 0) { + search = false; if (qAlpha(img->pixel(x,y-1)) > 0) { if (qAlpha(img->pixel(x-1,y+1)) == 0 && qAlpha(img->pixel(x+1,y+1)) == 0) @@ -202,7 +203,6 @@ void LayerBitmap::toThinBlackLine(int frame) { img->setPixel(x, y, transp); black = true; - search = false; } } } @@ -229,6 +229,7 @@ void LayerBitmap::toThinBlackLine(int frame) { if (qAlpha(img->pixel(x,y)) > 0) { + search = false; if (qAlpha(img->pixel(x-1,y)) > 0) { if (qAlpha(img->pixel(x+1,y-1)) == 0 && qAlpha(img->pixel(x+1,y+1)) == 0) @@ -238,7 +239,6 @@ void LayerBitmap::toThinBlackLine(int frame) { img->setPixel(x, y, transp); black = true; - search = false; } } } @@ -265,6 +265,7 @@ void LayerBitmap::toThinBlackLine(int frame) { if (qAlpha(img->pixel(x,y)) > 0) { + search = false; if (qAlpha(img->pixel(x+1,y)) > 0) { if (qAlpha(img->pixel(x-1,y-1)) == 0 && qAlpha(img->pixel(x-1,y+1)) == 0) @@ -274,7 +275,6 @@ void LayerBitmap::toThinBlackLine(int frame) { img->setPixel(x, y, transp); black = true; - search = false; } } } @@ -292,143 +292,6 @@ void LayerBitmap::toThinBlackLine(int frame) } } -/* -void LayerBitmap::toThinBlackLine(int frame) -{ - BitmapImage* img = static_cast(getKeyFrameAt(frame)); - bool N = true, E = true, S = true, W = true, black, search; - while (N || E || S || W) - { - if (N) // from NORTH - { - // set 'black' to false. 'black' is set to true whenever a black pixel is removed - black = false; - // 'search' is true while pixels are transparent - // when thinline pixel is found, 'search' is set to false until next transparent pixel - search = true; - for (int x = img->left(); x <= img->right(); x++) - { - for (int y = img->top(); y < img->bottom(); y++) - { - if (search) - { - if (qAlpha(img->pixel(x, y)) > 0 && qAlpha(img->pixel(x, y+1)) > 0 && - qAlpha(img->pixel(x-1, y-1)) == 0 && qAlpha(img->pixel(x+1, y-1)) == 0) - { - if (qAlpha(img->pixel(x+1, y)) > 0 || qAlpha(img->pixel(x+1, y+1)) > 0 || - qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x-1, y+1)) > 0) - { - img->setPixel(x, y, transp); - black = true; - search = false; - } - } - } - else - { - if (qAlpha(img->pixel(x,y)) == 0) - search = true; - } - } - } - N = black; // if none 'black' is removed, N = false - } - if (E) // from EAST - { - black = false; - search = true; - for (int y = img->top(); y <= img->bottom(); y++) - { - for (int x = img->right(); x > img->left(); x--) - { - if (search) - { - if (qAlpha(img->pixel(x, y)) > 0 && qAlpha(img->pixel(x-1, y)) > 0 && - qAlpha(img->pixel(x+1, y-1)) == 0 && qAlpha(img->pixel(x+1, y+1)) == 0) - { - if (qAlpha(img->pixel(x-1, y+1)) > 0 || qAlpha(img->pixel(x, y+1)) > 0 || - qAlpha(img->pixel(x, y-1)) > 0 || qAlpha(img->pixel(x-1, y-1)) > 0) - { - img->setPixel(x, y, transp); - black = true; - search = false; - } - } - } - else - { - if (qAlpha(img->pixel(x,y)) == 0) - search = true; - } - } - } - E = black; // if none 'black' is removed, E = false - } - if (S) // from SOUTH - { - black = false; - search = true; - for (int x = img->left(); x <= img->right(); x++) - { - for (int y = img->bottom(); y < img->top(); y--) - { - if (search) - { - if (qAlpha(img->pixel(x, y)) > 0 && qAlpha(img->pixel(x, y-1)) > 0 && - qAlpha(img->pixel(x+1, y+1)) == 0 && qAlpha(img->pixel(x-1, y+1)) == 0) - { - if (qAlpha(img->pixel(x+1, y)) > 0 || qAlpha(img->pixel(x+1, y-1)) > 0 || - qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x-1, y-1)) > 0) - { - img->setPixel(x, y, transp); - black = true; - search = false; - } - } - } - else - { - if (qAlpha(img->pixel(x,y)) == 0) - search = true; - } - } - } - S = black; // if none 'black' is removed, S = false - } - if (W) // from WEST - { - black = false; - search = true; - for (int y = img->top(); y <= img->bottom(); y++) - { - for (int x = img->left(); x < img->right(); x++) - { - if (search) - { - if (qAlpha(img->pixel(x, y)) > 0 && qAlpha(img->pixel(x+1, y)) > 0 && - qAlpha(img->pixel(x-1, y-1)) == 0 && qAlpha(img->pixel(x-1, y+1)) == 0) - { - if (qAlpha(img->pixel(x+1, y+1)) > 0 || qAlpha(img->pixel(x, y+1)) > 0 || - qAlpha(img->pixel(x, y-1)) > 0 || qAlpha(img->pixel(x+1, y-1)) > 0) - { - img->setPixel(x, y, transp); - black = true; - search = false; - } - } - } - else - { - if (qAlpha(img->pixel(x,y)) == 0) - search = true; - } - } - } - W = black; // if none 'black' is removed, E = false - } - } -} -*/ int LayerBitmap::fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, int frame) { BitmapImage* img = static_cast(getKeyFrameAt(frame)); From 7b5c2a6a38d093338e2de972de9dc5f9eb822f2f Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Tue, 29 Jan 2019 06:26:04 +0100 Subject: [PATCH 013/100] Replace thinline works --- app/src/bitmapcoloring.cpp | 1 + core_lib/src/interface/editor.cpp | 19 ++++++++ core_lib/src/interface/editor.h | 1 + core_lib/src/structure/layerbitmap.cpp | 65 +++++++++++++++++++++----- core_lib/src/structure/layerbitmap.h | 1 + 5 files changed, 75 insertions(+), 12 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 63e078a95c..c71110e46e 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -47,6 +47,7 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : connect(ui->btn5_thin, &QPushButton::clicked, mEditor, &Editor::toThinBlackLine); connect(ui->btn5_next, &QPushButton::clicked, mEditor, &Editor::scrubNextKeyFrame); connect(ui->btn5_thinRest, &QPushButton::clicked, mEditor, &Editor::toThinBlackLineRest); + connect(ui->btn7_replaceThinLines, &QPushButton::clicked, mEditor, &Editor::replaceThinLines); } BitmapColoring::~BitmapColoring() diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index cc384e0124..cdd638e894 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -591,6 +591,7 @@ void Editor::copyFromScan() void Editor::scanToTransparent() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); + mObject->updateActiveFrames(currentFrame()); layerBitmap->scanToTransparent(currentFrame()); mScribbleArea->updateFrame(currentFrame()); } @@ -598,6 +599,7 @@ void Editor::scanToTransparent() void Editor::scanToTransparentRest() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); + mObject->updateActiveFrames(currentFrame()); while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()) { scrubNextKeyFrame(); @@ -608,6 +610,7 @@ void Editor::scanToTransparentRest() void Editor::fillWhiteAreas() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); + mObject->updateActiveFrames(currentFrame()); layerBitmap->fillWhiteAreas(currentFrame()); mScribbleArea->updateFrame(currentFrame()); } @@ -618,6 +621,7 @@ void Editor::fillWhiteAreasRest() while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()) { scrubNextKeyFrame(); + mObject->updateActiveFrames(currentFrame()); layerBitmap->fillWhiteAreas(currentFrame()); } mScribbleArea->updateFrame(currentFrame()); @@ -626,6 +630,7 @@ void Editor::fillWhiteAreasRest() void Editor::toThinBlackLine() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); + mObject->updateActiveFrames(currentFrame()); layerBitmap->toThinBlackLine(currentFrame()); mScribbleArea->updateFrame(currentFrame()); } @@ -636,11 +641,25 @@ void Editor::toThinBlackLineRest() while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()) { scrubNextKeyFrame(); + mObject->updateActiveFrames(currentFrame()); layerBitmap->toThinBlackLine(currentFrame()); } mScribbleArea->updateFrame(currentFrame()); } +void Editor::replaceThinLines() +{ + LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); + do + { + mObject->updateActiveFrames(currentFrame()); + layerBitmap->replaceThinLine(currentFrame()); + scrubNextKeyFrame(); + qDebug() << "replace thin..." << currentFrame(); + } while (layerBitmap->getNextKeyFramePosition(currentFrame()) != currentFrame()); + mScribbleArea->updateFrame(currentFrame()); +} + void Editor::clipboardChanged() { if (clipboardBitmapOk == false) diff --git a/core_lib/src/interface/editor.h b/core_lib/src/interface/editor.h index 36d317b0cd..dcee331358 100644 --- a/core_lib/src/interface/editor.h +++ b/core_lib/src/interface/editor.h @@ -158,6 +158,7 @@ class Editor : public QObject void fillWhiteAreasRest(); void toThinBlackLine(); void toThinBlackLineRest(); + void replaceThinLines(); void toogleOnionSkinType(); diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index d3899e2d67..4f2f5a14de 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -23,6 +23,7 @@ GNU General Public License for more details. #include "keyframe.h" #include "bitmapimage.h" #include +#include LayerBitmap::LayerBitmap(Object* object) : Layer(object, Layer::BITMAP) @@ -59,26 +60,26 @@ void LayerBitmap::initColorLayer(Layer *fromLayer, LayerBitmap *colorlayer) BitmapImage* LayerBitmap::scanToTransparent(int frame) { BitmapImage* img = static_cast(getKeyFrameAt(frame)); - int xOffset = img->left(); - int yOffset = img->top(); - for (int x = 0; x < img->width(); x++) + QRgb rgba; + int grayValue; + for (int x = img->left(); x <= img->right(); x++) { - for (int y = 0; y < img->height(); y++) + for (int y = img->top(); y <= img->bottom(); y++) { - QColor c = img->pixel(x + xOffset, y + yOffset); - if (c.value() >= mThreshold) + rgba = img->pixel(x, y); + grayValue = (qRed(rgba) + qGreen(rgba) + qBlue(rgba)) / 3; + if (grayValue >= mThreshold) { - img->setPixel(x + xOffset, y + yOffset, transp); + img->setPixel(x, y, transp); } - else if(c.value() > 99 && c.value() < mThreshold) + else if(grayValue > 39 && grayValue < mThreshold) { - int alpha = static_cast(floor(255 - 255/(mThreshold - 100) * (c.value() - 100))); - QRgb rgba = qRgba(c.value(), c.value(), c.value(), alpha); - img->setPixel(x + xOffset, y + yOffset, rgba); + int alpha = static_cast(floor(255 - 255 * (grayValue - 40)/(mThreshold - 40) )); + QRgb rgba = qRgba(grayValue, grayValue, grayValue, alpha); + img->setPixel(x , y, rgba); } } } - qDebug() << img->bounds(); return img; } @@ -292,6 +293,46 @@ void LayerBitmap::toThinBlackLine(int frame) } } +void LayerBitmap::replaceThinLine(int frame) +{ + BitmapImage* img = static_cast(getKeyFrameAt(frame)); + int r, g, b, a; //red, green, blue, alpha + QList points; + for (int x = img->left(); x <= img->right(); x++) + { + for (int y = img->top(); y <= img->bottom(); y++) + { + points.clear(); + r=0; g=0; b=0; a=0; + if (img->pixel(x,y) == thinline) + { + qDebug() << "in replace..."; + if (img->pixel(x-1, y-1) != thinline) points.append(QPoint(x-1, y-1)); + if (img->pixel(x-1, y ) != thinline) points.append(QPoint(x-1, y )); + if (img->pixel(x-1, y+1) != thinline) points.append(QPoint(x-1, y+1)); + if (img->pixel(x , y-1) != thinline) points.append(QPoint(x , y-1)); + if (img->pixel(x , y+1) != thinline) points.append(QPoint(x , y+1)); + if (img->pixel(x+1, y-1) != thinline) points.append(QPoint(x+1, y-1)); + if (img->pixel(x+1, y ) != thinline) points.append(QPoint(x+1, y )); + if (img->pixel(x+1, y+1) != thinline) points.append(QPoint(x+1, y+1)); + + for (int i = 0; i < points.size(); i++) + { + r += qPow(qRed(img->pixel(points.at(i))), 2); + g += qPow(qGreen(img->pixel(points.at(i))), 2); + b += qPow(qBlue(img->pixel(points.at(i))), 2); + a += qPow(qAlpha(img->pixel(points.at(i))), 2); + } + r = static_cast(sqrt(r/points.size())); + g = static_cast(sqrt(g/points.size())); + b = static_cast(sqrt(b/points.size())); + a = static_cast(sqrt(a/points.size())); + img->setPixel(x, y, qRgba(r, g, b, a)); + } + } + } +} + int LayerBitmap::fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, int frame) { BitmapImage* img = static_cast(getKeyFrameAt(frame)); diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index 09f84ca729..8a95b3c63f 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -51,6 +51,7 @@ class LayerBitmap : public Layer void toBlackLine(int frame); void fillWhiteAreas(int frame); void toThinBlackLine(int frame); + void replaceThinLine(int frame); int fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, int frame); protected: From 71f41ba2205d29ca93927643e8d99aa8373b1e85 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Tue, 29 Jan 2019 11:12:22 +0100 Subject: [PATCH 014/100] ui changes and change in transp-calculation --- app/ui/bitmapcoloringwidget.ui | 14 ++++++++++++++ core_lib/src/interface/editor.cpp | 6 ++++-- core_lib/src/structure/layerbitmap.cpp | 4 ++-- core_lib/src/structure/layerbitmap.h | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index a1fda8a76f..47c39feeaf 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -477,6 +477,20 @@ 7 + + + + All drawings must be finished! + + + + + + + Handle with care... + + + diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index cdd638e894..125c85348c 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -650,13 +650,15 @@ void Editor::toThinBlackLineRest() void Editor::replaceThinLines() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); - do + while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()) { mObject->updateActiveFrames(currentFrame()); layerBitmap->replaceThinLine(currentFrame()); scrubNextKeyFrame(); qDebug() << "replace thin..." << currentFrame(); - } while (layerBitmap->getNextKeyFramePosition(currentFrame()) != currentFrame()); + } + scrubNextKeyFrame(); + layerBitmap->replaceThinLine(currentFrame()); mScribbleArea->updateFrame(currentFrame()); } diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index 4f2f5a14de..b38cc5aafb 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -72,9 +72,9 @@ BitmapImage* LayerBitmap::scanToTransparent(int frame) { img->setPixel(x, y, transp); } - else if(grayValue > 39 && grayValue < mThreshold) + else if(grayValue > mLowThreshold - 1 && grayValue < mThreshold) { - int alpha = static_cast(floor(255 - 255 * (grayValue - 40)/(mThreshold - 40) )); + int alpha = static_cast(floor(255 - 255 * (grayValue - mLowThreshold)/(mThreshold - mLowThreshold) )); QRgb rgba = qRgba(grayValue, grayValue, grayValue, alpha); img->setPixel(x , y, rgba); } diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index 8a95b3c63f..2654fe44c5 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -65,6 +65,7 @@ class LayerBitmap : public Layer bool needSaveFrame(KeyFrame* key, const QString& strSavePath); int mThreshold = 200; + const int mLowThreshold = 100; // threshold for images to be given transparency int mWhiteArea = 6; }; From 48240cb74e1aae7bfc274b8ba0be186afc20dd86 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Tue, 29 Jan 2019 23:01:54 +0100 Subject: [PATCH 015/100] removed some dead code --- core_lib/src/managers/layermanager.cpp | 10 ---------- core_lib/src/managers/layermanager.h | 1 - core_lib/src/structure/layerbitmap.cpp | 2 +- 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/core_lib/src/managers/layermanager.cpp b/core_lib/src/managers/layermanager.cpp index 1baa8afb56..ac3ea2782d 100644 --- a/core_lib/src/managers/layermanager.cpp +++ b/core_lib/src/managers/layermanager.cpp @@ -153,17 +153,7 @@ LayerBitmap* LayerManager::createBitmapLayer(const QString& strLayerName) return layer; } -/* -LayerBitmap* LayerManager::createBitmapColorLayer(const QString& strLayerName) -{ - LayerBitmap* layer = object()->addNewBitmapLayer(); - layer->setName(strLayerName); - Q_EMIT layerCountChanged(count()); - - return layer; -} -*/ LayerVector* LayerManager::createVectorLayer(const QString& strLayerName) { LayerVector* layer = object()->addNewVectorLayer(); diff --git a/core_lib/src/managers/layermanager.h b/core_lib/src/managers/layermanager.h index 16bbca766a..886818536a 100644 --- a/core_lib/src/managers/layermanager.h +++ b/core_lib/src/managers/layermanager.h @@ -57,7 +57,6 @@ class LayerManager : public BaseManager void gotoPreviouslayer(); LayerBitmap* createBitmapLayer(const QString& strLayerName); -// LayerBitmap* createBitmapColorLayer(const QString& strLayerName); LayerVector* createVectorLayer(const QString& strLayerName); LayerCamera* createCameraLayer(const QString& strLayerName); LayerSound* createSoundLayer(const QString& strLayerName); diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index b38cc5aafb..39e86cb033 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -296,6 +296,7 @@ void LayerBitmap::toThinBlackLine(int frame) void LayerBitmap::replaceThinLine(int frame) { BitmapImage* img = static_cast(getKeyFrameAt(frame)); + int r, g, b, a; //red, green, blue, alpha QList points; for (int x = img->left(); x <= img->right(); x++) @@ -315,7 +316,6 @@ void LayerBitmap::replaceThinLine(int frame) if (img->pixel(x+1, y-1) != thinline) points.append(QPoint(x+1, y-1)); if (img->pixel(x+1, y ) != thinline) points.append(QPoint(x+1, y )); if (img->pixel(x+1, y+1) != thinline) points.append(QPoint(x+1, y+1)); - for (int i = 0; i < points.size(); i++) { r += qPow(qRed(img->pixel(points.at(i))), 2); From daa1fbc2b1a11dc694fb11da13a1501e80bf12c1 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Wed, 30 Jan 2019 13:58:33 +0100 Subject: [PATCH 016/100] WIP coloring not working yet --- core_lib/src/structure/layerbitmap.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index 39e86cb033..47d9e63bcf 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -67,17 +67,27 @@ BitmapImage* LayerBitmap::scanToTransparent(int frame) for (int y = img->top(); y <= img->bottom(); y++) { rgba = img->pixel(x, y); - grayValue = (qRed(rgba) + qGreen(rgba) + qBlue(rgba)) / 3; - if (grayValue >= mThreshold) +// grayValue = (qRed(rgba) + qGreen(rgba) + qBlue(rgba)) / 3; + if (qGray(rgba) >= mThreshold) { img->setPixel(x, y, transp); } - else if(grayValue > mLowThreshold - 1 && grayValue < mThreshold) + /* + else { - int alpha = static_cast(floor(255 - 255 * (grayValue - mLowThreshold)/(mThreshold - mLowThreshold) )); - QRgb rgba = qRgba(grayValue, grayValue, grayValue, alpha); + QRgb rgba = qRgba(grayValue, grayValue, grayValue, 255 - grayValue); img->setPixel(x , y, rgba); } + */ + else if(qGray(rgba) > mThreshold - 60) + { + +// int alpha = static_cast(floor(255 - 255 * (grayValue - mLowThreshold)/(mThreshold - mLowThreshold) )); + QRgb tmp = qRgba(qGray(rgba), qGray(rgba), qGray(rgba), 255 - qGray(rgba)); + + img->setPixel(x , y, tmp); + } + } } return img; From aff05ee27533b0b5f50137d7d6e52583034b8c81 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Thu, 31 Jan 2019 22:13:05 +0100 Subject: [PATCH 017/100] WIP still not working --- app/ui/bitmapcoloringwidget.ui | 64 +++++++++++++++++++++++++- core_lib/src/interface/editor.cpp | 8 ++++ core_lib/src/interface/editor.h | 1 + core_lib/src/structure/layerbitmap.cpp | 50 ++++++++++---------- core_lib/src/structure/layerbitmap.h | 1 + 5 files changed, 98 insertions(+), 26 deletions(-) diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index 47c39feeaf..06d5f1d62b 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -59,6 +59,13 @@ + + + + x. Black line (for repairs!) + + + @@ -80,7 +87,7 @@ - 0 + 3 @@ -251,10 +258,65 @@ + + + x + + + + + + + + Make line all black. + + + + + + + + 75 + true + true + + + + Use only on color layer! + + + + + + + To Black line + + + + + + + Qt::Vertical + + + + 20 + 18 + + + + + + + + + + false + QFrame::StyledPanel diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 125c85348c..b0c86568fe 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -607,6 +607,14 @@ void Editor::scanToTransparentRest() } } +void Editor::toBlackLine() +{ + LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); + mObject->updateActiveFrames(currentFrame()); + layerBitmap->singleInitColorLayer(layerBitmap, layerBitmap, currentFrame()); + mScribbleArea->updateFrame(currentFrame()); +} + void Editor::fillWhiteAreas() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); diff --git a/core_lib/src/interface/editor.h b/core_lib/src/interface/editor.h index dcee331358..930df04277 100644 --- a/core_lib/src/interface/editor.h +++ b/core_lib/src/interface/editor.h @@ -154,6 +154,7 @@ class Editor : public QObject void copyFromScan(); void scanToTransparent(); void scanToTransparentRest(); + void toBlackLine(); void fillWhiteAreas(); void fillWhiteAreasRest(); void toThinBlackLine(); diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index 47d9e63bcf..4681fc7bc9 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -49,6 +49,7 @@ BitmapImage* LayerBitmap::getLastBitmapImageAtFrame(int frameNumber, int increme void LayerBitmap::initColorLayer(Layer *fromLayer, LayerBitmap *colorlayer) { + Q_ASSERT(fromLayer != nullptr && colorlayer != nullptr); int max = fromLayer->getMaxKeyFramePosition(); for (int i = 1; i <=max; i++) { @@ -57,37 +58,38 @@ void LayerBitmap::initColorLayer(Layer *fromLayer, LayerBitmap *colorlayer) } } +void LayerBitmap::singleInitColorLayer(Layer *fromLayer, LayerBitmap *colorlayer, int frame) +{ + Q_ASSERT(fromLayer != nullptr && colorlayer != nullptr); + if (fromLayer->keyExists(frame)) + { + colorlayer->copyFrame(fromLayer, colorlayer, frame); + toBlackLine(frame); + } +} + BitmapImage* LayerBitmap::scanToTransparent(int frame) { + if (!keyExists(frame)) { return nullptr; } + + qDebug() << "Acos 60 " << acos(60.0); BitmapImage* img = static_cast(getKeyFrameAt(frame)); QRgb rgba; - int grayValue; for (int x = img->left(); x <= img->right(); x++) { for (int y = img->top(); y <= img->bottom(); y++) { rgba = img->pixel(x, y); -// grayValue = (qRed(rgba) + qGreen(rgba) + qBlue(rgba)) / 3; - if (qGray(rgba) >= mThreshold) + if (qAlpha(rgba) != 0 && qGray(rgba) >= mThreshold) { img->setPixel(x, y, transp); } - /* - else - { - QRgb rgba = qRgba(grayValue, grayValue, grayValue, 255 - grayValue); - img->setPixel(x , y, rgba); - } - */ - else if(qGray(rgba) > mThreshold - 60) + else if(qAlpha(rgba) != 0) { - -// int alpha = static_cast(floor(255 - 255 * (grayValue - mLowThreshold)/(mThreshold - mLowThreshold) )); - QRgb tmp = qRgba(qGray(rgba), qGray(rgba), qGray(rgba), 255 - qGray(rgba)); - + int alpha = static_cast(floor(255 * (mThreshold - qGray(rgba))/mThreshold)); + QRgb tmp = qRgba(qGray(rgba), qGray(rgba), qGray(rgba), alpha); img->setPixel(x , y, tmp); } - } } return img; @@ -98,17 +100,12 @@ void LayerBitmap::toBlackLine(int frame) if (!keyExists(frame)) { return; } BitmapImage* img = static_cast(getKeyFrameAt(frame)); - int xOffset = img->left(); - int yOffset = img->top(); - - // make line black (0, 1, 0, 255) - for (int x = 0; x < img->width(); x++) + for (int x = img->left(); x <= img->right(); x++) { - for (int y = 0; y < img->height(); y++) + for (int y = img->top(); y <= img->bottom(); y++) { - QRgb rgba = img->pixel(x + xOffset, y + yOffset); - if (rgba != transp) - img->setPixel(x + xOffset, y + yOffset, thinline); + if (qAlpha(img->pixel(x, y)) > 0) + img->setPixel(x, y, thinline); } } } @@ -149,6 +146,7 @@ void LayerBitmap::fillWhiteAreas(int frame) void LayerBitmap::toThinBlackLine(int frame) { + if (!keyExists(frame)) { return; } BitmapImage* img = static_cast(getKeyFrameAt(frame)); bool N = true, E = true, S = true, W = true, black, search; while (N || E || S || W) @@ -305,6 +303,7 @@ void LayerBitmap::toThinBlackLine(int frame) void LayerBitmap::replaceThinLine(int frame) { + if (!keyExists(frame)) { return; } BitmapImage* img = static_cast(getKeyFrameAt(frame)); int r, g, b, a; //red, green, blue, alpha @@ -345,6 +344,7 @@ void LayerBitmap::replaceThinLine(int frame) int LayerBitmap::fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, int frame) { + if (!keyExists(frame)) { return -1; } BitmapImage* img = static_cast(getKeyFrameAt(frame)); QList fillList; fillList.clear(); diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index 2654fe44c5..0d3d653b99 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -43,6 +43,7 @@ class LayerBitmap : public Layer // color layer methods void initColorLayer(Layer* fromLayer, LayerBitmap* colorlayer); + void singleInitColorLayer(Layer* fromLayer, LayerBitmap* colorlayer, int frame); int getThreshold() { return mThreshold; } void setThreshold(int threshold) { mThreshold = threshold; } int getWhiteArea() { return mWhiteArea; } From 4c708ef22bbe34813a3dc85ed25c72e6a72feb5e Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Fri, 1 Feb 2019 20:52:01 +0100 Subject: [PATCH 018/100] WIP just getting worse --- app/src/bitmapcoloring.cpp | 2 ++ core_lib/src/interface/editor.cpp | 4 +++- core_lib/src/structure/layerbitmap.cpp | 27 +++++++++++++------------- core_lib/src/structure/layerbitmap.h | 7 +++++++ 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index c71110e46e..42ee46ae5b 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -40,6 +40,8 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : connect(ui->btn3_apply, &QPushButton::clicked, mEditor, &Editor::scanToTransparent); connect(ui->btn3_Next, &QPushButton::clicked, mEditor, &Editor::scrubNextKeyFrame); connect(ui->btn3_applyRest, &QPushButton::clicked, mEditor, &Editor::scanToTransparentRest); + connect(ui->btnx_blackLine, &QPushButton::clicked, mEditor, &Editor::toBlackLine); + connect(ui->sb4_fillArea, QOverload::of(&QSpinBox::valueChanged), mLayerBitmap, &LayerBitmap::setWhiteArea); connect(ui->btn4_apply, &QPushButton::clicked, mEditor, &Editor::fillWhiteAreas); connect(ui->btn4_next, &QPushButton::clicked, mEditor, &Editor::scrubNextKeyFrame); diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index b0c86568fe..57100e1ae9 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -610,8 +610,10 @@ void Editor::scanToTransparentRest() void Editor::toBlackLine() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); + LayerBitmap* toLayer = static_cast(layers()->findLayerByName(layerBitmap->name() + "_C")); mObject->updateActiveFrames(currentFrame()); - layerBitmap->singleInitColorLayer(layerBitmap, layerBitmap, currentFrame()); + layers()->setCurrentLayer(toLayer); + layerBitmap->singleInitColorLayer(layerBitmap, toLayer , currentFrame()); mScribbleArea->updateFrame(currentFrame()); } diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index 4681fc7bc9..e92ed97595 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -64,6 +64,7 @@ void LayerBitmap::singleInitColorLayer(Layer *fromLayer, LayerBitmap *colorlayer if (fromLayer->keyExists(frame)) { colorlayer->copyFrame(fromLayer, colorlayer, frame); + toBlackLine(frame); } } @@ -72,7 +73,6 @@ BitmapImage* LayerBitmap::scanToTransparent(int frame) { if (!keyExists(frame)) { return nullptr; } - qDebug() << "Acos 60 " << acos(60.0); BitmapImage* img = static_cast(getKeyFrameAt(frame)); QRgb rgba; for (int x = img->left(); x <= img->right(); x++) @@ -80,16 +80,17 @@ BitmapImage* LayerBitmap::scanToTransparent(int frame) for (int y = img->top(); y <= img->bottom(); y++) { rgba = img->pixel(x, y); - if (qAlpha(rgba) != 0 && qGray(rgba) >= mThreshold) + if (qGray(rgba) >= mThreshold) { img->setPixel(x, y, transp); } - else if(qAlpha(rgba) != 0) + else if(qGray(rgba) >= mLowThreshold && qGray(rgba) < mThreshold) { - int alpha = static_cast(floor(255 * (mThreshold - qGray(rgba))/mThreshold)); + qreal degree = 90 * (mThreshold - qGray(rgba)) / (mThreshold - mLowThreshold); + int alpha = static_cast(255 - 255 * cos(degree * 3.1415 / 180)); +// qDebug() << "gray/degree/alpha: " << qGray(rgba) << " " << degree << " " << alpha; QRgb tmp = qRgba(qGray(rgba), qGray(rgba), qGray(rgba), alpha); - img->setPixel(x , y, tmp); - } + img->setPixel(x , y, tmp);} } } return img; @@ -104,6 +105,7 @@ void LayerBitmap::toBlackLine(int frame) { for (int y = img->top(); y <= img->bottom(); y++) { + qDebug() << "Alpha: " << qAlpha(img->pixel(x,y)); if (qAlpha(img->pixel(x, y)) > 0) img->setPixel(x, y, thinline); } @@ -115,20 +117,19 @@ void LayerBitmap::fillWhiteAreas(int frame) if (!keyExists(frame)) { return; } BitmapImage* img = static_cast(getKeyFrameAt(frame)); - int xOffset = img->left(); - int yOffset = img->top(); // fill areas size 'area' or less with black QVector points; points.clear(); - for (int x = 0; x < img->width(); x++) + for (int x = img->left(); x < img->right(); x++) { - for (int y = 0; y < img->height(); y++) + for (int y = img->top(); y < img->bottom(); y++) { - if (qAlpha(img->pixel(x + xOffset, y + yOffset)) == 0) + if (qAlpha(img->pixel(x, y)) < 1) { - points.append(QPoint(x + xOffset, y + yOffset)); - int areaSize = fillWithColor(QPoint(x + xOffset, y + yOffset), transp, rosa, frame); + points.append(QPoint(x, y)); + int areaSize = fillWithColor(QPoint(x, y), transp, rosa, frame); + qDebug() << "size: " << areaSize; if (areaSize <= mWhiteArea) { // replace rosa with thinline (black) fillWithColor(points.last(), rosa, thinline, frame); diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index 0d3d653b99..59abedae07 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -42,6 +42,9 @@ class LayerBitmap : public Layer BitmapImage* getLastBitmapImageAtFrame(int frameNumber, int increment = 0); // color layer methods + bool getIsColorLayer() { return mIsColorLayer; } + void setIsColorLayer(bool isColor) { mIsColorLayer = isColor; } + void initColorLayer(Layer* fromLayer, LayerBitmap* colorlayer); void singleInitColorLayer(Layer* fromLayer, LayerBitmap* colorlayer, int frame); int getThreshold() { return mThreshold; } @@ -49,11 +52,14 @@ class LayerBitmap : public Layer int getWhiteArea() { return mWhiteArea; } void setWhiteArea(int whiteArea) { mWhiteArea = whiteArea; } BitmapImage* scanToTransparent(int frame); + void toBlackLine(int frame); + void fillWhiteAreas(int frame); void toThinBlackLine(int frame); void replaceThinLine(int frame); int fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, int frame); + // color layer methods end protected: Status saveKeyFrameFile(KeyFrame*, QString strPath) override; @@ -68,6 +74,7 @@ class LayerBitmap : public Layer int mThreshold = 200; const int mLowThreshold = 100; // threshold for images to be given transparency int mWhiteArea = 6; + bool mIsColorLayer = false; }; #endif From 69ab2473dca2167ce574bfe3e9a4c3d28f2eb378 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Fri, 1 Feb 2019 23:04:33 +0100 Subject: [PATCH 019/100] Tested several gray values for pencil. Works now. --- core_lib/src/structure/layerbitmap.cpp | 37 +++++++++++++++----------- core_lib/src/structure/layerbitmap.h | 2 +- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index 39e86cb033..857bf0dfce 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -59,27 +59,37 @@ void LayerBitmap::initColorLayer(Layer *fromLayer, LayerBitmap *colorlayer) BitmapImage* LayerBitmap::scanToTransparent(int frame) { + if (!keyExists(frame)) { return nullptr; } + BitmapImage* img = static_cast(getKeyFrameAt(frame)); QRgb rgba; - int grayValue; for (int x = img->left(); x <= img->right(); x++) { for (int y = img->top(); y <= img->bottom(); y++) { rgba = img->pixel(x, y); - grayValue = (qRed(rgba) + qGreen(rgba) + qBlue(rgba)) / 3; - if (grayValue >= mThreshold) + if (qGray(rgba) >= mThreshold) { img->setPixel(x, y, transp); } - else if(grayValue > mLowThreshold - 1 && grayValue < mThreshold) + else if(qGray(rgba) >= mLowThreshold && qGray(rgba) < mThreshold) { - int alpha = static_cast(floor(255 - 255 * (grayValue - mLowThreshold)/(mThreshold - mLowThreshold) )); - QRgb rgba = qRgba(grayValue, grayValue, grayValue, alpha); - img->setPixel(x , y, rgba); + /* + qreal degree = 90 * (mThreshold - qGray(rgba)) / (mThreshold - mLowThreshold) ; + int alpha = static_cast(255 - 255 * cos(degree * 3.1415 / 180)); + qDebug() << "gray/degree/alpha: " << qGray(rgba) << " " << degree << " " << alpha; + QRgb tmp = qRgba(qGray(rgba), qGray(rgba), qGray(rgba), alpha); + img->setPixel(x , y, tmp); + */ + qreal factor = qreal(mThreshold - qGray(rgba)) / qreal(mThreshold - mLowThreshold); + int alpha = static_cast(255 * factor); + QRgb tmp = qRgba(qGray(rgba), qGray(rgba), qGray(rgba), alpha); + qDebug() << "gray/factor/alpha: " << qGray(rgba) << " " << factor << " " << alpha; + img->setPixel(x , y, tmp); } } } + qDebug() << "Threshold: " << mThreshold; return img; } @@ -88,17 +98,15 @@ void LayerBitmap::toBlackLine(int frame) if (!keyExists(frame)) { return; } BitmapImage* img = static_cast(getKeyFrameAt(frame)); - int xOffset = img->left(); - int yOffset = img->top(); - // make line black (0, 1, 0, 255) - for (int x = 0; x < img->width(); x++) + // make line black (0, 0, 0, 255) + for (int x = img->left(); x <= img->height(); x++) { - for (int y = 0; y < img->height(); y++) + for (int y = img->top(); y < img->bottom(); y++) { - QRgb rgba = img->pixel(x + xOffset, y + yOffset); + QRgb rgba = img->pixel(x, y); if (rgba != transp) - img->setPixel(x + xOffset, y + yOffset, thinline); + img->setPixel(x, y, thinline); } } } @@ -307,7 +315,6 @@ void LayerBitmap::replaceThinLine(int frame) r=0; g=0; b=0; a=0; if (img->pixel(x,y) == thinline) { - qDebug() << "in replace..."; if (img->pixel(x-1, y-1) != thinline) points.append(QPoint(x-1, y-1)); if (img->pixel(x-1, y ) != thinline) points.append(QPoint(x-1, y )); if (img->pixel(x-1, y+1) != thinline) points.append(QPoint(x-1, y+1)); diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index 2654fe44c5..049ac12937 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -65,7 +65,7 @@ class LayerBitmap : public Layer bool needSaveFrame(KeyFrame* key, const QString& strSavePath); int mThreshold = 200; - const int mLowThreshold = 100; // threshold for images to be given transparency + const int mLowThreshold = 40; // threshold for images to be given transparency int mWhiteArea = 6; }; From 46145a8a16eb6ebd2aac41db8eeced507149e130 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 2 Feb 2019 11:35:08 +0100 Subject: [PATCH 020/100] Added colorlayer info to xml --- app/src/actioncommands.cpp | 1 + app/src/bitmapcoloring.cpp | 11 +++++++++-- core_lib/src/structure/layer.h | 3 +++ core_lib/src/structure/layerbitmap.cpp | 5 ++++- core_lib/src/structure/layerbitmap.h | 4 ---- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/src/actioncommands.cpp b/app/src/actioncommands.cpp index 20339eecf9..db002619bd 100644 --- a/app/src/actioncommands.cpp +++ b/app/src/actioncommands.cpp @@ -656,6 +656,7 @@ Status ActionCommands::addNewBitmapColorLayer() { LayerBitmap* colorlayer = mEditor->layers()->createBitmapLayer(name); colorlayer->initColorLayer(mEditor->layers()->currentLayer(), colorlayer); + colorlayer->setColorLayer(true); } return Status::OK; } diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 42ee46ae5b..83ef296439 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -67,9 +67,16 @@ void BitmapColoring::initUI() void BitmapColoring::updateUI() { Layer* layer = mEditor->layers()->currentLayer(); - if (layer->type() == Layer::BITMAP) + setEnabled(true); + if (layer->type() == Layer::BITMAP && !layer->colorLayer()) { - setEnabled(true); + ui->tabWidgetColor->setEnabled(false); + ui->tabWidgetScans->setEnabled(true); + } + else if (layer->type() == Layer::BITMAP && layer->colorLayer()) + { + ui->tabWidgetColor->setEnabled(true); + ui->tabWidgetScans->setEnabled(false); } else { diff --git a/core_lib/src/structure/layer.h b/core_lib/src/structure/layer.h index 91f5d239fd..ae58ad9014 100644 --- a/core_lib/src/structure/layer.h +++ b/core_lib/src/structure/layer.h @@ -64,6 +64,8 @@ class Layer : public QObject bool visible() const { return mVisible; } void setVisible(bool b) { mVisible = b; } + bool colorLayer() { return mIsColorLayer; } + void setColorLayer(bool isColor) { mIsColorLayer = isColor; } virtual Status saveKeyFrameFile(KeyFrame*, QString dataPath) = 0; virtual void loadDomElement(QDomElement element, QString dataDirPath, ProgressCallback progressForward) = 0; @@ -131,6 +133,7 @@ class Layer : public QObject Object* mObject = nullptr; int mId = 0; bool mVisible = true; + bool mIsColorLayer = false; QString mName; std::map> mKeyFrames; diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index 07323e882c..465839b326 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -95,7 +95,8 @@ BitmapImage* LayerBitmap::scanToTransparent(int frame) */ qreal factor = qreal(mThreshold - qGray(rgba)) / qreal(mThreshold - mLowThreshold); int alpha = static_cast(255 * factor); - QRgb tmp = qRgba(qGray(rgba), qGray(rgba), qGray(rgba), alpha); + QRgb tmp = qRgba(0, 0, 0, alpha); +// QRgb tmp = qRgba(qGray(rgba), qGray(rgba), qGray(rgba), alpha); qDebug() << "gray/factor/alpha: " << qGray(rgba) << " " << factor << " " << alpha; img->setPixel(x , y, tmp); } @@ -513,6 +514,7 @@ QDomElement LayerBitmap::createDomElement(QDomDocument& doc) layerTag.setAttribute("name", name()); layerTag.setAttribute("visibility", visible()); layerTag.setAttribute("type", type()); + layerTag.setAttribute("colorlayer", colorLayer()); foreachKeyFrame([&](KeyFrame* pKeyFrame) { @@ -540,6 +542,7 @@ void LayerBitmap::loadDomElement(QDomElement element, QString dataDirPath, Progr } setName(element.attribute("name")); setVisible(element.attribute("visibility").toInt() == 1); + setColorLayer(element.attribute("colorlayer").toInt() == 1); QDomNode imageTag = element.firstChild(); while (!imageTag.isNull()) diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index 5e4ac9333a..f53b22129b 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -42,9 +42,6 @@ class LayerBitmap : public Layer BitmapImage* getLastBitmapImageAtFrame(int frameNumber, int increment = 0); // color layer methods - bool getIsColorLayer() { return mIsColorLayer; } - void setIsColorLayer(bool isColor) { mIsColorLayer = isColor; } - void initColorLayer(Layer* fromLayer, LayerBitmap* colorlayer); void singleInitColorLayer(Layer* fromLayer, LayerBitmap* colorlayer, int frame); int getThreshold() { return mThreshold; } @@ -74,7 +71,6 @@ class LayerBitmap : public Layer int mThreshold = 200; const int mLowThreshold = 40; // threshold for images to be given transparency int mWhiteArea = 6; - bool mIsColorLayer = false; }; #endif From a515c5984987139be220805c8305ca71a649f233 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 2 Feb 2019 21:46:12 +0100 Subject: [PATCH 021/100] ParentId. Recovery of one frame. Ui improved --- app/src/actioncommands.cpp | 2 +- app/src/bitmapcoloring.cpp | 17 +- app/ui/bitmapcoloringwidget.ui | 321 ++++++++++++------------- core_lib/src/interface/editor.cpp | 3 +- core_lib/src/structure/layer.h | 6 +- core_lib/src/structure/layerbitmap.cpp | 17 +- core_lib/src/structure/layerbitmap.h | 2 +- 7 files changed, 180 insertions(+), 188 deletions(-) diff --git a/app/src/actioncommands.cpp b/app/src/actioncommands.cpp index db002619bd..6ce76aab41 100644 --- a/app/src/actioncommands.cpp +++ b/app/src/actioncommands.cpp @@ -656,7 +656,7 @@ Status ActionCommands::addNewBitmapColorLayer() { LayerBitmap* colorlayer = mEditor->layers()->createBitmapLayer(name); colorlayer->initColorLayer(mEditor->layers()->currentLayer(), colorlayer); - colorlayer->setColorLayer(true); + colorlayer->setParentId(mEditor->layers()->currentLayer()->id()); } return Status::OK; } diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 83ef296439..83dd19316a 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -59,24 +59,35 @@ BitmapColoring::~BitmapColoring() void BitmapColoring::initUI() { - if (!isVisible()) { return; } +// if (!isVisible()) { return; } updateUI(); } void BitmapColoring::updateUI() { + if (!isVisible()) { return; } + Layer* layer = mEditor->layers()->currentLayer(); setEnabled(true); - if (layer->type() == Layer::BITMAP && !layer->colorLayer()) + if (layer->type() == Layer::BITMAP && layer->parentId() == -1) { ui->tabWidgetColor->setEnabled(false); + ui->frameWidgetColor->setEnabled(false); ui->tabWidgetScans->setEnabled(true); + ui->frameWidgetScans->setEnabled(true); + for (int i = 0; i < mEditor->layers()->count(); i++) + { + if (mEditor->layers()->getLayer(i)->parentId() == layer->id()) + ui->labx_3->setText(tr("To Layer: %1").arg(mEditor->layers()->getLayer(i)->name())); + } } - else if (layer->type() == Layer::BITMAP && layer->colorLayer()) + else if (layer->type() == Layer::BITMAP && layer->parentId() > -1) { ui->tabWidgetColor->setEnabled(true); + ui->frameWidgetColor->setEnabled(true); ui->tabWidgetScans->setEnabled(false); + ui->frameWidgetScans->setEnabled(false); } else { diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index 06d5f1d62b..434a8d6de1 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -15,71 +15,67 @@ - + QFrame::StyledPanel QFrame::Raised - + + + + + + 75 + true + + + + Process scanned drawings + + + + + + + 1. Select from scan + + + - - - - - - 75 - true - - - - Process scanned drawings - - - - - - - 1. Select from scan - - - - - - - 2. Clean up drawings - - - - - - - 3. Threshold and transparency - - - - - - - x. Black line (for repairs!) - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - + + + 2. Clean up drawings + + + + + + + 3. Threshold and transparency + + + + + + + x. Black line (for repairs!) + + + + + + + Qt::Vertical + + + + 20 + 40 + + + @@ -87,7 +83,7 @@ - 3 + 0 @@ -262,58 +258,61 @@ x - + - - - - - Make line all black. - - - - - - - - 75 - true - true - - - - Use only on color layer! - - - - - - - To Black line - - - - - - - Qt::Vertical - - - - 20 - 18 - - - - - + + + Recreate black line + + + + + + + + 75 + true + true + + + + From bitmap to color layer + + + + + + + + + + + + + + To Black line + + + + + + + Qt::Vertical + + + + 20 + 21 + + + - + false @@ -323,64 +322,60 @@ QFrame::Raised - + + + + + + 75 + true + + + + Bitmap coloring + + + + + + + 4. Remove white areas + + + + + + + 5. Thin black line to 1 pixel + + + + + + + 6. Colorize with fills + + + + + + + 7. Remove/replace 1 pixel line + + + - - - - - - 75 - true - - - - Bitmap coloring - - - - - - - 4. Remove white areas - - - - - - - 5. Thin black line to 1 pixel - - - - - - - 6. Colorize with fills - - - - - - - 7. Remove/replace 1 pixel line - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - + + + Qt::Vertical + + + + 20 + 40 + + + @@ -542,14 +537,14 @@ - All drawings must be finished! + Are all drawings finished? - Handle with care... + Only then... diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 57100e1ae9..52ee3dc48a 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -612,8 +612,7 @@ void Editor::toBlackLine() LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); LayerBitmap* toLayer = static_cast(layers()->findLayerByName(layerBitmap->name() + "_C")); mObject->updateActiveFrames(currentFrame()); - layers()->setCurrentLayer(toLayer); - layerBitmap->singleInitColorLayer(layerBitmap, toLayer , currentFrame()); + toLayer->singleInitColorLayer(layerBitmap, toLayer , currentFrame()); mScribbleArea->updateFrame(currentFrame()); } diff --git a/core_lib/src/structure/layer.h b/core_lib/src/structure/layer.h index ae58ad9014..915a3863d4 100644 --- a/core_lib/src/structure/layer.h +++ b/core_lib/src/structure/layer.h @@ -64,8 +64,8 @@ class Layer : public QObject bool visible() const { return mVisible; } void setVisible(bool b) { mVisible = b; } - bool colorLayer() { return mIsColorLayer; } - void setColorLayer(bool isColor) { mIsColorLayer = isColor; } + int parentId() const { return mParentId; } + void setParentId(int pId) { mParentId = pId; } virtual Status saveKeyFrameFile(KeyFrame*, QString dataPath) = 0; virtual void loadDomElement(QDomElement element, QString dataDirPath, ProgressCallback progressForward) = 0; @@ -133,7 +133,7 @@ class Layer : public QObject Object* mObject = nullptr; int mId = 0; bool mVisible = true; - bool mIsColorLayer = false; + int mParentId = -1; ///< Only set (changed) for coloring layers QString mName; std::map> mKeyFrames; diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index 465839b326..eb74c6e668 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -64,7 +64,6 @@ void LayerBitmap::singleInitColorLayer(Layer *fromLayer, LayerBitmap *colorlayer if (fromLayer->keyExists(frame)) { colorlayer->copyFrame(fromLayer, colorlayer, frame); - toBlackLine(frame); } } @@ -86,23 +85,13 @@ BitmapImage* LayerBitmap::scanToTransparent(int frame) } else if(qGray(rgba) >= mLowThreshold && qGray(rgba) < mThreshold) { - /* - qreal degree = 90 * (mThreshold - qGray(rgba)) / (mThreshold - mLowThreshold) ; - int alpha = static_cast(255 - 255 * cos(degree * 3.1415 / 180)); - qDebug() << "gray/degree/alpha: " << qGray(rgba) << " " << degree << " " << alpha; - QRgb tmp = qRgba(qGray(rgba), qGray(rgba), qGray(rgba), alpha); - img->setPixel(x , y, tmp); - */ qreal factor = qreal(mThreshold - qGray(rgba)) / qreal(mThreshold - mLowThreshold); int alpha = static_cast(255 * factor); QRgb tmp = qRgba(0, 0, 0, alpha); -// QRgb tmp = qRgba(qGray(rgba), qGray(rgba), qGray(rgba), alpha); - qDebug() << "gray/factor/alpha: " << qGray(rgba) << " " << factor << " " << alpha; img->setPixel(x , y, tmp); } } } - qDebug() << "Threshold: " << mThreshold; return img; } @@ -115,7 +104,6 @@ void LayerBitmap::toBlackLine(int frame) { for (int y = img->top(); y <= img->bottom(); y++) { - qDebug() << "Alpha: " << qAlpha(img->pixel(x,y)); if (qAlpha(img->pixel(x, y)) > 0) img->setPixel(x, y, thinline); } @@ -139,7 +127,6 @@ void LayerBitmap::fillWhiteAreas(int frame) { points.append(QPoint(x, y)); int areaSize = fillWithColor(QPoint(x, y), transp, rosa, frame); - qDebug() << "size: " << areaSize; if (areaSize <= mWhiteArea) { // replace rosa with thinline (black) fillWithColor(points.last(), rosa, thinline, frame); @@ -514,7 +501,7 @@ QDomElement LayerBitmap::createDomElement(QDomDocument& doc) layerTag.setAttribute("name", name()); layerTag.setAttribute("visibility", visible()); layerTag.setAttribute("type", type()); - layerTag.setAttribute("colorlayer", colorLayer()); + layerTag.setAttribute("parentid", parentId()); foreachKeyFrame([&](KeyFrame* pKeyFrame) { @@ -542,7 +529,7 @@ void LayerBitmap::loadDomElement(QDomElement element, QString dataDirPath, Progr } setName(element.attribute("name")); setVisible(element.attribute("visibility").toInt() == 1); - setColorLayer(element.attribute("colorlayer").toInt() == 1); + setParentId(element.attribute("parentid").toInt()); QDomNode imageTag = element.firstChild(); while (!imageTag.isNull()) diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index f53b22129b..aebf654709 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -69,7 +69,7 @@ class LayerBitmap : public Layer bool needSaveFrame(KeyFrame* key, const QString& strSavePath); int mThreshold = 200; - const int mLowThreshold = 40; // threshold for images to be given transparency + const int mLowThreshold = 30; // threshold for images to be given transparency int mWhiteArea = 6; }; From 649d1b76b78304fb2e8c48d216131de168dcd762 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 3 Feb 2019 09:18:55 +0100 Subject: [PATCH 022/100] Added modification to frames. x-button en-/disable. --- app/src/bitmapcoloring.cpp | 5 +++++ core_lib/src/structure/layer.cpp | 1 + core_lib/src/structure/layerbitmap.cpp | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 83dd19316a..fd7b0c8eab 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -76,11 +76,16 @@ void BitmapColoring::updateUI() ui->frameWidgetColor->setEnabled(false); ui->tabWidgetScans->setEnabled(true); ui->frameWidgetScans->setEnabled(true); + bool colLayerExists = false; for (int i = 0; i < mEditor->layers()->count(); i++) { if (mEditor->layers()->getLayer(i)->parentId() == layer->id()) + { ui->labx_3->setText(tr("To Layer: %1").arg(mEditor->layers()->getLayer(i)->name())); + colLayerExists = true; + } } + colLayerExists == true ? ui->btnx_blackLine->setEnabled(true) : ui->btnx_blackLine->setEnabled(false); } else if (layer->type() == Layer::BITMAP && layer->parentId() > -1) { diff --git a/core_lib/src/structure/layer.cpp b/core_lib/src/structure/layer.cpp index d84ee6b72b..ad00fabfd7 100644 --- a/core_lib/src/structure/layer.cpp +++ b/core_lib/src/structure/layer.cpp @@ -456,6 +456,7 @@ void Layer::copyFrame(Layer *fromLayer, Layer *toLayer, int frame) toLayer->removeKeyFrame(frame); toLayer->addKeyFrame(frame, dupKey); toLayer->setModified(frame, true); + toLayer->getKeyFrameAt(frame)->modification(); } } diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index eb74c6e668..f06cbf9715 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -92,6 +92,7 @@ BitmapImage* LayerBitmap::scanToTransparent(int frame) } } } + getKeyFrameAt(frame)->modification(); return img; } @@ -108,6 +109,7 @@ void LayerBitmap::toBlackLine(int frame) img->setPixel(x, y, thinline); } } + getKeyFrameAt(frame)->modification(); } void LayerBitmap::fillWhiteAreas(int frame) @@ -140,6 +142,7 @@ void LayerBitmap::fillWhiteAreas(int frame) fillWithColor(points[0], rosa, transp, frame); points.removeFirst(); } + getKeyFrameAt(frame)->modification(); } void LayerBitmap::toThinBlackLine(int frame) @@ -297,6 +300,7 @@ void LayerBitmap::toThinBlackLine(int frame) W = black; // if none 'black' is removed, W = false } } + getKeyFrameAt(frame)->modification(); } void LayerBitmap::replaceThinLine(int frame) @@ -337,6 +341,7 @@ void LayerBitmap::replaceThinLine(int frame) } } } + getKeyFrameAt(frame)->modification(); } int LayerBitmap::fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, int frame) @@ -380,6 +385,7 @@ int LayerBitmap::fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, int f } fillList.removeFirst(); } + getKeyFrameAt(frame)->modification(); return pixels; } From f2f0775522c1f8b45c01eec576928878f6fe2d05 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 3 Feb 2019 15:23:03 +0100 Subject: [PATCH 023/100] Added scrollbar to coloring dock --- app/ui/bitmapcoloringwidget.ui | 1103 +++++++++++++++-------------- core_lib/src/interface/editor.cpp | 1 - 2 files changed, 559 insertions(+), 545 deletions(-) diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index 434a8d6de1..f2ccfa7db8 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -13,564 +13,579 @@ Form - + - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - 75 - true - - - - Process scanned drawings - - - - - - - 1. Select from scan - - - - - - - 2. Clean up drawings - - - - - - - 3. Threshold and transparency - - - - - - - x. Black line (for repairs!) - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - 0 - - - - 1 - - - - - - Select coloring area. - - - - - - - Only if you work with scans - - - - - - - Use select tool! - - - - - - - - - Select - - - - - - - Next - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 2 - - - - - - Clean up if necessary - - - - - - - Use normal tools - - - - - - - Finish all drawings - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 3 - - - - - - - - Choose threshold - - - - - - - 150 - - - 250 - - - 200 - - - - - - - - - - - Apply - - - - - - - Next - - - - - - - - - Apply the rest... - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - x - - - - - - Recreate black line - - - - - - - - 75 - true - true - - - - From bitmap to color layer - - - + + + - - - - + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 75 + true + + + + Process scanned drawings + + + + + + + 1. Select from scan + + + + + + + 2. Clean up drawings + + + + + + + 3. Threshold and transparency + + + + + + + x. Black line (for repairs!) + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + - - - To Black line - + + + 0 + + + + 1 + + + + + + Select coloring area. + + + + + + + Only if you work with scans + + + + + + + Use select tool! + + + + + + + + + Select + + + + + + + Next + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 2 + + + + + + Clean up if necessary + + + + + + + Use normal tools + + + + + + + Finish all drawings + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 3 + + + + + + + + Choose threshold + + + + + + + 150 + + + 250 + + + 200 + + + + + + + + + + + Apply + + + + + + + Next + + + + + + + + + Apply the rest... + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + x + + + + + + Recreate black line + + + + + + + + 75 + true + true + + + + From bitmap to color layer + + + + + + + + + + + + + + To Black line + + + + + + + Qt::Vertical + + + + 20 + 21 + + + + + + - - - Qt::Vertical - - - - 20 - 21 - - - - - - - - - - - - false - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - 75 - true - - - - Bitmap coloring - - - - - - - 4. Remove white areas - - - - - - - 5. Thin black line to 1 pixel - - - - - - - 6. Colorize with fills - - - - - - - 7. Remove/replace 1 pixel line - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - 0 - - - - 4 - - - - - - - - Fill area: - - - - - - - px - - - 1 - - - 16 - - - 6 - - - - - - - - - - - Apply - - - - - - - Next - - - - - - - - - Apply the rest... - + + + false + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 75 + true + + + + Bitmap coloring + + + + + + + 4. Remove white areas + + + + + + + 5. Thin black line to 1 pixel + + + + + + + 6. Colorize with fills + + + + + + + 7. Remove/replace 1 pixel line + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 5 - - - - - - - - Thin line - - - - - - - Next - - - - - - - - - Thin rest... - + + + 0 + + + + 4 + + + + + + + + Fill area: + + + + + + + px + + + 1 + + + 16 + + + 6 + + + + + + + + + + + Apply + + + + + + + Next + + + + + + + + + Apply the rest... + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 5 + + + + + + + + Thin line + + + + + + + Next + + + + + + + + + Thin rest... + + + + + + + Qt::Vertical + + + + 20 + 31 + + + + + + + + + 6 + + + + + + Colorize... + + + + + + + Qt::Vertical + + + + 20 + 70 + + + + + + + + + 7 + + + + + + Are all drawings finished? + + + + + + + Only then... + + + + + + + Replace thin lines... + + + + + + + Qt::Vertical + + + + 20 + 62 + + + + + + - - - - Qt::Vertical - - - - 20 - 31 - - - - - - - - - 6 - - - - - - Colorize... - - - - - - - Qt::Vertical - - - - 20 - 70 - - - - - - - - - 7 - - - - - - Are all drawings finished? - - - - - - - Only then... - - - - - - - Replace thin lines... - - - - - - - Qt::Vertical - - - - 20 - 62 - - - - - - + + + + + Qt::Vertical + + + + diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 52ee3dc48a..e9a31509e8 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -664,7 +664,6 @@ void Editor::replaceThinLines() mObject->updateActiveFrames(currentFrame()); layerBitmap->replaceThinLine(currentFrame()); scrubNextKeyFrame(); - qDebug() << "replace thin..." << currentFrame(); } scrubNextKeyFrame(); layerBitmap->replaceThinLine(currentFrame()); From b023e1e5eb45f78cce307debb47aa96fe67737fa Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Mon, 11 Feb 2019 15:22:02 +0100 Subject: [PATCH 024/100] Simplified Ui and Ux --- app/src/bitmapcoloring.cpp | 23 +- app/ui/bitmapcoloringwidget.ui | 889 +++++++++++------------------- core_lib/src/interface/editor.cpp | 31 +- core_lib/src/interface/editor.h | 1 - 4 files changed, 353 insertions(+), 591 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index fd7b0c8eab..2b7db9e279 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -36,20 +36,15 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : connect(ui->btn1Select, &QPushButton::clicked, mEditor, &Editor::copyFromScan); connect(ui->btn1Next, &QPushButton::clicked, mEditor, &Editor::scrubNextKeyFrame); - connect(ui->sb2_Threshold, QOverload::of(&QSpinBox::valueChanged), mLayerBitmap, &LayerBitmap::setThreshold); - connect(ui->btn3_apply, &QPushButton::clicked, mEditor, &Editor::scanToTransparent); - connect(ui->btn3_Next, &QPushButton::clicked, mEditor, &Editor::scrubNextKeyFrame); - connect(ui->btn3_applyRest, &QPushButton::clicked, mEditor, &Editor::scanToTransparentRest); + connect(ui->sb1_Threshold, QOverload::of(&QSpinBox::valueChanged), mLayerBitmap, &LayerBitmap::setThreshold); connect(ui->btnx_blackLine, &QPushButton::clicked, mEditor, &Editor::toBlackLine); - connect(ui->sb4_fillArea, QOverload::of(&QSpinBox::valueChanged), mLayerBitmap, &LayerBitmap::setWhiteArea); - connect(ui->btn4_apply, &QPushButton::clicked, mEditor, &Editor::fillWhiteAreas); - connect(ui->btn4_next, &QPushButton::clicked, mEditor, &Editor::scrubNextKeyFrame); - connect(ui->btn4_applyRest, &QPushButton::clicked, mEditor, &Editor::fillWhiteAreasRest); - connect(ui->btn5_thin, &QPushButton::clicked, mEditor, &Editor::toThinBlackLine); - connect(ui->btn5_next, &QPushButton::clicked, mEditor, &Editor::scrubNextKeyFrame); - connect(ui->btn5_thinRest, &QPushButton::clicked, mEditor, &Editor::toThinBlackLineRest); - connect(ui->btn7_replaceThinLines, &QPushButton::clicked, mEditor, &Editor::replaceThinLines); + connect(ui->sb2_fillArea, QOverload::of(&QSpinBox::valueChanged), mLayerBitmap, &LayerBitmap::setWhiteArea); + connect(ui->btn2_fillRest, &QPushButton::clicked, mEditor, &Editor::fillWhiteAreasRest); + connect(ui->btn2_repairs, &QPushButton::clicked, mEditor, &Editor::fillWhiteAreas); + connect(ui->btn3_thinRest, &QPushButton::clicked, mEditor, &Editor::toThinBlackLineRest); + connect(ui->btn3_repairs, &QPushButton::clicked, mEditor, &Editor::toThinBlackLine); + connect(ui->btn4_replaceThinLines, &QPushButton::clicked, mEditor, &Editor::replaceThinLines); } BitmapColoring::~BitmapColoring() @@ -73,9 +68,7 @@ void BitmapColoring::updateUI() if (layer->type() == Layer::BITMAP && layer->parentId() == -1) { ui->tabWidgetColor->setEnabled(false); - ui->frameWidgetColor->setEnabled(false); ui->tabWidgetScans->setEnabled(true); - ui->frameWidgetScans->setEnabled(true); bool colLayerExists = false; for (int i = 0; i < mEditor->layers()->count(); i++) { @@ -90,9 +83,7 @@ void BitmapColoring::updateUI() else if (layer->type() == Layer::BITMAP && layer->parentId() > -1) { ui->tabWidgetColor->setEnabled(true); - ui->frameWidgetColor->setEnabled(true); ui->tabWidgetScans->setEnabled(false); - ui->frameWidgetScans->setEnabled(false); } else { diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index f2ccfa7db8..24122131cc 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -6,586 +6,367 @@ 0 0 - 270 - 649 + 222 + 475 Form - + - - - + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 75 + true + + + + Bitmap coloring process: + + + + + + + 1. Select from scan (optional) + + + + + + + x. Black line (for repairs!) + + + + + + + 2. Remove white areas + + + + + + + 3. Thin the lines... + + + + + + + 4. Remove black line + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 0 + + + + 1 + + + + + + Select coloring area. + + + + + + + Use select tool! + + + + + + + + + Threshold: + + + + + + + 150 + + + 250 + + + 200 + + + + + + + + + + + Select + + + + + + + Next + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + x + + + + + + Recreate black line + + + + + + + + 75 + true + true + + + + From bitmap to color layer + + + + + + + + + + + + + + To Black line + + + + + + + Qt::Vertical + + + + 20 + 21 + + + + + + + + + + + + 0 + + + + 2 + + + + + + + + Fill area: + + + + + + + px + + + 1 + + + 20 + + + 6 + + + + + + + + + Apply to lines... + + + + + + + [Apply repairs...] + + + - - - QFrame::StyledPanel + + + Qt::Vertical - - QFrame::Raised + + + 20 + 40 + + + + + + + + + 3 + + + + + + Thin the Lines... - - - - - - 75 - true - - - - Process scanned drawings - - - - - - - 1. Select from scan - - - - - - - 2. Clean up drawings - - - - - - - 3. Threshold and transparency - - - - - - - x. Black line (for repairs!) - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - 0 + + + [Thin repairs...] - - - 1 - - - - - - Select coloring area. - - - - - - - Only if you work with scans - - - - - - - Use select tool! - - - - - - - - - Select - - - - - - - Next - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 2 - - - - - - Clean up if necessary - - - - - - - Use normal tools - - - - - - - Finish all drawings - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 3 - - - - - - - - Choose threshold - - - - - - - 150 - - - 250 - - - 200 - - - - - - - - - - - Apply - - - - - - - Next - - - - - - - - - Apply the rest... - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - x - - - - - - Recreate black line - - - - - - - - 75 - true - true - - - - From bitmap to color layer - - - - - - - - - - - - - - To Black line - - - - - - - Qt::Vertical - - - - 20 - 21 - - - - - - - - - false + + + Qt::Vertical - - QFrame::StyledPanel + + + 20 + 31 + - - QFrame::Raised + + + + + + + 4 + + + + + + Finished coloring? - - - - - - 75 - true - - - - Bitmap coloring - - - - - - - 4. Remove white areas - - - - - - - 5. Thin black line to 1 pixel - - - - - - - 6. Colorize with fills - - - - - - - 7. Remove/replace 1 pixel line - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - 0 + + + Only then... - - - 4 - - - - - - - - Fill area: - - - - - - - px - - - 1 - - - 16 - - - 6 - - - - - - - - - - - Apply - - - - - - - Next - - - - - - - - - Apply the rest... - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 5 - - - - - - - - Thin line - - - - - - - Next - - - - - - - - - Thin rest... - - - - - - - Qt::Vertical - - - - 20 - 31 - - - - - - - - - 6 - - - - - - Colorize... - - - - - - - Qt::Vertical - - - - 20 - 70 - - - - - - - - - 7 - - - - - - Are all drawings finished? - - - - - - - Only then... - - - - - - - Replace thin lines... - - - - - - - Qt::Vertical - - - - 20 - 62 - - - - - - + + + + Replace thin lines... + + + + + + + Qt::Vertical + + + + 20 + 62 + + + + - - - - - Qt::Vertical - - - - + + diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index e9a31509e8..0844d3bcad 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -585,6 +585,7 @@ void Editor::copyFromScan() layer->addNewKeyFrameAt(currentFrame()); paste(); g_clipboardBitmapImage.clear(); + scanToTransparent(); } } @@ -596,17 +597,6 @@ void Editor::scanToTransparent() mScribbleArea->updateFrame(currentFrame()); } -void Editor::scanToTransparentRest() -{ - LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); - mObject->updateActiveFrames(currentFrame()); - while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()) - { - scrubNextKeyFrame(); - layerBitmap->scanToTransparent(currentFrame()); - } -} - void Editor::toBlackLine() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); @@ -627,12 +617,13 @@ void Editor::fillWhiteAreas() void Editor::fillWhiteAreasRest() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); - while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()) + do { + layerBitmap->fillWhiteAreas(currentFrame()); scrubNextKeyFrame(); mObject->updateActiveFrames(currentFrame()); - layerBitmap->fillWhiteAreas(currentFrame()); - } + } while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()); + layerBitmap->fillWhiteAreas(currentFrame()); mScribbleArea->updateFrame(currentFrame()); } @@ -647,25 +638,25 @@ void Editor::toThinBlackLine() void Editor::toThinBlackLineRest() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); - while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()) + do { + layerBitmap->toThinBlackLine(currentFrame()); scrubNextKeyFrame(); mObject->updateActiveFrames(currentFrame()); - layerBitmap->toThinBlackLine(currentFrame()); - } + } while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()); + layerBitmap->toThinBlackLine(currentFrame()); mScribbleArea->updateFrame(currentFrame()); } void Editor::replaceThinLines() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); - while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()) + do { mObject->updateActiveFrames(currentFrame()); layerBitmap->replaceThinLine(currentFrame()); scrubNextKeyFrame(); - } - scrubNextKeyFrame(); + } while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()); layerBitmap->replaceThinLine(currentFrame()); mScribbleArea->updateFrame(currentFrame()); } diff --git a/core_lib/src/interface/editor.h b/core_lib/src/interface/editor.h index 930df04277..183518bdca 100644 --- a/core_lib/src/interface/editor.h +++ b/core_lib/src/interface/editor.h @@ -153,7 +153,6 @@ class Editor : public QObject void copyFromScan(); void scanToTransparent(); - void scanToTransparentRest(); void toBlackLine(); void fillWhiteAreas(); void fillWhiteAreasRest(); From f8b469c442d094d6996293395ca910bb3ec5a76d Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Mon, 11 Feb 2019 21:12:24 +0100 Subject: [PATCH 025/100] Clarity in coloring dock. Ensuring start from frame 1 --- app/ui/bitmapcoloringwidget.ui | 12 ++++++------ core_lib/src/interface/editor.cpp | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index 24122131cc..577f55d961 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -46,7 +46,7 @@ - x. Black line (for repairs!) + [x. Black line (for repairs!)] @@ -265,14 +265,14 @@ - Apply to lines... + Apply to ALL lines... - [Apply repairs...] + [Apply to Active...] @@ -299,14 +299,14 @@ - Thin the Lines... + Thin ALL Lines... - [Thin repairs...] + [Thin Active line] @@ -347,7 +347,7 @@ - Replace thin lines... + Replace ALL thin lines... diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index ad63252f37..9e03d413a3 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -617,10 +617,12 @@ void Editor::fillWhiteAreas() void Editor::fillWhiteAreasRest() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); + scrubTo(1); do { layerBitmap->fillWhiteAreas(currentFrame()); scrubNextKeyFrame(); + emit updateTimeLine(); mObject->updateActiveFrames(currentFrame()); } while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()); layerBitmap->fillWhiteAreas(currentFrame()); @@ -638,6 +640,7 @@ void Editor::toThinBlackLine() void Editor::toThinBlackLineRest() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); + scrubTo(1); do { layerBitmap->toThinBlackLine(currentFrame()); @@ -651,6 +654,7 @@ void Editor::toThinBlackLineRest() void Editor::replaceThinLines() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); + scrubTo(1); do { mObject->updateActiveFrames(currentFrame()); From c004c09ce571e6cc810c05bfe0d2f3f2b6263c09 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Wed, 13 Feb 2019 06:44:26 +0100 Subject: [PATCH 026/100] Enhanced thin algorithm --- app/ui/bitmapcoloringwidget.ui | 10 +-- core_lib/src/structure/layerbitmap.cpp | 119 +++++++++++++++++-------- 2 files changed, 86 insertions(+), 43 deletions(-) diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index 577f55d961..89ca1a524f 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -6,7 +6,7 @@ 0 0 - 222 + 205 475 @@ -32,21 +32,21 @@ - Bitmap coloring process: + Coloring process: - 1. Select from scan (optional) + 1. Select from scan - [x. Black line (for repairs!)] + [x. Black line repairs...] @@ -190,7 +190,7 @@ - From bitmap to color layer + Bitmap to Color layer diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index 75198853b5..1644cc9367 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -73,6 +73,8 @@ BitmapImage* LayerBitmap::scanToTransparent(int frame) if (!keyExists(frame)) { return nullptr; } BitmapImage* img = static_cast(getKeyFrameAt(frame)); + img->enableAutoCrop(true); + img->autoCrop(); QRgb rgba; for (int x = img->left(); x <= img->right(); x++) { @@ -150,6 +152,7 @@ void LayerBitmap::toThinBlackLine(int frame) if (!keyExists(frame)) { return; } BitmapImage* img = static_cast(getKeyFrameAt(frame)); bool N = true, E = true, S = true, W = true, black, search; + while (N || E || S || W) { if (N) // from NORTH @@ -170,14 +173,24 @@ void LayerBitmap::toThinBlackLine(int frame) search = false; if (qAlpha(img->pixel(x,y+1)) > 0) { - if (qAlpha(img->pixel(x-1,y-1)) == 0 && qAlpha(img->pixel(x+1,y-1)) == 0) + if ((qAlpha(img->pixel(x-1,y-1)) == 0 && qAlpha(img->pixel(x+1,y-1)) == 0) && + (qAlpha(img->pixel(x+1, y)) > 0 || qAlpha(img->pixel(x-1, y)) >0 || + qAlpha(img->pixel(x+1, y+1)) > 0 || qAlpha(img->pixel(x-1, y+1)) >0)) + { + img->setPixel(x, y, transp); + black = true; + } + else if ((qAlpha(img->pixel(x-1,y-1)) > 0 && qAlpha(img->pixel(x+1,y-1)) > 0) && + (qAlpha(img->pixel(x+1,y)) > 0 && qAlpha(img->pixel(x-1,y)) > 0)) + { + img->setPixel(x, y, transp); + black = true; + } + else if ((qAlpha(img->pixel(x-1,y-1)) > 0 && qAlpha(img->pixel(x-1,y)) > 0) || + (qAlpha(img->pixel(x+1,y-1)) > 0 && qAlpha(img->pixel(x+1,y)) > 0)) { - if (qAlpha(img->pixel(x+1, y)) > 0 || qAlpha(img->pixel(x+1, y+1)) > 0 || - qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x-1, y+1)) > 0) - { - img->setPixel(x, y, transp); - black = true; - } + img->setPixel(x, y, transp); + black = true; } } } @@ -191,29 +204,39 @@ void LayerBitmap::toThinBlackLine(int frame) } N = black; // if none 'black' is removed, N = false } - if (S) // from SOUTH + if (E) // from EAST { black = false; search = true; - for (int x = img->left(); x < img->right(); x++) + for (int y = img->top(); y < img->bottom(); y++) { - for (int y = img->bottom(); y > img->top(); y--) + for (int x = img->right(); x > img->left(); x--) { if (search) { if (qAlpha(img->pixel(x,y)) > 0) { search = false; - if (qAlpha(img->pixel(x,y-1)) > 0) + if (qAlpha(img->pixel(x-1,y)) > 0) { - if (qAlpha(img->pixel(x-1,y+1)) == 0 && qAlpha(img->pixel(x+1,y+1)) == 0) + if ((qAlpha(img->pixel(x+1,y-1)) == 0 && qAlpha(img->pixel(x+1,y+1)) == 0) && + (qAlpha(img->pixel(x,y-1)) > 0 || qAlpha(img->pixel(x,y+1)) >0 || + qAlpha(img->pixel(x-1,y-1)) > 0 || qAlpha(img->pixel(x-1,y+1)) >0)) + { + img->setPixel(x, y, transp); + black = true; + } + else if ((qAlpha(img->pixel(x+1,y+1)) > 0 && qAlpha(img->pixel(x+1,y-1)) > 0) && + (qAlpha(img->pixel(x,y+1)) > 0 && qAlpha(img->pixel(x,y-1)) > 0)) { - if (qAlpha(img->pixel(x+1, y)) > 0 || qAlpha(img->pixel(x+1, y-1)) > 0 || - qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x-1, y-1)) > 0) - { - img->setPixel(x, y, transp); - black = true; - } + img->setPixel(x, y, transp); + black = true; + } + else if ((qAlpha(img->pixel(x+1,y+1)) > 0 && qAlpha(img->pixel(x,y+1)) > 0) || + (qAlpha(img->pixel(x+1,y-1)) > 0 && qAlpha(img->pixel(x,y-1)) > 0)) + { + img->setPixel(x, y, transp); + black = true; } } } @@ -225,31 +248,41 @@ void LayerBitmap::toThinBlackLine(int frame) } } } - S = black; // if none 'black' is removed, S = false + E = black; // if none 'black' is removed, E = false } - if (E) // from EAST + if (S) // from SOUTH { black = false; search = true; - for (int y = img->top(); y < img->bottom(); y++) + for (int x = img->left(); x < img->right(); x++) { - for (int x = img->right(); x > img->left(); x--) + for (int y = img->bottom(); y > img->top(); y--) { if (search) { if (qAlpha(img->pixel(x,y)) > 0) { search = false; - if (qAlpha(img->pixel(x-1,y)) > 0) + if (qAlpha(img->pixel(x,y-1)) > 0) { - if (qAlpha(img->pixel(x+1,y-1)) == 0 && qAlpha(img->pixel(x+1,y+1)) == 0) + if ((qAlpha(img->pixel(x-1,y+1)) == 0 && qAlpha(img->pixel(x+1,y+1)) == 0) && + (qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x+1, y)) >0 || + qAlpha(img->pixel(x-1, y-1)) > 0 || qAlpha(img->pixel(x+1, y-1)) >0)) + { + img->setPixel(x, y, transp); + black = true; + } + else if ((qAlpha(img->pixel(x-1,y+1)) > 0 && qAlpha(img->pixel(x+1,y+1)) > 0) && + (qAlpha(img->pixel(x+1,y)) > 0 && qAlpha(img->pixel(x-1,y)) > 0)) + { + img->setPixel(x, y, transp); + black = true; + } + else if ((qAlpha(img->pixel(x-1,y+1)) > 0 && qAlpha(img->pixel(x-1,y)) > 0) || + (qAlpha(img->pixel(x+1,y+1)) > 0 && qAlpha(img->pixel(x+1,y)) > 0)) { - if (qAlpha(img->pixel(x-1, y-1)) > 0 || qAlpha(img->pixel(x, y-1)) > 0 || - qAlpha(img->pixel(x-1, y+1)) > 0 || qAlpha(img->pixel(x, y+1)) > 0) - { - img->setPixel(x, y, transp); - black = true; - } + img->setPixel(x, y, transp); + black = true; } } } @@ -261,7 +294,7 @@ void LayerBitmap::toThinBlackLine(int frame) } } } - E = black; // if none 'black' is removed, E = false + S = black; // if none 'black' is removed, S = false } if (W) // from WEST { @@ -278,14 +311,24 @@ void LayerBitmap::toThinBlackLine(int frame) search = false; if (qAlpha(img->pixel(x+1,y)) > 0) { - if (qAlpha(img->pixel(x-1,y-1)) == 0 && qAlpha(img->pixel(x-1,y+1)) == 0) + if ((qAlpha(img->pixel(x-1,y-1)) == 0 && qAlpha(img->pixel(x-1,y+1)) == 0) && + (qAlpha(img->pixel(x,y-1)) > 0 || qAlpha(img->pixel(x,y+1)) >0 || + qAlpha(img->pixel(x+1,y-1)) > 0 || qAlpha(img->pixel(x+1,y+1)) >0)) + { + img->setPixel(x, y, transp); + black = true; + } + else if ((qAlpha(img->pixel(x-1,y+1)) > 0 && qAlpha(img->pixel(x-1,y-1)) > 0) && + (qAlpha(img->pixel(x,y+1)) > 0 && qAlpha(img->pixel(x,y-1)) > 0)) + { + img->setPixel(x, y, transp); + black = true; + } + else if ((qAlpha(img->pixel(x-1,y+1)) > 0 && qAlpha(img->pixel(x,y+1)) > 0) || + (qAlpha(img->pixel(x-1,y-1)) > 0 && qAlpha(img->pixel(x,y-1)) > 0)) { - if (qAlpha(img->pixel(x, y-1)) > 0 || qAlpha(img->pixel(x+1, y-1)) > 0 || - qAlpha(img->pixel(x, y+1)) > 0 || qAlpha(img->pixel(x+1, y+1)) > 0) - { - img->setPixel(x, y, transp); - black = true; - } + img->setPixel(x, y, transp); + black = true; } } } From 669a9a170c0875e6411b5c29c7078757175483e0 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Wed, 13 Feb 2019 08:15:18 +0100 Subject: [PATCH 027/100] Changed QRgb thinline. Optimized coloring functions --- core_lib/src/interface/editor.cpp | 54 ++++++++++++++-------------- core_lib/src/structure/layerbitmap.h | 2 +- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 9e03d413a3..50f6cb9ae1 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -617,16 +617,16 @@ void Editor::fillWhiteAreas() void Editor::fillWhiteAreasRest() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); - scrubTo(1); - do + for (int i = 1; i <= layerBitmap->getMaxKeyFramePosition(); i++) { - layerBitmap->fillWhiteAreas(currentFrame()); - scrubNextKeyFrame(); - emit updateTimeLine(); - mObject->updateActiveFrames(currentFrame()); - } while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()); - layerBitmap->fillWhiteAreas(currentFrame()); - mScribbleArea->updateFrame(currentFrame()); + if (layerBitmap->keyExists(i)) + { + scrubTo(i); + layerBitmap->fillWhiteAreas(currentFrame()); + mObject->updateActiveFrames(currentFrame()); + mScribbleArea->updateFrame(currentFrame()); + } + } } void Editor::toThinBlackLine() @@ -640,29 +640,31 @@ void Editor::toThinBlackLine() void Editor::toThinBlackLineRest() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); - scrubTo(1); - do + for (int i = 1; i <= layerBitmap->getMaxKeyFramePosition(); i++) { - layerBitmap->toThinBlackLine(currentFrame()); - scrubNextKeyFrame(); - mObject->updateActiveFrames(currentFrame()); - } while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()); - layerBitmap->toThinBlackLine(currentFrame()); - mScribbleArea->updateFrame(currentFrame()); + if (layerBitmap->keyExists(i)) + { + scrubTo(i); + layerBitmap->toThinBlackLine(currentFrame()); + mObject->updateActiveFrames(currentFrame()); + mScribbleArea->updateFrame(currentFrame()); + } + } } void Editor::replaceThinLines() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); - scrubTo(1); - do - { - mObject->updateActiveFrames(currentFrame()); - layerBitmap->replaceThinLine(currentFrame()); - scrubNextKeyFrame(); - } while (layerBitmap->getNextKeyFramePosition(currentFrame()) > currentFrame()); - layerBitmap->replaceThinLine(currentFrame()); - mScribbleArea->updateFrame(currentFrame()); + for (int i = 1; i <= layerBitmap->getMaxKeyFramePosition(); i++) + { + if (layerBitmap->keyExists(i)) + { + scrubTo(i); + layerBitmap->replaceThinLine(currentFrame()); + mObject->updateActiveFrames(currentFrame()); + mScribbleArea->updateFrame(currentFrame()); + } + } } void Editor::clipboardChanged() diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index aebf654709..609f8f2368 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -28,7 +28,7 @@ class LayerBitmap : public Layer public: const QRgb transp = qRgba(0, 0, 0, 0); - const QRgb thinline = qRgba(0, 0, 0, 255); + const QRgb thinline = qRgba(0, 1, 0, 255); const QRgb rosa = qRgba(255,230,230,255); LayerBitmap(Object* object); From 1095da683e0bfcd0628102f8d0553e7893f4eb0c Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Wed, 13 Feb 2019 11:29:13 +0100 Subject: [PATCH 028/100] Replaced ParentId with mHasColorLayer and mIsColorLayer --- app/src/actioncommands.cpp | 7 +++++-- app/src/bitmapcoloring.cpp | 19 +++++++++---------- app/src/mainwindow2.cpp | 3 ++- core_lib/src/interface/timelinecells.cpp | 14 ++++++++++++++ core_lib/src/structure/layer.h | 11 ++++++++--- core_lib/src/structure/layerbitmap.cpp | 2 -- core_lib/src/structure/layerbitmap.h | 2 +- 7 files changed, 39 insertions(+), 19 deletions(-) diff --git a/app/src/actioncommands.cpp b/app/src/actioncommands.cpp index 102ecd5a07..5a11c78a8c 100644 --- a/app/src/actioncommands.cpp +++ b/app/src/actioncommands.cpp @@ -655,9 +655,12 @@ Status ActionCommands::addNewBitmapColorLayer() QString name = mEditor->layers()->currentLayer()->name() + "_C"; if (!name.isEmpty()) { + LayerBitmap* parentlayer = static_cast(mEditor->layers()->currentLayer()); + parentlayer->setHasColorLayer(true); LayerBitmap* colorlayer = mEditor->layers()->createBitmapLayer(name); - colorlayer->initColorLayer(mEditor->layers()->currentLayer(), colorlayer); - colorlayer->setParentId(mEditor->layers()->currentLayer()->id()); + colorlayer->initColorLayer(parentlayer, colorlayer); + colorlayer->setIsColorLayer(true); + emit mEditor->layers()->currentLayerChanged(mEditor->layers()->currentLayerIndex()); } return Status::OK; } diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 2b7db9e279..e759280b45 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -65,22 +65,21 @@ void BitmapColoring::updateUI() Layer* layer = mEditor->layers()->currentLayer(); setEnabled(true); - if (layer->type() == Layer::BITMAP && layer->parentId() == -1) + if (layer->type() == Layer::BITMAP && !layer->getIsColorLayer()) { ui->tabWidgetColor->setEnabled(false); ui->tabWidgetScans->setEnabled(true); - bool colLayerExists = false; - for (int i = 0; i < mEditor->layers()->count(); i++) + if (layer->getHasColorLayer()) { - if (mEditor->layers()->getLayer(i)->parentId() == layer->id()) - { - ui->labx_3->setText(tr("To Layer: %1").arg(mEditor->layers()->getLayer(i)->name())); - colLayerExists = true; - } + ui->labx_3->setText(tr("To Layer: %1").arg(layer->name())); + ui->btnx_blackLine->setEnabled(true); + } + else + { + ui->btnx_blackLine->setEnabled(false); } - colLayerExists == true ? ui->btnx_blackLine->setEnabled(true) : ui->btnx_blackLine->setEnabled(false); } - else if (layer->type() == Layer::BITMAP && layer->parentId() > -1) + else if (layer->type() == Layer::BITMAP && layer->getIsColorLayer()) { ui->tabWidgetColor->setEnabled(true); ui->tabWidgetScans->setEnabled(false); diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index c687e48e60..06c8da8315 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -1394,7 +1394,8 @@ void MainWindow2::updateZoomLabel() void MainWindow2::updateLayerMenu() { - if (mEditor->layers()->currentLayer()->type() == Layer::BITMAP) + Layer* layer = mEditor->layers()->currentLayer(); + if (layer->type() == Layer::BITMAP && !layer->getHasColorLayer() && !layer->getIsColorLayer()) ui->actionAdd_Bitmap_Color_Layer->setEnabled(true); else ui->actionAdd_Bitmap_Color_Layer->setEnabled(false); diff --git a/core_lib/src/interface/timelinecells.cpp b/core_lib/src/interface/timelinecells.cpp index dcc9debc5f..93bf942da2 100644 --- a/core_lib/src/interface/timelinecells.cpp +++ b/core_lib/src/interface/timelinecells.cpp @@ -20,6 +20,7 @@ GNU General Public License for more details. #include #include #include +#include #include "object.h" #include "editor.h" @@ -725,6 +726,13 @@ void TimeLineCells::mouseDoubleClickEvent(QMouseEvent* event) } else { + if (layer->getIsColorLayer()) + { + Q_UNUSED(QMessageBox::information(this, tr("Rename not allowed"), + tr("You cannot rename color layers."), + QMessageBox::Ok)); + return; + } QRegExp regex("([\\xFFEF-\\xFFFF])+"); bool ok; @@ -734,7 +742,13 @@ void TimeLineCells::mouseDoubleClickEvent(QMouseEvent* event) if (ok && !text.isEmpty()) { text.replace(regex, ""); + QString orgName = layer->name(); mEditor->layers()->renameLayer(layer, text); + Layer* colorlayer = mEditor->layers()->findLayerByName(orgName + "_C"); + if (colorlayer != nullptr) + { + mEditor->layers()->renameLayer(colorlayer, text + "_C"); + } } } } diff --git a/core_lib/src/structure/layer.h b/core_lib/src/structure/layer.h index 915a3863d4..76ffadcb71 100644 --- a/core_lib/src/structure/layer.h +++ b/core_lib/src/structure/layer.h @@ -64,8 +64,12 @@ class Layer : public QObject bool visible() const { return mVisible; } void setVisible(bool b) { mVisible = b; } - int parentId() const { return mParentId; } - void setParentId(int pId) { mParentId = pId; } + + void setHasColorLayer(bool b) { mHasColorLayer = b; } + bool getHasColorLayer() { return mHasColorLayer; } + void setIsColorLayer(bool b) { mIsColorLayer = b; } + bool getIsColorLayer() { return mIsColorLayer; } + virtual Status saveKeyFrameFile(KeyFrame*, QString dataPath) = 0; virtual void loadDomElement(QDomElement element, QString dataDirPath, ProgressCallback progressForward) = 0; @@ -133,8 +137,9 @@ class Layer : public QObject Object* mObject = nullptr; int mId = 0; bool mVisible = true; - int mParentId = -1; ///< Only set (changed) for coloring layers QString mName; + bool mHasColorLayer = false; + bool mIsColorLayer = false; std::map> mKeyFrames; diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index 1644cc9367..fbf52d6e4c 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -552,7 +552,6 @@ QDomElement LayerBitmap::createDomElement(QDomDocument& doc) layerTag.setAttribute("name", name()); layerTag.setAttribute("visibility", visible()); layerTag.setAttribute("type", type()); - layerTag.setAttribute("parentid", parentId()); foreachKeyFrame([&](KeyFrame* pKeyFrame) { @@ -580,7 +579,6 @@ void LayerBitmap::loadDomElement(QDomElement element, QString dataDirPath, Progr } setName(element.attribute("name")); setVisible(element.attribute("visibility").toInt() == 1); - setParentId(element.attribute("parentid").toInt()); QDomNode imageTag = element.firstChild(); while (!imageTag.isNull()) diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index 609f8f2368..bf6222c1ac 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -28,7 +28,7 @@ class LayerBitmap : public Layer public: const QRgb transp = qRgba(0, 0, 0, 0); - const QRgb thinline = qRgba(0, 1, 0, 255); + const QRgb thinline = qRgba(1, 0, 0, 255); const QRgb rosa = qRgba(255,230,230,255); LayerBitmap(Object* object); From 97590df91d2a72a3312127f45472fb16b289bb1a Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Wed, 13 Feb 2019 14:01:58 +0100 Subject: [PATCH 029/100] Refining dialog appearence --- app/src/bitmapcoloring.cpp | 10 ++++++++++ app/ui/bitmapcoloringwidget.ui | 23 +++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index e759280b45..d439034ea7 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -69,6 +69,11 @@ void BitmapColoring::updateUI() { ui->tabWidgetColor->setEnabled(false); ui->tabWidgetScans->setEnabled(true); + ui->labcp_1->setEnabled(true); + ui->labcp_1x->setEnabled(true); + ui->labcp_2->setEnabled(false); + ui->labcp_3->setEnabled(false); + ui->labcp_4->setEnabled(false); if (layer->getHasColorLayer()) { ui->labx_3->setText(tr("To Layer: %1").arg(layer->name())); @@ -83,6 +88,11 @@ void BitmapColoring::updateUI() { ui->tabWidgetColor->setEnabled(true); ui->tabWidgetScans->setEnabled(false); + ui->labcp_1->setEnabled(false); + ui->labcp_1x->setEnabled(false); + ui->labcp_2->setEnabled(true); + ui->labcp_3->setEnabled(true); + ui->labcp_4->setEnabled(true); } else { diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index 89ca1a524f..90893ca44d 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -6,8 +6,8 @@ 0 0 - 205 - 475 + 247 + 585 @@ -24,7 +24,7 @@ - + 75 @@ -37,35 +37,42 @@ - + 1. Select from scan - + [x. Black line repairs...] - + + + Qt::Horizontal + + + + + 2. Remove white areas - + 3. Thin the lines... - + 4. Remove black line From 091a2c292a75d2a9c3d04562eac324b418de6940 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Wed, 13 Feb 2019 23:12:37 +0100 Subject: [PATCH 030/100] Update dock when visible --- app/src/bitmapcoloring.cpp | 8 ++++++-- app/src/bitmapcoloring.h | 1 + app/src/mainwindow2.cpp | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index d439034ea7..f972c894fe 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -54,8 +54,6 @@ BitmapColoring::~BitmapColoring() void BitmapColoring::initUI() { -// if (!isVisible()) { return; } - updateUI(); } @@ -99,3 +97,9 @@ void BitmapColoring::updateUI() setEnabled(false); } } + +void BitmapColoring::visibilityChanged(bool visibility) +{ + Q_UNUSED(visibility); + updateUI(); +} diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 505f7c1219..2791e1053e 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -22,6 +22,7 @@ class BitmapColoring : public BaseDockWidget void initUI() override; void updateUI() override; + void visibilityChanged(bool visibility); signals: diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index 06c8da8315..287acd652f 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -1336,6 +1336,7 @@ void MainWindow2::makeConnections(Editor* pEditor, TimeLine* pTimeline) connect(pEditor->layers(), &LayerManager::currentLayerChanged, mToolOptions, &ToolOptionWidget::updateUI); connect(pEditor->layers(), &LayerManager::currentLayerChanged, mBitmapColoring, &BitmapColoring::updateUI); + connect(mBitmapColoring, &QDockWidget::visibilityChanged, mBitmapColoring, &BitmapColoring::visibilityChanged); connect(pEditor->layers(), &LayerManager::currentLayerChanged, this, &MainWindow2::updateLayerMenu); } From 4b9f8d03ac2fb9d0fb013a9650f8981b5a97253b Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Tue, 19 Feb 2019 22:18:21 +0100 Subject: [PATCH 031/100] Moved functions from LayerBitmap to BitmapImage --- app/src/actioncommands.cpp | 2 +- app/src/bitmapcoloring.cpp | 5 +- app/src/bitmapcoloring.h | 2 + core_lib/src/graphics/bitmap/bitmapimage.cpp | 367 ++++++++++++++++++ core_lib/src/graphics/bitmap/bitmapimage.h | 32 +- core_lib/src/interface/editor.cpp | 17 +- core_lib/src/structure/layerbitmap.cpp | 373 +------------------ core_lib/src/structure/layerbitmap.h | 20 - 8 files changed, 418 insertions(+), 400 deletions(-) diff --git a/app/src/actioncommands.cpp b/app/src/actioncommands.cpp index 5a11c78a8c..a222bc2332 100644 --- a/app/src/actioncommands.cpp +++ b/app/src/actioncommands.cpp @@ -658,7 +658,7 @@ Status ActionCommands::addNewBitmapColorLayer() LayerBitmap* parentlayer = static_cast(mEditor->layers()->currentLayer()); parentlayer->setHasColorLayer(true); LayerBitmap* colorlayer = mEditor->layers()->createBitmapLayer(name); - colorlayer->initColorLayer(parentlayer, colorlayer); + parentlayer->initColorLayer(parentlayer, colorlayer); colorlayer->setIsColorLayer(true); emit mEditor->layers()->currentLayerChanged(mEditor->layers()->currentLayerIndex()); } diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index f972c894fe..3174d967c4 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -33,13 +33,14 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : mEditor = editor; if (mEditor->layers()->currentLayer()->type() == Layer::BITMAP) mLayerBitmap = static_cast(mEditor->layers()->currentLayer()); + mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); connect(ui->btn1Select, &QPushButton::clicked, mEditor, &Editor::copyFromScan); connect(ui->btn1Next, &QPushButton::clicked, mEditor, &Editor::scrubNextKeyFrame); - connect(ui->sb1_Threshold, QOverload::of(&QSpinBox::valueChanged), mLayerBitmap, &LayerBitmap::setThreshold); +// connect(ui->sb1_Threshold, QOverload(&QSpinBox::valueChanged), mBitmapImage, &BitmapImage::setThreshold); connect(ui->btnx_blackLine, &QPushButton::clicked, mEditor, &Editor::toBlackLine); - connect(ui->sb2_fillArea, QOverload::of(&QSpinBox::valueChanged), mLayerBitmap, &LayerBitmap::setWhiteArea); +// connect(ui->sb2_fillArea, SIGNAL(valueChanged(int)), mBitmapImage, SLOT(setWhiteArea(int))); connect(ui->btn2_fillRest, &QPushButton::clicked, mEditor, &Editor::fillWhiteAreasRest); connect(ui->btn2_repairs, &QPushButton::clicked, mEditor, &Editor::fillWhiteAreas); connect(ui->btn3_thinRest, &QPushButton::clicked, mEditor, &Editor::toThinBlackLineRest); diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 2791e1053e..019332015b 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -4,6 +4,7 @@ #include "basedockwidget.h" #include "editor.h" #include "layerbitmap.h" +#include "bitmapimage.h" class Layer; @@ -32,6 +33,7 @@ public slots: Ui::BitmapColoringWidget* ui = nullptr; Editor* mEditor = nullptr; LayerBitmap* mLayerBitmap = nullptr; + BitmapImage* mBitmapImage; }; diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 418f0b7b69..9dd6995e36 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -655,6 +655,373 @@ void BitmapImage::setBounds(QRect rect) updateBounds(rect); } +BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage) +{ + Q_ASSERT(bitmapimage != nullptr); + + BitmapImage* img = bitmapimage; + img->enableAutoCrop(true); + img->autoCrop(); + QRgb rgba; + for (int x = img->left(); x <= img->right(); x++) + { + for (int y = img->top(); y <= img->bottom(); y++) + { + rgba = img->pixel(x, y); + if (qGray(rgba) >= mThreshold) + { + img->setPixel(x, y, transp); + } + else if(qGray(rgba) >= mLowThreshold && qGray(rgba) < mThreshold) + { + qreal factor = qreal(mThreshold - qGray(rgba)) / qreal(mThreshold - mLowThreshold); + int alpha = static_cast(255 * factor); + QRgb tmp = qRgba(0, 0, 0, alpha); + img->setPixel(x , y, tmp); + } + } + } + img->modification(); + return img; +} + +void BitmapImage::toBlackLine(BitmapImage* bitmapimage) +{ + Q_ASSERT(bitmapimage != nullptr); + + BitmapImage* img = bitmapimage; + for (int x = img->left(); x <= img->right(); x++) + { + for (int y = img->top(); y <= img->bottom(); y++) + { + if (qAlpha(img->pixel(x, y)) > 0) + img->setPixel(x, y, thinline); + } + } + bitmapimage->modification(); +} + +void BitmapImage::fillWhiteAreas(BitmapImage *bitmapimage) +{ + Q_ASSERT(bitmapimage != nullptr); + + BitmapImage* img = bitmapimage; + + // fill areas size 'area' or less with black + QVector points; + points.clear(); + for (int x = img->left(); x < img->right(); x++) + { + for (int y = img->top(); y < img->bottom(); y++) + { + if (qAlpha(img->pixel(x, y)) < 1) + { + points.append(QPoint(x, y)); + int areaSize = fillWithColor(QPoint(x, y), transp, rosa, bitmapimage); + if (areaSize <= mWhiteArea) + { // replace rosa with thinline (black) + fillWithColor(points.last(), rosa, thinline, bitmapimage); + points.removeLast(); + } + } + } + } + // replace rosa with trans + while (!points.isEmpty()) { + fillWithColor(points[0], rosa, transp, bitmapimage); + points.removeFirst(); + } + bitmapimage->modification(); +} + +void BitmapImage::toThinBlackLine(BitmapImage* bitmapimage) +{ + Q_ASSERT(bitmapimage != nullptr); + + BitmapImage* img = bitmapimage; + bool N = true, E = true, S = true, W = true, black, search; + + while (N || E || S || W) + { + if (N) // from NORTH + { + // set 'black' to false. 'black' is set to true whenever a black pixel is removed + black = false; + // 'search' is true while pixels are transparent + // when thinline pixel is found, 'search' is set to false until next transparent pixel + search = true; + for (int x = img->left(); x < img->right(); x++) + { + for (int y = img->top(); y < img->bottom(); y++) + { + if (search) + { + if (qAlpha(img->pixel(x,y)) > 0) + { + search = false; + if (qAlpha(img->pixel(x,y+1)) > 0) + { + if ((qAlpha(img->pixel(x-1,y-1)) == 0 && qAlpha(img->pixel(x+1,y-1)) == 0) && + (qAlpha(img->pixel(x+1, y)) > 0 || qAlpha(img->pixel(x-1, y)) >0 || + qAlpha(img->pixel(x+1, y+1)) > 0 || qAlpha(img->pixel(x-1, y+1)) >0)) + { + img->setPixel(x, y, transp); + black = true; + } + else if ((qAlpha(img->pixel(x-1,y-1)) > 0 && qAlpha(img->pixel(x+1,y-1)) > 0) && + (qAlpha(img->pixel(x+1,y)) > 0 && qAlpha(img->pixel(x-1,y)) > 0)) + { + img->setPixel(x, y, transp); + black = true; + } + else if ((qAlpha(img->pixel(x-1,y-1)) > 0 && qAlpha(img->pixel(x-1,y)) > 0) || + (qAlpha(img->pixel(x+1,y-1)) > 0 && qAlpha(img->pixel(x+1,y)) > 0)) + { + img->setPixel(x, y, transp); + black = true; + } + } + } + } + else + { + if (qAlpha(img->pixel(x,y)) == 0) + search = true; + } + } + } + N = black; // if none 'black' is removed, N = false + } + if (E) // from EAST + { + black = false; + search = true; + for (int y = img->top(); y < img->bottom(); y++) + { + for (int x = img->right(); x > img->left(); x--) + { + if (search) + { + if (qAlpha(img->pixel(x,y)) > 0) + { + search = false; + if (qAlpha(img->pixel(x-1,y)) > 0) + { + if ((qAlpha(img->pixel(x+1,y-1)) == 0 && qAlpha(img->pixel(x+1,y+1)) == 0) && + (qAlpha(img->pixel(x,y-1)) > 0 || qAlpha(img->pixel(x,y+1)) >0 || + qAlpha(img->pixel(x-1,y-1)) > 0 || qAlpha(img->pixel(x-1,y+1)) >0)) + { + img->setPixel(x, y, transp); + black = true; + } + else if ((qAlpha(img->pixel(x+1,y+1)) > 0 && qAlpha(img->pixel(x+1,y-1)) > 0) && + (qAlpha(img->pixel(x,y+1)) > 0 && qAlpha(img->pixel(x,y-1)) > 0)) + { + img->setPixel(x, y, transp); + black = true; + } + else if ((qAlpha(img->pixel(x+1,y+1)) > 0 && qAlpha(img->pixel(x,y+1)) > 0) || + (qAlpha(img->pixel(x+1,y-1)) > 0 && qAlpha(img->pixel(x,y-1)) > 0)) + { + img->setPixel(x, y, transp); + black = true; + } + } + } + } + else + { + if (qAlpha(img->pixel(x,y)) == 0) + search = true; + } + } + } + E = black; // if none 'black' is removed, E = false + } + if (S) // from SOUTH + { + black = false; + search = true; + for (int x = img->left(); x < img->right(); x++) + { + for (int y = img->bottom(); y > img->top(); y--) + { + if (search) + { + if (qAlpha(img->pixel(x,y)) > 0) + { + search = false; + if (qAlpha(img->pixel(x,y-1)) > 0) + { + if ((qAlpha(img->pixel(x-1,y+1)) == 0 && qAlpha(img->pixel(x+1,y+1)) == 0) && + (qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x+1, y)) >0 || + qAlpha(img->pixel(x-1, y-1)) > 0 || qAlpha(img->pixel(x+1, y-1)) >0)) + { + img->setPixel(x, y, transp); + black = true; + } + else if ((qAlpha(img->pixel(x-1,y+1)) > 0 && qAlpha(img->pixel(x+1,y+1)) > 0) && + (qAlpha(img->pixel(x+1,y)) > 0 && qAlpha(img->pixel(x-1,y)) > 0)) + { + img->setPixel(x, y, transp); + black = true; + } + else if ((qAlpha(img->pixel(x-1,y+1)) > 0 && qAlpha(img->pixel(x-1,y)) > 0) || + (qAlpha(img->pixel(x+1,y+1)) > 0 && qAlpha(img->pixel(x+1,y)) > 0)) + { + img->setPixel(x, y, transp); + black = true; + } + } + } + } + else + { + if (qAlpha(img->pixel(x,y)) == 0) + search = true; + } + } + } + S = black; // if none 'black' is removed, S = false + } + if (W) // from WEST + { + black = false; + search = true; + for (int y = img->top(); y <= img->bottom(); y++) + { + for (int x = img->left(); x < img->right(); x++) + { + if (search) + { + if (qAlpha(img->pixel(x,y)) > 0) + { + search = false; + if (qAlpha(img->pixel(x+1,y)) > 0) + { + if ((qAlpha(img->pixel(x-1,y-1)) == 0 && qAlpha(img->pixel(x-1,y+1)) == 0) && + (qAlpha(img->pixel(x,y-1)) > 0 || qAlpha(img->pixel(x,y+1)) >0 || + qAlpha(img->pixel(x+1,y-1)) > 0 || qAlpha(img->pixel(x+1,y+1)) >0)) + { + img->setPixel(x, y, transp); + black = true; + } + else if ((qAlpha(img->pixel(x-1,y+1)) > 0 && qAlpha(img->pixel(x-1,y-1)) > 0) && + (qAlpha(img->pixel(x,y+1)) > 0 && qAlpha(img->pixel(x,y-1)) > 0)) + { + img->setPixel(x, y, transp); + black = true; + } + else if ((qAlpha(img->pixel(x-1,y+1)) > 0 && qAlpha(img->pixel(x,y+1)) > 0) || + (qAlpha(img->pixel(x-1,y-1)) > 0 && qAlpha(img->pixel(x,y-1)) > 0)) + { + img->setPixel(x, y, transp); + black = true; + } + } + } + } + else + { + if (qAlpha(img->pixel(x,y)) == 0) + search = true; + } + } + } + W = black; // if none 'black' is removed, W = false + } + } + bitmapimage->modification(); +} + +void BitmapImage::replaceThinLine(BitmapImage *bitmapimage) +{ + Q_ASSERT(bitmapimage != nullptr); + + BitmapImage* img = bitmapimage; + + int r, g, b, a; //red, green, blue, alpha + QList points; + for (int x = img->left(); x <= img->right(); x++) + { + for (int y = img->top(); y <= img->bottom(); y++) + { + points.clear(); + r=0; g=0; b=0; a=0; + if (img->pixel(x,y) == thinline) + { + if (img->pixel(x-1, y-1) != thinline) points.append(QPoint(x-1, y-1)); + if (img->pixel(x-1, y ) != thinline) points.append(QPoint(x-1, y )); + if (img->pixel(x-1, y+1) != thinline) points.append(QPoint(x-1, y+1)); + if (img->pixel(x , y-1) != thinline) points.append(QPoint(x , y-1)); + if (img->pixel(x , y+1) != thinline) points.append(QPoint(x , y+1)); + if (img->pixel(x+1, y-1) != thinline) points.append(QPoint(x+1, y-1)); + if (img->pixel(x+1, y ) != thinline) points.append(QPoint(x+1, y )); + if (img->pixel(x+1, y+1) != thinline) points.append(QPoint(x+1, y+1)); + for (int i = 0; i < points.size(); i++) + { + r += qPow(qRed(img->pixel(points.at(i))), 2); + g += qPow(qGreen(img->pixel(points.at(i))), 2); + b += qPow(qBlue(img->pixel(points.at(i))), 2); + a += qPow(qAlpha(img->pixel(points.at(i))), 2); + } + r = static_cast(sqrt(r/points.size())); + g = static_cast(sqrt(g/points.size())); + b = static_cast(sqrt(b/points.size())); + a = static_cast(sqrt(a/points.size())); + img->setPixel(x, y, qRgba(r, g, b, a)); + } + } + } + bitmapimage->modification(); +} + +int BitmapImage::fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, BitmapImage *bitmapimage) +{ + Q_ASSERT(bitmapimage != nullptr); + + BitmapImage* img = bitmapimage; + QList fillList; + fillList.clear(); + // fill first pixel + img->setPixel(point, newColor); + int pixels = 1; + fillList.append(point); + + QRect rect = img->bounds(); + while (!fillList.isEmpty()) + { + QPoint tmp = fillList.at(0); + if (rect.contains(QPoint(tmp.x() + 1, tmp.y())) && img->pixel(QPoint(tmp.x() + 1, tmp.y())) == orgColor) + { + img->setPixel(QPoint(tmp.x() + 1, tmp.y()), newColor); + fillList.append(QPoint(tmp.x() + 1, tmp.y())); + pixels++; + } + if (rect.contains(QPoint(tmp.x(), tmp.y() + 1)) && img->pixel(QPoint(tmp.x(), tmp.y() + 1)) == orgColor) + { + img->setPixel(QPoint(tmp.x(), tmp.y() + 1), newColor); + fillList.append(QPoint(tmp.x(), tmp.y() + 1)); + pixels++; + } + if (rect.contains(QPoint(tmp.x() - 1, tmp.y())) && img->pixel(QPoint(tmp.x() - 1, tmp.y())) == orgColor) + { + img->setPixel(QPoint(tmp.x() - 1, tmp.y()), newColor); + fillList.append(QPoint(tmp.x() - 1, tmp.y())); + pixels++; + } + if (rect.contains(QPoint(tmp.x(), tmp.y() - 1)) && img->pixel(QPoint(tmp.x(), tmp.y() - 1)) == orgColor) + { + img->setPixel(QPoint(tmp.x(), tmp.y() - 1), newColor); + fillList.append(QPoint(tmp.x(), tmp.y() - 1)); + pixels++; + } + fillList.removeFirst(); + } + bitmapimage->modification(); + return pixels; +} + Status BitmapImage::writeFile(const QString& filename) { if (mImage && !mImage->isNull()) diff --git a/core_lib/src/graphics/bitmap/bitmapimage.h b/core_lib/src/graphics/bitmap/bitmapimage.h index 38016491c8..4ea82d8bf6 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.h +++ b/core_lib/src/graphics/bitmap/bitmapimage.h @@ -20,18 +20,25 @@ GNU General Public License for more details. #include #include #include "keyframe.h" +#include "layer.h" +#include "layerbitmap.h" +class Editor; class BitmapImage : public KeyFrame { public: + const QRgb transp = qRgba(0, 0, 0, 0); + const QRgb thinline = qRgba(1, 0, 0, 255); + const QRgb rosa = qRgba(255,230,230,255); + BitmapImage(); BitmapImage(const BitmapImage&); BitmapImage(const QRect &rectangle, const QColor& colour); BitmapImage(const QPoint& topLeft, const QImage& image); BitmapImage(const QPoint& topLeft, const QString& path); - ~BitmapImage(); + ~BitmapImage() override; BitmapImage& operator=(const BitmapImage& a); BitmapImage* clone() override; @@ -94,6 +101,20 @@ class BitmapImage : public KeyFrame QRect& bounds() { autoCrop(); return mBounds; } void setBounds(QRect rect); + // coloring methods + int getThreshold() { return mThreshold; } + int getWhiteArea() { return mWhiteArea; } + BitmapImage* scanToTransparent(BitmapImage* bitmapimage); + + void toBlackLine(BitmapImage* bitmapimage); + + void fillWhiteAreas(BitmapImage* bitmapimage); + void toThinBlackLine(BitmapImage* bitmapimage); + void replaceThinLine(BitmapImage* bitmapimage); + int fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, BitmapImage* bitmapimage); + // color layer methods end + + /** Determines if the BitmapImage is minimally bounded. * * A BitmapImage is minimally bounded if all edges contain @@ -109,6 +130,10 @@ class BitmapImage : public KeyFrame Status writeFile(const QString& filename); +public slots: + void setThreshold(int threshold) { mThreshold = threshold; } + void setWhiteArea(int whiteArea) { mWhiteArea = whiteArea; } + protected: void updateBounds(QRect rectangle); void extend(const QPoint& p); @@ -124,6 +149,11 @@ class BitmapImage : public KeyFrame /** @see isMinimallyBounded() */ bool mMinBound = true; bool mEnableAutoCrop = false; + + int mThreshold = 200; + const int mLowThreshold = 30; // threshold for images to be given transparency + int mWhiteArea = 6; + }; #endif diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 50f6cb9ae1..febf54b3c2 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -591,9 +591,8 @@ void Editor::copyFromScan() void Editor::scanToTransparent() { - LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); - mObject->updateActiveFrames(currentFrame()); - layerBitmap->scanToTransparent(currentFrame()); + BitmapImage* bitmapimage = static_cast(layers()->currentLayer()->getKeyFrameAt(currentFrame())); + bitmapimage = bitmapimage->scanToTransparent(bitmapimage); mScribbleArea->updateFrame(currentFrame()); } @@ -602,7 +601,7 @@ void Editor::toBlackLine() LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); LayerBitmap* toLayer = static_cast(layers()->findLayerByName(layerBitmap->name() + "_C")); mObject->updateActiveFrames(currentFrame()); - toLayer->singleInitColorLayer(layerBitmap, toLayer , currentFrame()); + layerBitmap->singleInitColorLayer(layerBitmap, toLayer , currentFrame()); mScribbleArea->updateFrame(currentFrame()); } @@ -610,7 +609,7 @@ void Editor::fillWhiteAreas() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); mObject->updateActiveFrames(currentFrame()); - layerBitmap->fillWhiteAreas(currentFrame()); + layerBitmap->getBitmapImageAtFrame(currentFrame())->fillWhiteAreas(layerBitmap->getBitmapImageAtFrame(currentFrame())); mScribbleArea->updateFrame(currentFrame()); } @@ -622,7 +621,7 @@ void Editor::fillWhiteAreasRest() if (layerBitmap->keyExists(i)) { scrubTo(i); - layerBitmap->fillWhiteAreas(currentFrame()); + layerBitmap->getBitmapImageAtFrame(currentFrame())->fillWhiteAreas(layerBitmap->getBitmapImageAtFrame(currentFrame())); mObject->updateActiveFrames(currentFrame()); mScribbleArea->updateFrame(currentFrame()); } @@ -633,7 +632,7 @@ void Editor::toThinBlackLine() { LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); mObject->updateActiveFrames(currentFrame()); - layerBitmap->toThinBlackLine(currentFrame()); + layerBitmap->getBitmapImageAtFrame(currentFrame())->toThinBlackLine(layerBitmap->getBitmapImageAtFrame(currentFrame())); mScribbleArea->updateFrame(currentFrame()); } @@ -645,7 +644,7 @@ void Editor::toThinBlackLineRest() if (layerBitmap->keyExists(i)) { scrubTo(i); - layerBitmap->toThinBlackLine(currentFrame()); + layerBitmap->getBitmapImageAtFrame(currentFrame())->toThinBlackLine(layerBitmap->getBitmapImageAtFrame(currentFrame())); mObject->updateActiveFrames(currentFrame()); mScribbleArea->updateFrame(currentFrame()); } @@ -660,7 +659,7 @@ void Editor::replaceThinLines() if (layerBitmap->keyExists(i)) { scrubTo(i); - layerBitmap->replaceThinLine(currentFrame()); + layerBitmap->getBitmapImageAtFrame(currentFrame())->replaceThinLine(layerBitmap->getBitmapImageAtFrame(currentFrame())); mObject->updateActiveFrames(currentFrame()); mScribbleArea->updateFrame(currentFrame()); } diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index fbf52d6e4c..d374900631 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -53,8 +53,11 @@ void LayerBitmap::initColorLayer(Layer *fromLayer, LayerBitmap *colorlayer) int max = fromLayer->getMaxKeyFramePosition(); for (int i = 1; i <=max; i++) { - colorlayer->copyFrame(fromLayer, colorlayer, i); - toBlackLine(i); + if (fromLayer->keyExists(i)) + { + colorlayer->copyFrame(fromLayer, colorlayer, i); + colorlayer->getBitmapImageAtFrame(i)->toBlackLine(colorlayer->getBitmapImageAtFrame(i)); + } } } @@ -64,372 +67,8 @@ void LayerBitmap::singleInitColorLayer(Layer *fromLayer, LayerBitmap *colorlayer if (fromLayer->keyExists(frame)) { colorlayer->copyFrame(fromLayer, colorlayer, frame); - toBlackLine(frame); - } -} - -BitmapImage* LayerBitmap::scanToTransparent(int frame) -{ - if (!keyExists(frame)) { return nullptr; } - - BitmapImage* img = static_cast(getKeyFrameAt(frame)); - img->enableAutoCrop(true); - img->autoCrop(); - QRgb rgba; - for (int x = img->left(); x <= img->right(); x++) - { - for (int y = img->top(); y <= img->bottom(); y++) - { - rgba = img->pixel(x, y); - if (qGray(rgba) >= mThreshold) - { - img->setPixel(x, y, transp); - } - else if(qGray(rgba) >= mLowThreshold && qGray(rgba) < mThreshold) - { - qreal factor = qreal(mThreshold - qGray(rgba)) / qreal(mThreshold - mLowThreshold); - int alpha = static_cast(255 * factor); - QRgb tmp = qRgba(0, 0, 0, alpha); - img->setPixel(x , y, tmp); - } - } - } - getKeyFrameAt(frame)->modification(); - return img; -} - -void LayerBitmap::toBlackLine(int frame) -{ - if (!keyExists(frame)) { return; } - - BitmapImage* img = static_cast(getKeyFrameAt(frame)); - for (int x = img->left(); x <= img->right(); x++) - { - for (int y = img->top(); y <= img->bottom(); y++) - { - if (qAlpha(img->pixel(x, y)) > 0) - img->setPixel(x, y, thinline); - } - } - getKeyFrameAt(frame)->modification(); -} - -void LayerBitmap::fillWhiteAreas(int frame) -{ - if (!keyExists(frame)) { return; } - - BitmapImage* img = static_cast(getKeyFrameAt(frame)); - - // fill areas size 'area' or less with black - QVector points; - points.clear(); - for (int x = img->left(); x < img->right(); x++) - { - for (int y = img->top(); y < img->bottom(); y++) - { - if (qAlpha(img->pixel(x, y)) < 1) - { - points.append(QPoint(x, y)); - int areaSize = fillWithColor(QPoint(x, y), transp, rosa, frame); - if (areaSize <= mWhiteArea) - { // replace rosa with thinline (black) - fillWithColor(points.last(), rosa, thinline, frame); - points.removeLast(); - } - } - } - } - // replace rosa with trans - while (!points.isEmpty()) { - fillWithColor(points[0], rosa, transp, frame); - points.removeFirst(); - } - getKeyFrameAt(frame)->modification(); -} - -void LayerBitmap::toThinBlackLine(int frame) -{ - if (!keyExists(frame)) { return; } - BitmapImage* img = static_cast(getKeyFrameAt(frame)); - bool N = true, E = true, S = true, W = true, black, search; - - while (N || E || S || W) - { - if (N) // from NORTH - { - // set 'black' to false. 'black' is set to true whenever a black pixel is removed - black = false; - // 'search' is true while pixels are transparent - // when thinline pixel is found, 'search' is set to false until next transparent pixel - search = true; - for (int x = img->left(); x < img->right(); x++) - { - for (int y = img->top(); y < img->bottom(); y++) - { - if (search) - { - if (qAlpha(img->pixel(x,y)) > 0) - { - search = false; - if (qAlpha(img->pixel(x,y+1)) > 0) - { - if ((qAlpha(img->pixel(x-1,y-1)) == 0 && qAlpha(img->pixel(x+1,y-1)) == 0) && - (qAlpha(img->pixel(x+1, y)) > 0 || qAlpha(img->pixel(x-1, y)) >0 || - qAlpha(img->pixel(x+1, y+1)) > 0 || qAlpha(img->pixel(x-1, y+1)) >0)) - { - img->setPixel(x, y, transp); - black = true; - } - else if ((qAlpha(img->pixel(x-1,y-1)) > 0 && qAlpha(img->pixel(x+1,y-1)) > 0) && - (qAlpha(img->pixel(x+1,y)) > 0 && qAlpha(img->pixel(x-1,y)) > 0)) - { - img->setPixel(x, y, transp); - black = true; - } - else if ((qAlpha(img->pixel(x-1,y-1)) > 0 && qAlpha(img->pixel(x-1,y)) > 0) || - (qAlpha(img->pixel(x+1,y-1)) > 0 && qAlpha(img->pixel(x+1,y)) > 0)) - { - img->setPixel(x, y, transp); - black = true; - } - } - } - } - else - { - if (qAlpha(img->pixel(x,y)) == 0) - search = true; - } - } - } - N = black; // if none 'black' is removed, N = false - } - if (E) // from EAST - { - black = false; - search = true; - for (int y = img->top(); y < img->bottom(); y++) - { - for (int x = img->right(); x > img->left(); x--) - { - if (search) - { - if (qAlpha(img->pixel(x,y)) > 0) - { - search = false; - if (qAlpha(img->pixel(x-1,y)) > 0) - { - if ((qAlpha(img->pixel(x+1,y-1)) == 0 && qAlpha(img->pixel(x+1,y+1)) == 0) && - (qAlpha(img->pixel(x,y-1)) > 0 || qAlpha(img->pixel(x,y+1)) >0 || - qAlpha(img->pixel(x-1,y-1)) > 0 || qAlpha(img->pixel(x-1,y+1)) >0)) - { - img->setPixel(x, y, transp); - black = true; - } - else if ((qAlpha(img->pixel(x+1,y+1)) > 0 && qAlpha(img->pixel(x+1,y-1)) > 0) && - (qAlpha(img->pixel(x,y+1)) > 0 && qAlpha(img->pixel(x,y-1)) > 0)) - { - img->setPixel(x, y, transp); - black = true; - } - else if ((qAlpha(img->pixel(x+1,y+1)) > 0 && qAlpha(img->pixel(x,y+1)) > 0) || - (qAlpha(img->pixel(x+1,y-1)) > 0 && qAlpha(img->pixel(x,y-1)) > 0)) - { - img->setPixel(x, y, transp); - black = true; - } - } - } - } - else - { - if (qAlpha(img->pixel(x,y)) == 0) - search = true; - } - } - } - E = black; // if none 'black' is removed, E = false - } - if (S) // from SOUTH - { - black = false; - search = true; - for (int x = img->left(); x < img->right(); x++) - { - for (int y = img->bottom(); y > img->top(); y--) - { - if (search) - { - if (qAlpha(img->pixel(x,y)) > 0) - { - search = false; - if (qAlpha(img->pixel(x,y-1)) > 0) - { - if ((qAlpha(img->pixel(x-1,y+1)) == 0 && qAlpha(img->pixel(x+1,y+1)) == 0) && - (qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x+1, y)) >0 || - qAlpha(img->pixel(x-1, y-1)) > 0 || qAlpha(img->pixel(x+1, y-1)) >0)) - { - img->setPixel(x, y, transp); - black = true; - } - else if ((qAlpha(img->pixel(x-1,y+1)) > 0 && qAlpha(img->pixel(x+1,y+1)) > 0) && - (qAlpha(img->pixel(x+1,y)) > 0 && qAlpha(img->pixel(x-1,y)) > 0)) - { - img->setPixel(x, y, transp); - black = true; - } - else if ((qAlpha(img->pixel(x-1,y+1)) > 0 && qAlpha(img->pixel(x-1,y)) > 0) || - (qAlpha(img->pixel(x+1,y+1)) > 0 && qAlpha(img->pixel(x+1,y)) > 0)) - { - img->setPixel(x, y, transp); - black = true; - } - } - } - } - else - { - if (qAlpha(img->pixel(x,y)) == 0) - search = true; - } - } - } - S = black; // if none 'black' is removed, S = false - } - if (W) // from WEST - { - black = false; - search = true; - for (int y = img->top(); y <= img->bottom(); y++) - { - for (int x = img->left(); x < img->right(); x++) - { - if (search) - { - if (qAlpha(img->pixel(x,y)) > 0) - { - search = false; - if (qAlpha(img->pixel(x+1,y)) > 0) - { - if ((qAlpha(img->pixel(x-1,y-1)) == 0 && qAlpha(img->pixel(x-1,y+1)) == 0) && - (qAlpha(img->pixel(x,y-1)) > 0 || qAlpha(img->pixel(x,y+1)) >0 || - qAlpha(img->pixel(x+1,y-1)) > 0 || qAlpha(img->pixel(x+1,y+1)) >0)) - { - img->setPixel(x, y, transp); - black = true; - } - else if ((qAlpha(img->pixel(x-1,y+1)) > 0 && qAlpha(img->pixel(x-1,y-1)) > 0) && - (qAlpha(img->pixel(x,y+1)) > 0 && qAlpha(img->pixel(x,y-1)) > 0)) - { - img->setPixel(x, y, transp); - black = true; - } - else if ((qAlpha(img->pixel(x-1,y+1)) > 0 && qAlpha(img->pixel(x,y+1)) > 0) || - (qAlpha(img->pixel(x-1,y-1)) > 0 && qAlpha(img->pixel(x,y-1)) > 0)) - { - img->setPixel(x, y, transp); - black = true; - } - } - } - } - else - { - if (qAlpha(img->pixel(x,y)) == 0) - search = true; - } - } - } - W = black; // if none 'black' is removed, W = false - } - } - getKeyFrameAt(frame)->modification(); -} - -void LayerBitmap::replaceThinLine(int frame) -{ - if (!keyExists(frame)) { return; } - BitmapImage* img = static_cast(getKeyFrameAt(frame)); - - int r, g, b, a; //red, green, blue, alpha - QList points; - for (int x = img->left(); x <= img->right(); x++) - { - for (int y = img->top(); y <= img->bottom(); y++) - { - points.clear(); - r=0; g=0; b=0; a=0; - if (img->pixel(x,y) == thinline) - { - if (img->pixel(x-1, y-1) != thinline) points.append(QPoint(x-1, y-1)); - if (img->pixel(x-1, y ) != thinline) points.append(QPoint(x-1, y )); - if (img->pixel(x-1, y+1) != thinline) points.append(QPoint(x-1, y+1)); - if (img->pixel(x , y-1) != thinline) points.append(QPoint(x , y-1)); - if (img->pixel(x , y+1) != thinline) points.append(QPoint(x , y+1)); - if (img->pixel(x+1, y-1) != thinline) points.append(QPoint(x+1, y-1)); - if (img->pixel(x+1, y ) != thinline) points.append(QPoint(x+1, y )); - if (img->pixel(x+1, y+1) != thinline) points.append(QPoint(x+1, y+1)); - for (int i = 0; i < points.size(); i++) - { - r += qPow(qRed(img->pixel(points.at(i))), 2); - g += qPow(qGreen(img->pixel(points.at(i))), 2); - b += qPow(qBlue(img->pixel(points.at(i))), 2); - a += qPow(qAlpha(img->pixel(points.at(i))), 2); - } - r = static_cast(sqrt(r/points.size())); - g = static_cast(sqrt(g/points.size())); - b = static_cast(sqrt(b/points.size())); - a = static_cast(sqrt(a/points.size())); - img->setPixel(x, y, qRgba(r, g, b, a)); - } - } - } - getKeyFrameAt(frame)->modification(); -} - -int LayerBitmap::fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, int frame) -{ - if (!keyExists(frame)) { return -1; } - BitmapImage* img = static_cast(getKeyFrameAt(frame)); - QList fillList; - fillList.clear(); - // fill first pixel - img->setPixel(point, newColor); - int pixels = 1; - fillList.append(point); - - QRect rect = img->bounds(); - while (!fillList.isEmpty()) - { - QPoint tmp = fillList.at(0); - if (rect.contains(QPoint(tmp.x() + 1, tmp.y())) && img->pixel(QPoint(tmp.x() + 1, tmp.y())) == orgColor) - { - img->setPixel(QPoint(tmp.x() + 1, tmp.y()), newColor); - fillList.append(QPoint(tmp.x() + 1, tmp.y())); - pixels++; - } - if (rect.contains(QPoint(tmp.x(), tmp.y() + 1)) && img->pixel(QPoint(tmp.x(), tmp.y() + 1)) == orgColor) - { - img->setPixel(QPoint(tmp.x(), tmp.y() + 1), newColor); - fillList.append(QPoint(tmp.x(), tmp.y() + 1)); - pixels++; - } - if (rect.contains(QPoint(tmp.x() - 1, tmp.y())) && img->pixel(QPoint(tmp.x() - 1, tmp.y())) == orgColor) - { - img->setPixel(QPoint(tmp.x() - 1, tmp.y()), newColor); - fillList.append(QPoint(tmp.x() - 1, tmp.y())); - pixels++; - } - if (rect.contains(QPoint(tmp.x(), tmp.y() - 1)) && img->pixel(QPoint(tmp.x(), tmp.y() - 1)) == orgColor) - { - img->setPixel(QPoint(tmp.x(), tmp.y() - 1), newColor); - fillList.append(QPoint(tmp.x(), tmp.y() - 1)); - pixels++; - } - fillList.removeFirst(); + colorlayer->getBitmapImageAtFrame(frame)->toBlackLine(colorlayer->getBitmapImageAtFrame(frame)); } - getKeyFrameAt(frame)->modification(); - return pixels; } void LayerBitmap::loadImageAtFrame(QString path, QPoint topLeft, int frameNumber) diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index bf6222c1ac..8c01678b17 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -27,9 +27,6 @@ class LayerBitmap : public Layer Q_OBJECT public: - const QRgb transp = qRgba(0, 0, 0, 0); - const QRgb thinline = qRgba(1, 0, 0, 255); - const QRgb rosa = qRgba(255,230,230,255); LayerBitmap(Object* object); ~LayerBitmap() override; @@ -41,22 +38,8 @@ class LayerBitmap : public Layer BitmapImage* getBitmapImageAtFrame(int frameNumber); BitmapImage* getLastBitmapImageAtFrame(int frameNumber, int increment = 0); - // color layer methods void initColorLayer(Layer* fromLayer, LayerBitmap* colorlayer); void singleInitColorLayer(Layer* fromLayer, LayerBitmap* colorlayer, int frame); - int getThreshold() { return mThreshold; } - void setThreshold(int threshold) { mThreshold = threshold; } - int getWhiteArea() { return mWhiteArea; } - void setWhiteArea(int whiteArea) { mWhiteArea = whiteArea; } - BitmapImage* scanToTransparent(int frame); - - void toBlackLine(int frame); - - void fillWhiteAreas(int frame); - void toThinBlackLine(int frame); - void replaceThinLine(int frame); - int fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, int frame); - // color layer methods end protected: Status saveKeyFrameFile(KeyFrame*, QString strPath) override; @@ -68,9 +51,6 @@ class LayerBitmap : public Layer QString fileName(KeyFrame* key) const; bool needSaveFrame(KeyFrame* key, const QString& strSavePath); - int mThreshold = 200; - const int mLowThreshold = 30; // threshold for images to be given transparency - int mWhiteArea = 6; }; #endif From eb7c4d1ace4d076b568e99fd0640f8f2249e329a Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 23 Feb 2019 23:42:00 +0100 Subject: [PATCH 032/100] Thinning and removing colored lines works --- app/src/actioncommands.cpp | 2 +- app/src/mainwindow2.cpp | 17 ++ app/ui/bitmapcoloringwidget.ui | 3 +- core_lib/src/graphics/bitmap/bitmapimage.cpp | 184 ++++++++++++------- core_lib/src/graphics/bitmap/bitmapimage.h | 8 +- core_lib/src/interface/editor.cpp | 48 +++-- core_lib/src/managers/layermanager.cpp | 26 +++ core_lib/src/managers/layermanager.h | 2 + core_lib/src/structure/layerbitmap.cpp | 24 --- core_lib/src/structure/layerbitmap.h | 3 - 10 files changed, 211 insertions(+), 106 deletions(-) diff --git a/app/src/actioncommands.cpp b/app/src/actioncommands.cpp index a222bc2332..5b1cf9868c 100644 --- a/app/src/actioncommands.cpp +++ b/app/src/actioncommands.cpp @@ -658,7 +658,7 @@ Status ActionCommands::addNewBitmapColorLayer() LayerBitmap* parentlayer = static_cast(mEditor->layers()->currentLayer()); parentlayer->setHasColorLayer(true); LayerBitmap* colorlayer = mEditor->layers()->createBitmapLayer(name); - parentlayer->initColorLayer(parentlayer, colorlayer); + mEditor->layers()->initColorLayer(parentlayer, colorlayer); colorlayer->setIsColorLayer(true); emit mEditor->layers()->currentLayerChanged(mEditor->layers()->currentLayerIndex()); } diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index 287acd652f..41ea24ff92 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -626,6 +626,23 @@ bool MainWindow2::openObject(QString strFilePath, bool checkForChanges) mColorPalette->refreshColorList(); mEditor->layers()->notifyAnimationLengthChanged(); + // identify color layers + for (int i = 1; i < mEditor->layers()->count(); i++) + { + Layer* color = mEditor->layers()->getLayer(i); + if (color->type() == Layer::BITMAP && color->name().endsWith("_C")) + { + QString tmp = color->name(); + tmp.chop(2); + Layer* org = mEditor->layers()->findLayerByName(tmp); + if (org != nullptr) + { + color->setIsColorLayer(true); + org->setHasColorLayer(true); + } + } + } + progress.setValue(progress.maximum()); updateSaveState(); diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index 90893ca44d..7d3ade47ce 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -354,7 +354,8 @@ - Replace ALL thin lines... + Replace ALL thin lines... +Remove colored lines... diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 9dd6995e36..5514861774 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -20,6 +20,7 @@ GNU General Public License for more details. #include #include #include +#include #include "util.h" BitmapImage::BitmapImage() @@ -655,7 +656,7 @@ void BitmapImage::setBounds(QRect rect) updateBounds(rect); } -BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage) +BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, bool green, bool blue) { Q_ASSERT(bitmapimage != nullptr); @@ -666,12 +667,36 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage) for (int x = img->left(); x <= img->right(); x++) { for (int y = img->top(); y <= img->bottom(); y++) - { - rgba = img->pixel(x, y); + { // IF Threshold or above + rgba = img->constScanLine(x, y); if (qGray(rgba) >= mThreshold) { img->setPixel(x, y, transp); - } + } // IF Red line + else if(qRed(rgba) - 50 > qGreen(rgba)) + { + if (red) + { + QRgb tmp = qRgba(254, 0, 0, 255); + img->setPixel(x, y, tmp); + } + else + { + img->setPixel(x, y, transp); + } + } // IF Blue line + else if(qBlue(rgba) - 50 > qRed(rgba)) + { + if (blue) + { + QRgb tmp = qRgba(0, 0, 254, 255); + img->setPixel(x, y, tmp); + } + else + { + img->setPixel(x, y, transp); + } + } // IF in graduation area else if(qGray(rgba) >= mLowThreshold && qGray(rgba) < mThreshold) { qreal factor = qreal(mThreshold - qGray(rgba)) / qreal(mThreshold - mLowThreshold); @@ -694,11 +719,11 @@ void BitmapImage::toBlackLine(BitmapImage* bitmapimage) { for (int y = img->top(); y <= img->bottom(); y++) { - if (qAlpha(img->pixel(x, y)) > 0) + if (qAlpha(img->constScanLine(x, y)) > 0) img->setPixel(x, y, thinline); } } - bitmapimage->modification(); + img->modification(); } void BitmapImage::fillWhiteAreas(BitmapImage *bitmapimage) @@ -731,14 +756,14 @@ void BitmapImage::fillWhiteAreas(BitmapImage *bitmapimage) fillWithColor(points[0], rosa, transp, bitmapimage); points.removeFirst(); } - bitmapimage->modification(); + img->modification(); } -void BitmapImage::toThinBlackLine(BitmapImage* bitmapimage) +void BitmapImage::toThinBlackLine(BitmapImage* colorImage) { - Q_ASSERT(bitmapimage != nullptr); + Q_ASSERT(colorImage != nullptr); - BitmapImage* img = bitmapimage; + BitmapImage* img = colorImage; bool N = true, E = true, S = true, W = true, black, search; while (N || E || S || W) @@ -756,26 +781,26 @@ void BitmapImage::toThinBlackLine(BitmapImage* bitmapimage) { if (search) { - if (qAlpha(img->pixel(x,y)) > 0) + if (qAlpha(img->constScanLine(x,y)) > 0) { search = false; - if (qAlpha(img->pixel(x,y+1)) > 0) + if (qAlpha(img->constScanLine(x,y+1)) > 0) { - if ((qAlpha(img->pixel(x-1,y-1)) == 0 && qAlpha(img->pixel(x+1,y-1)) == 0) && - (qAlpha(img->pixel(x+1, y)) > 0 || qAlpha(img->pixel(x-1, y)) >0 || - qAlpha(img->pixel(x+1, y+1)) > 0 || qAlpha(img->pixel(x-1, y+1)) >0)) + if ((qAlpha(img->constScanLine(x-1,y-1)) == 0 && qAlpha(img->constScanLine(x+1,y-1)) == 0) && + (qAlpha(img->constScanLine(x+1, y)) > 0 || qAlpha(img->constScanLine(x-1, y)) >0 || + qAlpha(img->constScanLine(x+1, y+1)) > 0 || qAlpha(img->constScanLine(x-1, y+1)) >0)) { img->setPixel(x, y, transp); black = true; } - else if ((qAlpha(img->pixel(x-1,y-1)) > 0 && qAlpha(img->pixel(x+1,y-1)) > 0) && - (qAlpha(img->pixel(x+1,y)) > 0 && qAlpha(img->pixel(x-1,y)) > 0)) + else if ((qAlpha(img->constScanLine(x-1,y-1)) > 0 && qAlpha(img->constScanLine(x+1,y-1)) > 0) && + (qAlpha(img->constScanLine(x+1,y)) > 0 && qAlpha(img->constScanLine(x-1,y)) > 0)) { img->setPixel(x, y, transp); black = true; } - else if ((qAlpha(img->pixel(x-1,y-1)) > 0 && qAlpha(img->pixel(x-1,y)) > 0) || - (qAlpha(img->pixel(x+1,y-1)) > 0 && qAlpha(img->pixel(x+1,y)) > 0)) + else if ((qAlpha(img->constScanLine(x-1,y-1)) > 0 && qAlpha(img->constScanLine(x-1,y)) > 0) || + (qAlpha(img->constScanLine(x+1,y-1)) > 0 && qAlpha(img->constScanLine(x+1,y)) > 0)) { img->setPixel(x, y, transp); black = true; @@ -785,7 +810,7 @@ void BitmapImage::toThinBlackLine(BitmapImage* bitmapimage) } else { - if (qAlpha(img->pixel(x,y)) == 0) + if (qAlpha(img->constScanLine(x,y)) == 0) search = true; } } @@ -802,26 +827,26 @@ void BitmapImage::toThinBlackLine(BitmapImage* bitmapimage) { if (search) { - if (qAlpha(img->pixel(x,y)) > 0) + if (qAlpha(img->constScanLine(x,y)) > 0) { search = false; - if (qAlpha(img->pixel(x-1,y)) > 0) + if (qAlpha(img->constScanLine(x-1,y)) > 0) { - if ((qAlpha(img->pixel(x+1,y-1)) == 0 && qAlpha(img->pixel(x+1,y+1)) == 0) && - (qAlpha(img->pixel(x,y-1)) > 0 || qAlpha(img->pixel(x,y+1)) >0 || - qAlpha(img->pixel(x-1,y-1)) > 0 || qAlpha(img->pixel(x-1,y+1)) >0)) + if ((qAlpha(img->constScanLine(x+1,y-1)) == 0 && qAlpha(img->constScanLine(x+1,y+1)) == 0) && + (qAlpha(img->constScanLine(x,y-1)) > 0 || qAlpha(img->constScanLine(x,y+1)) >0 || + qAlpha(img->constScanLine(x-1,y-1)) > 0 || qAlpha(img->constScanLine(x-1,y+1)) >0)) { img->setPixel(x, y, transp); black = true; } - else if ((qAlpha(img->pixel(x+1,y+1)) > 0 && qAlpha(img->pixel(x+1,y-1)) > 0) && - (qAlpha(img->pixel(x,y+1)) > 0 && qAlpha(img->pixel(x,y-1)) > 0)) + else if ((qAlpha(img->constScanLine(x+1,y+1)) > 0 && qAlpha(img->constScanLine(x+1,y-1)) > 0) && + (qAlpha(img->constScanLine(x,y+1)) > 0 && qAlpha(img->constScanLine(x,y-1)) > 0)) { img->setPixel(x, y, transp); black = true; } - else if ((qAlpha(img->pixel(x+1,y+1)) > 0 && qAlpha(img->pixel(x,y+1)) > 0) || - (qAlpha(img->pixel(x+1,y-1)) > 0 && qAlpha(img->pixel(x,y-1)) > 0)) + else if ((qAlpha(img->constScanLine(x+1,y+1)) > 0 && qAlpha(img->constScanLine(x,y+1)) > 0) || + (qAlpha(img->constScanLine(x+1,y-1)) > 0 && qAlpha(img->constScanLine(x,y-1)) > 0)) { img->setPixel(x, y, transp); black = true; @@ -831,7 +856,7 @@ void BitmapImage::toThinBlackLine(BitmapImage* bitmapimage) } else { - if (qAlpha(img->pixel(x,y)) == 0) + if (qAlpha(img->constScanLine(x,y)) == 0) search = true; } } @@ -848,26 +873,26 @@ void BitmapImage::toThinBlackLine(BitmapImage* bitmapimage) { if (search) { - if (qAlpha(img->pixel(x,y)) > 0) + if (qAlpha(img->constScanLine(x,y)) > 0) { search = false; - if (qAlpha(img->pixel(x,y-1)) > 0) + if (qAlpha(img->constScanLine(x,y-1)) > 0) { - if ((qAlpha(img->pixel(x-1,y+1)) == 0 && qAlpha(img->pixel(x+1,y+1)) == 0) && - (qAlpha(img->pixel(x-1, y)) > 0 || qAlpha(img->pixel(x+1, y)) >0 || - qAlpha(img->pixel(x-1, y-1)) > 0 || qAlpha(img->pixel(x+1, y-1)) >0)) + if ((qAlpha(img->constScanLine(x-1,y+1)) == 0 && qAlpha(img->constScanLine(x+1,y+1)) == 0) && + (qAlpha(img->constScanLine(x-1, y)) > 0 || qAlpha(img->constScanLine(x+1, y)) >0 || + qAlpha(img->constScanLine(x-1, y-1)) > 0 || qAlpha(img->constScanLine(x+1, y-1)) >0)) { img->setPixel(x, y, transp); black = true; } - else if ((qAlpha(img->pixel(x-1,y+1)) > 0 && qAlpha(img->pixel(x+1,y+1)) > 0) && - (qAlpha(img->pixel(x+1,y)) > 0 && qAlpha(img->pixel(x-1,y)) > 0)) + else if ((qAlpha(img->constScanLine(x-1,y+1)) > 0 && qAlpha(img->constScanLine(x+1,y+1)) > 0) && + (qAlpha(img->constScanLine(x+1,y)) > 0 && qAlpha(img->constScanLine(x-1,y)) > 0)) { img->setPixel(x, y, transp); black = true; } - else if ((qAlpha(img->pixel(x-1,y+1)) > 0 && qAlpha(img->pixel(x-1,y)) > 0) || - (qAlpha(img->pixel(x+1,y+1)) > 0 && qAlpha(img->pixel(x+1,y)) > 0)) + else if ((qAlpha(img->constScanLine(x-1,y+1)) > 0 && qAlpha(img->constScanLine(x-1,y)) > 0) || + (qAlpha(img->constScanLine(x+1,y+1)) > 0 && qAlpha(img->constScanLine(x+1,y)) > 0)) { img->setPixel(x, y, transp); black = true; @@ -877,7 +902,7 @@ void BitmapImage::toThinBlackLine(BitmapImage* bitmapimage) } else { - if (qAlpha(img->pixel(x,y)) == 0) + if (qAlpha(img->constScanLine(x,y)) == 0) search = true; } } @@ -894,26 +919,26 @@ void BitmapImage::toThinBlackLine(BitmapImage* bitmapimage) { if (search) { - if (qAlpha(img->pixel(x,y)) > 0) + if (qAlpha(img->constScanLine(x,y)) > 0) { search = false; - if (qAlpha(img->pixel(x+1,y)) > 0) + if (qAlpha(img->constScanLine(x+1,y)) > 0) { - if ((qAlpha(img->pixel(x-1,y-1)) == 0 && qAlpha(img->pixel(x-1,y+1)) == 0) && - (qAlpha(img->pixel(x,y-1)) > 0 || qAlpha(img->pixel(x,y+1)) >0 || - qAlpha(img->pixel(x+1,y-1)) > 0 || qAlpha(img->pixel(x+1,y+1)) >0)) + if ((qAlpha(img->constScanLine(x-1,y-1)) == 0 && qAlpha(img->constScanLine(x-1,y+1)) == 0) && + (qAlpha(img->constScanLine(x,y-1)) > 0 || qAlpha(img->constScanLine(x,y+1)) >0 || + qAlpha(img->constScanLine(x+1,y-1)) > 0 || qAlpha(img->constScanLine(x+1,y+1)) >0)) { img->setPixel(x, y, transp); black = true; } - else if ((qAlpha(img->pixel(x-1,y+1)) > 0 && qAlpha(img->pixel(x-1,y-1)) > 0) && - (qAlpha(img->pixel(x,y+1)) > 0 && qAlpha(img->pixel(x,y-1)) > 0)) + else if ((qAlpha(img->constScanLine(x-1,y+1)) > 0 && qAlpha(img->constScanLine(x-1,y-1)) > 0) && + (qAlpha(img->constScanLine(x,y+1)) > 0 && qAlpha(img->constScanLine(x,y-1)) > 0)) { img->setPixel(x, y, transp); black = true; } - else if ((qAlpha(img->pixel(x-1,y+1)) > 0 && qAlpha(img->pixel(x,y+1)) > 0) || - (qAlpha(img->pixel(x-1,y-1)) > 0 && qAlpha(img->pixel(x,y-1)) > 0)) + else if ((qAlpha(img->constScanLine(x-1,y+1)) > 0 && qAlpha(img->constScanLine(x,y+1)) > 0) || + (qAlpha(img->constScanLine(x-1,y-1)) > 0 && qAlpha(img->constScanLine(x,y-1)) > 0)) { img->setPixel(x, y, transp); black = true; @@ -923,7 +948,7 @@ void BitmapImage::toThinBlackLine(BitmapImage* bitmapimage) } else { - if (qAlpha(img->pixel(x,y)) == 0) + if (qAlpha(img->constScanLine(x,y)) == 0) search = true; } } @@ -931,7 +956,24 @@ void BitmapImage::toThinBlackLine(BitmapImage* bitmapimage) W = black; // if none 'black' is removed, W = false } } - bitmapimage->modification(); + img->modification(); +} + +void BitmapImage::restoreColoredLines(BitmapImage *orgImage, BitmapImage *colorImage) +{ + qDebug() << "restore1" ; + Q_ASSERT(colorImage != nullptr); + qDebug() << "restore2" ; + + for (int x = colorImage->left(); x <= colorImage->right(); x++) + { + for (int y = colorImage->top(); y <= colorImage->bottom(); y++) + { + if (colorImage->constScanLine(x, y) == thinline) + if (orgImage->constScanLine(x,y) == qRgba(254,0,0,255) || orgImage->constScanLine(x,y) == qRgba(0,0,254,255)) + colorImage->setPixel(x, y, orgImage->constScanLine(x, y)); + } + } } void BitmapImage::replaceThinLine(BitmapImage *bitmapimage) @@ -942,22 +984,24 @@ void BitmapImage::replaceThinLine(BitmapImage *bitmapimage) int r, g, b, a; //red, green, blue, alpha QList points; + QList rgblist; + rgblist << thinline << redline << blueline; for (int x = img->left(); x <= img->right(); x++) { for (int y = img->top(); y <= img->bottom(); y++) { points.clear(); r=0; g=0; b=0; a=0; - if (img->pixel(x,y) == thinline) + if (rgblist.contains(img->pixel(x,y))) { - if (img->pixel(x-1, y-1) != thinline) points.append(QPoint(x-1, y-1)); - if (img->pixel(x-1, y ) != thinline) points.append(QPoint(x-1, y )); - if (img->pixel(x-1, y+1) != thinline) points.append(QPoint(x-1, y+1)); - if (img->pixel(x , y-1) != thinline) points.append(QPoint(x , y-1)); - if (img->pixel(x , y+1) != thinline) points.append(QPoint(x , y+1)); - if (img->pixel(x+1, y-1) != thinline) points.append(QPoint(x+1, y-1)); - if (img->pixel(x+1, y ) != thinline) points.append(QPoint(x+1, y )); - if (img->pixel(x+1, y+1) != thinline) points.append(QPoint(x+1, y+1)); + if (!rgblist.contains(img->pixel(x-1, y-1))) points.append(QPoint(x-1, y-1)); + if (!rgblist.contains(img->pixel(x-1, y ))) points.append(QPoint(x-1, y )); + if (!rgblist.contains(img->pixel(x-1, y+1))) points.append(QPoint(x-1, y+1)); + if (!rgblist.contains(img->pixel(x , y-1))) points.append(QPoint(x , y-1)); + if (!rgblist.contains(img->pixel(x , y+1))) points.append(QPoint(x , y+1)); + if (!rgblist.contains(img->pixel(x+1, y-1))) points.append(QPoint(x+1, y-1)); + if (!rgblist.contains(img->pixel(x+1, y ))) points.append(QPoint(x+1, y )); + if (!rgblist.contains(img->pixel(x+1, y+1))) points.append(QPoint(x+1, y+1)); for (int i = 0; i < points.size(); i++) { r += qPow(qRed(img->pixel(points.at(i))), 2); @@ -973,7 +1017,23 @@ void BitmapImage::replaceThinLine(BitmapImage *bitmapimage) } } } - bitmapimage->modification(); + img->modification(); +} + +void BitmapImage::removeColoredLines(BitmapImage *bitmapimage) +{ + Q_ASSERT(bitmapimage != nullptr); + + BitmapImage* img = bitmapimage; + for (int x = img->left(); x <= img->right(); x++) + { + for (int y = img->top(); y <= img->bottom(); y++) + { + if (qRed(img->constScanLine(x, y)) == 254 || qBlue(img->constScanLine(x,y)) == 254) + img->setPixel(x, y, transp); + } + } + img->modification(); } int BitmapImage::fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, BitmapImage *bitmapimage) @@ -1018,7 +1078,7 @@ int BitmapImage::fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, Bitma } fillList.removeFirst(); } - bitmapimage->modification(); + img->modification(); return pixels; } diff --git a/core_lib/src/graphics/bitmap/bitmapimage.h b/core_lib/src/graphics/bitmap/bitmapimage.h index 4ea82d8bf6..325ce93d8e 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.h +++ b/core_lib/src/graphics/bitmap/bitmapimage.h @@ -31,6 +31,8 @@ class BitmapImage : public KeyFrame const QRgb transp = qRgba(0, 0, 0, 0); const QRgb thinline = qRgba(1, 0, 0, 255); const QRgb rosa = qRgba(255,230,230,255); + const QRgb redline = qRgba(254,0,0,255); + const QRgb blueline = qRgba(0,0,254,255); BitmapImage(); BitmapImage(const BitmapImage&); @@ -104,13 +106,15 @@ class BitmapImage : public KeyFrame // coloring methods int getThreshold() { return mThreshold; } int getWhiteArea() { return mWhiteArea; } - BitmapImage* scanToTransparent(BitmapImage* bitmapimage); + BitmapImage* scanToTransparent(BitmapImage* bitmapimage, bool red, bool green, bool blue); void toBlackLine(BitmapImage* bitmapimage); void fillWhiteAreas(BitmapImage* bitmapimage); - void toThinBlackLine(BitmapImage* bitmapimage); + void toThinBlackLine(BitmapImage* colorImage); + void restoreColoredLines(BitmapImage* orgImage, BitmapImage* colorImage); void replaceThinLine(BitmapImage* bitmapimage); + void removeColoredLines(BitmapImage* bitmapimage); int fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, BitmapImage* bitmapimage); // color layer methods end diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index febf54b3c2..4557c41459 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -592,7 +592,7 @@ void Editor::copyFromScan() void Editor::scanToTransparent() { BitmapImage* bitmapimage = static_cast(layers()->currentLayer()->getKeyFrameAt(currentFrame())); - bitmapimage = bitmapimage->scanToTransparent(bitmapimage); + bitmapimage = bitmapimage->scanToTransparent(bitmapimage,true,true,true); mScribbleArea->updateFrame(currentFrame()); } @@ -601,7 +601,7 @@ void Editor::toBlackLine() LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); LayerBitmap* toLayer = static_cast(layers()->findLayerByName(layerBitmap->name() + "_C")); mObject->updateActiveFrames(currentFrame()); - layerBitmap->singleInitColorLayer(layerBitmap, toLayer , currentFrame()); + layers()->initColorLayer(layerBitmap, toLayer , currentFrame()); mScribbleArea->updateFrame(currentFrame()); } @@ -630,21 +630,37 @@ void Editor::fillWhiteAreasRest() void Editor::toThinBlackLine() { - LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); + LayerBitmap* colorLayer = static_cast(layers()->currentLayer()); + QString tmp = colorLayer->name(); + tmp.chop(2); + LayerBitmap* orgLayer = static_cast(layers()->findLayerByName(tmp)); mObject->updateActiveFrames(currentFrame()); - layerBitmap->getBitmapImageAtFrame(currentFrame())->toThinBlackLine(layerBitmap->getBitmapImageAtFrame(currentFrame())); - mScribbleArea->updateFrame(currentFrame()); + if (colorLayer != nullptr) + { + colorLayer->getBitmapImageAtFrame(currentFrame())->toThinBlackLine(colorLayer->getBitmapImageAtFrame(currentFrame())); + qDebug() << "før restore..."; + orgLayer->getBitmapImageAtFrame(currentFrame())->restoreColoredLines(orgLayer->getBitmapImageAtFrame(currentFrame()), colorLayer->getBitmapImageAtFrame(currentFrame())); + qDebug() << "efter restore..."; + mScribbleArea->updateFrame(currentFrame()); + } } void Editor::toThinBlackLineRest() { - LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); - for (int i = 1; i <= layerBitmap->getMaxKeyFramePosition(); i++) + LayerBitmap* colorLayer = static_cast(layers()->currentLayer()); + QString tmp = colorLayer->name(); + tmp.chop(2); + LayerBitmap* orgLayer = static_cast(layers()->findLayerByName(tmp)); + mObject->updateActiveFrames(currentFrame()); + for (int i = 1; i <= colorLayer->getMaxKeyFramePosition(); i++) { - if (layerBitmap->keyExists(i)) + if (colorLayer->keyExists(i)) { scrubTo(i); - layerBitmap->getBitmapImageAtFrame(currentFrame())->toThinBlackLine(layerBitmap->getBitmapImageAtFrame(currentFrame())); + colorLayer->getBitmapImageAtFrame(currentFrame())->toThinBlackLine(colorLayer->getBitmapImageAtFrame(currentFrame())); + qDebug() << "før restore..."; + orgLayer->getBitmapImageAtFrame(currentFrame())->restoreColoredLines(orgLayer->getBitmapImageAtFrame(currentFrame()), colorLayer->getBitmapImageAtFrame(currentFrame())); + qDebug() << "efter restore..."; mObject->updateActiveFrames(currentFrame()); mScribbleArea->updateFrame(currentFrame()); } @@ -653,13 +669,19 @@ void Editor::toThinBlackLineRest() void Editor::replaceThinLines() { - LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); - for (int i = 1; i <= layerBitmap->getMaxKeyFramePosition(); i++) + LayerBitmap* colorBitmap = static_cast(layers()->currentLayer()); + QString tmp = colorBitmap->name(); + tmp.chop(2); + LayerBitmap* orgBitmap = static_cast(layers()->findLayerByName(tmp)); + for (int i = 1; i <= colorBitmap->getMaxKeyFramePosition(); i++) { - if (layerBitmap->keyExists(i)) + if (colorBitmap->keyExists(i) && orgBitmap->keyExists(i)) { scrubTo(i); - layerBitmap->getBitmapImageAtFrame(currentFrame())->replaceThinLine(layerBitmap->getBitmapImageAtFrame(currentFrame())); + colorBitmap->getBitmapImageAtFrame(currentFrame())->replaceThinLine(colorBitmap->getBitmapImageAtFrame(currentFrame())); + colorBitmap->setModified(currentFrame(),true); + orgBitmap->getBitmapImageAtFrame(currentFrame())->removeColoredLines(orgBitmap->getBitmapImageAtFrame(currentFrame())); + orgBitmap->setModified(currentFrame(), true); mObject->updateActiveFrames(currentFrame()); mScribbleArea->updateFrame(currentFrame()); } diff --git a/core_lib/src/managers/layermanager.cpp b/core_lib/src/managers/layermanager.cpp index ac3ea2782d..685967b9fb 100644 --- a/core_lib/src/managers/layermanager.cpp +++ b/core_lib/src/managers/layermanager.cpp @@ -19,6 +19,7 @@ GNU General Public License for more details. #include "object.h" #include "editor.h" +#include "bitmapimage.h" #include "layersound.h" #include "layerbitmap.h" @@ -184,6 +185,31 @@ LayerSound* LayerManager::createSoundLayer(const QString& strLayerName) return layer; } +void LayerManager::initColorLayer(Layer *fromLayer, LayerBitmap *colorlayer, int frame) +{ + Q_ASSERT(fromLayer != nullptr && colorlayer != nullptr); + if (frame == 0) + { // init color layer, all drawings + int max = fromLayer->getMaxKeyFramePosition(); + for (int i = 1; i <=max; i++) + { + if (fromLayer->keyExists(i)) + { + colorlayer->copyFrame(fromLayer, colorlayer, i); + colorlayer->getBitmapImageAtFrame(i)->toBlackLine(colorlayer->getBitmapImageAtFrame(i)); + } + } + } + else + { // single keyframe to color layer + if (fromLayer->keyExists(frame)) + { + colorlayer->copyFrame(fromLayer, colorlayer, frame); + colorlayer->getBitmapImageAtFrame(frame)->toBlackLine(colorlayer->getBitmapImageAtFrame(frame)); + } + } +} + int LayerManager::LastFrameAtFrame(int frameIndex) { Object* o = object(); diff --git a/core_lib/src/managers/layermanager.h b/core_lib/src/managers/layermanager.h index 886818536a..60a90f4328 100644 --- a/core_lib/src/managers/layermanager.h +++ b/core_lib/src/managers/layermanager.h @@ -61,6 +61,8 @@ class LayerManager : public BaseManager LayerCamera* createCameraLayer(const QString& strLayerName); LayerSound* createSoundLayer(const QString& strLayerName); + void initColorLayer(Layer* fromLayer, LayerBitmap* colorlayer, int frame = 0); + // KeyFrame Management int LastFrameAtFrame(int frameIndex); int firstKeyFrameIndex(); diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index d374900631..e9ceded9e8 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -47,30 +47,6 @@ BitmapImage* LayerBitmap::getLastBitmapImageAtFrame(int frameNumber, int increme return static_cast(getLastKeyFrameAtPosition(frameNumber + increment)); } -void LayerBitmap::initColorLayer(Layer *fromLayer, LayerBitmap *colorlayer) -{ - Q_ASSERT(fromLayer != nullptr && colorlayer != nullptr); - int max = fromLayer->getMaxKeyFramePosition(); - for (int i = 1; i <=max; i++) - { - if (fromLayer->keyExists(i)) - { - colorlayer->copyFrame(fromLayer, colorlayer, i); - colorlayer->getBitmapImageAtFrame(i)->toBlackLine(colorlayer->getBitmapImageAtFrame(i)); - } - } -} - -void LayerBitmap::singleInitColorLayer(Layer *fromLayer, LayerBitmap *colorlayer, int frame) -{ - Q_ASSERT(fromLayer != nullptr && colorlayer != nullptr); - if (fromLayer->keyExists(frame)) - { - colorlayer->copyFrame(fromLayer, colorlayer, frame); - colorlayer->getBitmapImageAtFrame(frame)->toBlackLine(colorlayer->getBitmapImageAtFrame(frame)); - } -} - void LayerBitmap::loadImageAtFrame(QString path, QPoint topLeft, int frameNumber) { BitmapImage* pKeyFrame = new BitmapImage(topLeft, path); diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index 8c01678b17..d90782bb3b 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -38,9 +38,6 @@ class LayerBitmap : public Layer BitmapImage* getBitmapImageAtFrame(int frameNumber); BitmapImage* getLastBitmapImageAtFrame(int frameNumber, int increment = 0); - void initColorLayer(Layer* fromLayer, LayerBitmap* colorlayer); - void singleInitColorLayer(Layer* fromLayer, LayerBitmap* colorlayer, int frame); - protected: Status saveKeyFrameFile(KeyFrame*, QString strPath) override; KeyFrame* createKeyFrame(int position, Object*) override; From 38dee80056eb89deb1bc67d5e6589be74b172761 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 24 Feb 2019 16:22:04 +0100 Subject: [PATCH 033/100] Adjusted colored line support --- core_lib/src/graphics/bitmap/bitmapimage.cpp | 10 ++++------ core_lib/src/graphics/bitmap/bitmapimage.h | 2 +- core_lib/src/interface/editor.cpp | 6 +----- core_lib/src/managers/layermanager.h | 1 + 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 5514861774..3e8b9c2f5d 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -656,7 +656,7 @@ void BitmapImage::setBounds(QRect rect) updateBounds(rect); } -BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, bool green, bool blue) +BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, bool blue) { Q_ASSERT(bitmapimage != nullptr); @@ -677,8 +677,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, { if (red) { - QRgb tmp = qRgba(254, 0, 0, 255); - img->setPixel(x, y, tmp); + img->setPixel(x, y, redline); } else { @@ -689,14 +688,13 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, { if (blue) { - QRgb tmp = qRgba(0, 0, 254, 255); - img->setPixel(x, y, tmp); + img->setPixel(x, y, blueline); } else { img->setPixel(x, y, transp); } - } // IF in graduation area + } // IF in grayscale graduation area else if(qGray(rgba) >= mLowThreshold && qGray(rgba) < mThreshold) { qreal factor = qreal(mThreshold - qGray(rgba)) / qreal(mThreshold - mLowThreshold); diff --git a/core_lib/src/graphics/bitmap/bitmapimage.h b/core_lib/src/graphics/bitmap/bitmapimage.h index 325ce93d8e..662a46f6f2 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.h +++ b/core_lib/src/graphics/bitmap/bitmapimage.h @@ -106,7 +106,7 @@ class BitmapImage : public KeyFrame // coloring methods int getThreshold() { return mThreshold; } int getWhiteArea() { return mWhiteArea; } - BitmapImage* scanToTransparent(BitmapImage* bitmapimage, bool red, bool green, bool blue); + BitmapImage* scanToTransparent(BitmapImage* bitmapimage, bool red, bool blue); void toBlackLine(BitmapImage* bitmapimage); diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 4557c41459..4547aca984 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -592,7 +592,7 @@ void Editor::copyFromScan() void Editor::scanToTransparent() { BitmapImage* bitmapimage = static_cast(layers()->currentLayer()->getKeyFrameAt(currentFrame())); - bitmapimage = bitmapimage->scanToTransparent(bitmapimage,true,true,true); + bitmapimage = bitmapimage->scanToTransparent(bitmapimage,true,true); mScribbleArea->updateFrame(currentFrame()); } @@ -638,9 +638,7 @@ void Editor::toThinBlackLine() if (colorLayer != nullptr) { colorLayer->getBitmapImageAtFrame(currentFrame())->toThinBlackLine(colorLayer->getBitmapImageAtFrame(currentFrame())); - qDebug() << "før restore..."; orgLayer->getBitmapImageAtFrame(currentFrame())->restoreColoredLines(orgLayer->getBitmapImageAtFrame(currentFrame()), colorLayer->getBitmapImageAtFrame(currentFrame())); - qDebug() << "efter restore..."; mScribbleArea->updateFrame(currentFrame()); } } @@ -658,9 +656,7 @@ void Editor::toThinBlackLineRest() { scrubTo(i); colorLayer->getBitmapImageAtFrame(currentFrame())->toThinBlackLine(colorLayer->getBitmapImageAtFrame(currentFrame())); - qDebug() << "før restore..."; orgLayer->getBitmapImageAtFrame(currentFrame())->restoreColoredLines(orgLayer->getBitmapImageAtFrame(currentFrame()), colorLayer->getBitmapImageAtFrame(currentFrame())); - qDebug() << "efter restore..."; mObject->updateActiveFrames(currentFrame()); mScribbleArea->updateFrame(currentFrame()); } diff --git a/core_lib/src/managers/layermanager.h b/core_lib/src/managers/layermanager.h index 60a90f4328..a48dceb252 100644 --- a/core_lib/src/managers/layermanager.h +++ b/core_lib/src/managers/layermanager.h @@ -61,6 +61,7 @@ class LayerManager : public BaseManager LayerCamera* createCameraLayer(const QString& strLayerName); LayerSound* createSoundLayer(const QString& strLayerName); + // color layer void initColorLayer(Layer* fromLayer, LayerBitmap* colorlayer, int frame = 0); // KeyFrame Management From de1e4a5edbdd0200e65cfebc8879b051405a5a04 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Mon, 25 Feb 2019 11:48:37 +0100 Subject: [PATCH 034/100] Added support for green lines for shadowing --- core_lib/src/graphics/bitmap/bitmapimage.cpp | 32 +++++++++++++++----- core_lib/src/graphics/bitmap/bitmapimage.h | 4 ++- core_lib/src/interface/editor.cpp | 2 +- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 3e8b9c2f5d..86092eeb3d 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -656,7 +656,7 @@ void BitmapImage::setBounds(QRect rect) updateBounds(rect); } -BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, bool blue) +BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, bool green, bool blue) { Q_ASSERT(bitmapimage != nullptr); @@ -684,7 +684,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, img->setPixel(x, y, transp); } } // IF Blue line - else if(qBlue(rgba) - 50 > qRed(rgba)) + else if(qBlue(rgba) - 50 > qRed(rgba) && qBlue(rgba) > qGreen(rgba)) { if (blue) { @@ -694,6 +694,17 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, { img->setPixel(x, y, transp); } + } // IF Green line + else if(qGreen(rgba) - 50 > qRed(rgba)) + { + if (green) + { + img->setPixel(x, y, greenline); + } + else + { + img->setPixel(x, y, transp); + } } // IF in grayscale graduation area else if(qGray(rgba) >= mLowThreshold && qGray(rgba) < mThreshold) { @@ -708,6 +719,11 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, return img; } +void BitmapImage::getThresholdSuggestion(BitmapImage* img) +{ + Q_ASSERT(img != nullptr); +} + void BitmapImage::toBlackLine(BitmapImage* bitmapimage) { Q_ASSERT(bitmapimage != nullptr); @@ -980,10 +996,10 @@ void BitmapImage::replaceThinLine(BitmapImage *bitmapimage) BitmapImage* img = bitmapimage; - int r, g, b, a; //red, green, blue, alpha - QList points; - QList rgblist; - rgblist << thinline << redline << blueline; + int r, g, b, a; //red, green, blue, alpha + QList points; // QPoints to add in calculation + QList rgblist; // QRgb's that should be excluded + rgblist << thinline << redline << greenline << blueline; for (int x = img->left(); x <= img->right(); x++) { for (int y = img->top(); y <= img->bottom(); y++) @@ -1027,7 +1043,9 @@ void BitmapImage::removeColoredLines(BitmapImage *bitmapimage) { for (int y = img->top(); y <= img->bottom(); y++) { - if (qRed(img->constScanLine(x, y)) == 254 || qBlue(img->constScanLine(x,y)) == 254) + if (qRed(img->constScanLine(x, y)) == 254 || + qBlue(img->constScanLine(x,y)) == 254 || + qGreen(img->constScanLine(x, y) == 254)) img->setPixel(x, y, transp); } } diff --git a/core_lib/src/graphics/bitmap/bitmapimage.h b/core_lib/src/graphics/bitmap/bitmapimage.h index 662a46f6f2..54c78ee959 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.h +++ b/core_lib/src/graphics/bitmap/bitmapimage.h @@ -32,6 +32,7 @@ class BitmapImage : public KeyFrame const QRgb thinline = qRgba(1, 0, 0, 255); const QRgb rosa = qRgba(255,230,230,255); const QRgb redline = qRgba(254,0,0,255); + const QRgb greenline = qRgba(0,254,0,255); const QRgb blueline = qRgba(0,0,254,255); BitmapImage(); @@ -106,8 +107,9 @@ class BitmapImage : public KeyFrame // coloring methods int getThreshold() { return mThreshold; } int getWhiteArea() { return mWhiteArea; } - BitmapImage* scanToTransparent(BitmapImage* bitmapimage, bool red, bool blue); + BitmapImage* scanToTransparent(BitmapImage* bitmapimage, bool red, bool green, bool blue); + void getThresholdSuggestion(BitmapImage* img); void toBlackLine(BitmapImage* bitmapimage); void fillWhiteAreas(BitmapImage* bitmapimage); diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 4547aca984..65c04b9504 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -592,7 +592,7 @@ void Editor::copyFromScan() void Editor::scanToTransparent() { BitmapImage* bitmapimage = static_cast(layers()->currentLayer()->getKeyFrameAt(currentFrame())); - bitmapimage = bitmapimage->scanToTransparent(bitmapimage,true,true); + bitmapimage = bitmapimage->scanToTransparent(bitmapimage,true,true,true); mScribbleArea->updateFrame(currentFrame()); } From fbc553cbe238bccc18b154b54259918c679c0b48 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Mon, 25 Feb 2019 21:50:57 +0100 Subject: [PATCH 035/100] Support for green colored lines --- core_lib/src/graphics/bitmap/bitmapimage.cpp | 32 +++++++++++++------- core_lib/src/graphics/bitmap/bitmapimage.h | 5 +-- core_lib/src/interface/editor.cpp | 2 +- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 3e8b9c2f5d..bfd2a0bb7d 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -644,7 +644,7 @@ void BitmapImage::drawPath(QPainterPath path, QPen pen, QBrush brush, else { // forces drawing when points are coincident (mousedown) - painter.drawPoint(path.elementAt(0).x, path.elementAt(0).y); + painter.drawPoint(static_cast(path.elementAt(0).x), static_cast(path.elementAt(0).y)); } painter.end(); } @@ -656,7 +656,7 @@ void BitmapImage::setBounds(QRect rect) updateBounds(rect); } -BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, bool blue) +BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, bool green, bool blue) { Q_ASSERT(bitmapimage != nullptr); @@ -684,7 +684,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, img->setPixel(x, y, transp); } } // IF Blue line - else if(qBlue(rgba) - 50 > qRed(rgba)) + else if(qBlue(rgba) - 50 > qRed(rgba) && qBlue(rgba) > qGreen(rgba)) { if (blue) { @@ -694,6 +694,17 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, { img->setPixel(x, y, transp); } + } // IF Green line + else if(qGreen(rgba) - 50 > qRed(rgba) && qGreen(rgba) > qBlue(rgba)) + { + if (green) + { + img->setPixel(x, y, greenline); + } + else + { + img->setPixel(x, y, transp); + } } // IF in grayscale graduation area else if(qGray(rgba) >= mLowThreshold && qGray(rgba) < mThreshold) { @@ -959,16 +970,15 @@ void BitmapImage::toThinBlackLine(BitmapImage* colorImage) void BitmapImage::restoreColoredLines(BitmapImage *orgImage, BitmapImage *colorImage) { - qDebug() << "restore1" ; Q_ASSERT(colorImage != nullptr); - qDebug() << "restore2" ; for (int x = colorImage->left(); x <= colorImage->right(); x++) { for (int y = colorImage->top(); y <= colorImage->bottom(); y++) { if (colorImage->constScanLine(x, y) == thinline) - if (orgImage->constScanLine(x,y) == qRgba(254,0,0,255) || orgImage->constScanLine(x,y) == qRgba(0,0,254,255)) + if (orgImage->constScanLine(x,y) == redline || + orgImage->constScanLine(x,y) == blueline || orgImage->constScanLine(x,y) == greenline) colorImage->setPixel(x, y, orgImage->constScanLine(x, y)); } } @@ -1173,12 +1183,12 @@ bool BitmapImage::compareColor(QRgb newColor, QRgb oldColor, int tolerance, QHas // Get Eulcidian distance between colors // Not an accurate representation of human perception, // but it's the best any image editing program ever does - int diffRed = qPow(qRed(oldColor) - qRed(newColor), 2); - int diffGreen = qPow(qGreen(oldColor) - qGreen(newColor), 2); - int diffBlue = qPow(qBlue(oldColor) - qBlue(newColor), 2); + int diffRed = static_cast(qPow(qRed(oldColor) - qRed(newColor), 2)); + int diffGreen = static_cast(qPow(qGreen(oldColor) - qGreen(newColor), 2)); + int diffBlue = static_cast(qPow(qBlue(oldColor) - qBlue(newColor), 2)); // This may not be the best way to handle alpha since the other channels become less relevant as // the alpha is reduces (ex. QColor(0,0,0,0) is the same as QColor(255,255,255,0)) - int diffAlpha = qPow(qAlpha(oldColor) - qAlpha(newColor), 2); + int diffAlpha = static_cast(qPow(qAlpha(oldColor) - qAlpha(newColor), 2)); bool isSimilar = (diffRed + diffGreen + diffBlue + diffAlpha) <= tolerance; @@ -1206,7 +1216,7 @@ void BitmapImage::floodFill(BitmapImage* targetImage, } // Square tolerance for use with compareColor - tolerance = qPow(tolerance, 2); + tolerance = static_cast(qPow(tolerance, 2)); QRgb oldColor = targetImage->pixel(point); oldColor = qRgba(qRed(oldColor), qGreen(oldColor), qBlue(oldColor), qAlpha(oldColor)); diff --git a/core_lib/src/graphics/bitmap/bitmapimage.h b/core_lib/src/graphics/bitmap/bitmapimage.h index 662a46f6f2..d603765c02 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.h +++ b/core_lib/src/graphics/bitmap/bitmapimage.h @@ -32,6 +32,7 @@ class BitmapImage : public KeyFrame const QRgb thinline = qRgba(1, 0, 0, 255); const QRgb rosa = qRgba(255,230,230,255); const QRgb redline = qRgba(254,0,0,255); + const QRgb greenline = qRgba(0,254,0,255); const QRgb blueline = qRgba(0,0,254,255); BitmapImage(); @@ -106,7 +107,7 @@ class BitmapImage : public KeyFrame // coloring methods int getThreshold() { return mThreshold; } int getWhiteArea() { return mWhiteArea; } - BitmapImage* scanToTransparent(BitmapImage* bitmapimage, bool red, bool blue); + BitmapImage* scanToTransparent(BitmapImage* bitmapimage, bool red, bool green, bool blue); void toBlackLine(BitmapImage* bitmapimage); @@ -116,7 +117,7 @@ class BitmapImage : public KeyFrame void replaceThinLine(BitmapImage* bitmapimage); void removeColoredLines(BitmapImage* bitmapimage); int fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, BitmapImage* bitmapimage); - // color layer methods end + // coloring methods end /** Determines if the BitmapImage is minimally bounded. diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 4547aca984..76a348e9f0 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -592,7 +592,7 @@ void Editor::copyFromScan() void Editor::scanToTransparent() { BitmapImage* bitmapimage = static_cast(layers()->currentLayer()->getKeyFrameAt(currentFrame())); - bitmapimage = bitmapimage->scanToTransparent(bitmapimage,true,true); + bitmapimage = bitmapimage->scanToTransparent(bitmapimage,true, true, true); // TODO mScribbleArea->updateFrame(currentFrame()); } From 5fbbc788c13733631c768a684b6f5e5262ac803c Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Wed, 27 Feb 2019 17:26:24 +0100 Subject: [PATCH 036/100] Optimizing fillWhiteAreas --- app/src/bitmapcoloring.cpp | 4 +-- core_lib/src/graphics/bitmap/bitmapimage.cpp | 33 ++++++++++++++------ core_lib/src/interface/editor.cpp | 1 + 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 3174d967c4..d670c57be4 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -37,10 +37,10 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : connect(ui->btn1Select, &QPushButton::clicked, mEditor, &Editor::copyFromScan); connect(ui->btn1Next, &QPushButton::clicked, mEditor, &Editor::scrubNextKeyFrame); -// connect(ui->sb1_Threshold, QOverload(&QSpinBox::valueChanged), mBitmapImage, &BitmapImage::setThreshold); +// connect(ui->sb1_Threshold, static_cast(&QSpinBox::valueChanged) , mBitmapImage, &BitmapImage::setThreshold); connect(ui->btnx_blackLine, &QPushButton::clicked, mEditor, &Editor::toBlackLine); -// connect(ui->sb2_fillArea, SIGNAL(valueChanged(int)), mBitmapImage, SLOT(setWhiteArea(int))); +// connect(ui->sb2_fillArea, QOverload::of(&QSpinBox::valueChanged) , mBitmapImage, &BitmapImage::setWhiteArea); connect(ui->btn2_fillRest, &QPushButton::clicked, mEditor, &Editor::fillWhiteAreasRest); connect(ui->btn2_repairs, &QPushButton::clicked, mEditor, &Editor::fillWhiteAreas); connect(ui->btn3_thinRest, &QPushButton::clicked, mEditor, &Editor::toThinBlackLineRest); diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 3ec39b0a35..6a60de4e1f 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -721,7 +721,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, void BitmapImage::getThresholdSuggestion(BitmapImage* img) { - Q_ASSERT(img != nullptr); + Q_ASSERT(img != nullptr); // TODO } void BitmapImage::toBlackLine(BitmapImage* bitmapimage) @@ -729,12 +729,23 @@ void BitmapImage::toBlackLine(BitmapImage* bitmapimage) Q_ASSERT(bitmapimage != nullptr); BitmapImage* img = bitmapimage; + QRgb rgba; for (int x = img->left(); x <= img->right(); x++) { for (int y = img->top(); y <= img->bottom(); y++) { + rgba = img->constScanLine(x, y); if (qAlpha(img->constScanLine(x, y)) > 0) - img->setPixel(x, y, thinline); + { + if(qRed(rgba) - 50 > qGreen(rgba)) + img->setPixel(x, y, redline); + else if(qBlue(rgba) - 50 > qRed(rgba) && qBlue(rgba) > qGreen(rgba)) + img->setPixel(x, y, blueline); + else if(qGreen(rgba) - 50 > qRed(rgba) && qGreen(rgba) > qBlue(rgba)) + img->setPixel(x, y, greenline); + else + img->setPixel(x, y, thinline); + } } } img->modification(); @@ -743,26 +754,28 @@ void BitmapImage::toBlackLine(BitmapImage* bitmapimage) void BitmapImage::fillWhiteAreas(BitmapImage *bitmapimage) { Q_ASSERT(bitmapimage != nullptr); - - BitmapImage* img = bitmapimage; +// BitmapImage* img = bitmapimage; // fill areas size 'area' or less with black QVector points; points.clear(); - for (int x = img->left(); x < img->right(); x++) + QRgb active, previous = thinline; + for (int x = bitmapimage->left(); x < bitmapimage->right(); x++) { - for (int y = img->top(); y < img->bottom(); y++) + for (int y = bitmapimage->top(); y < bitmapimage->bottom(); y++) { - if (qAlpha(img->pixel(x, y)) < 1) + active =bitmapimage->constScanLine(x, y); + if (qAlpha(active) < 1) { points.append(QPoint(x, y)); int areaSize = fillWithColor(QPoint(x, y), transp, rosa, bitmapimage); if (areaSize <= mWhiteArea) - { // replace rosa with thinline (black) - fillWithColor(points.last(), rosa, thinline, bitmapimage); + { // replace rosa with last color + fillWithColor(points.last(), rosa, previous, bitmapimage); points.removeLast(); } } + previous = active; } } // replace rosa with trans @@ -770,7 +783,7 @@ void BitmapImage::fillWhiteAreas(BitmapImage *bitmapimage) fillWithColor(points[0], rosa, transp, bitmapimage); points.removeFirst(); } - img->modification(); + bitmapimage->modification(); } void BitmapImage::toThinBlackLine(BitmapImage* colorImage) diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 76a348e9f0..31fdeb066b 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -536,6 +536,7 @@ void Editor::paste() qDebug() << "to be pasted --->" << tobePasted.image()->offset(); if (mScribbleArea->isSomethingSelected()) { + mObject->updateActiveFrames(currentFrame()); QRectF selection = mScribbleArea->getSelection(); if (g_clipboardBitmapImage.width() <= selection.width() && g_clipboardBitmapImage.height() <= selection.height()) { From a7d280d18f925c1666d004e3cccbc5c61819b740 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Wed, 27 Feb 2019 22:18:39 +0100 Subject: [PATCH 037/100] Supports red, green and blue lines --- core_lib/src/graphics/bitmap/bitmapimage.cpp | 1 + core_lib/src/interface/editor.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 6a60de4e1f..010beeca88 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -715,6 +715,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, } } } + img->autoCrop(); img->modification(); return img; } diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 31fdeb066b..5b2042ab66 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -536,7 +536,6 @@ void Editor::paste() qDebug() << "to be pasted --->" << tobePasted.image()->offset(); if (mScribbleArea->isSomethingSelected()) { - mObject->updateActiveFrames(currentFrame()); QRectF selection = mScribbleArea->getSelection(); if (g_clipboardBitmapImage.width() <= selection.width() && g_clipboardBitmapImage.height() <= selection.height()) { @@ -640,6 +639,7 @@ void Editor::toThinBlackLine() { colorLayer->getBitmapImageAtFrame(currentFrame())->toThinBlackLine(colorLayer->getBitmapImageAtFrame(currentFrame())); orgLayer->getBitmapImageAtFrame(currentFrame())->restoreColoredLines(orgLayer->getBitmapImageAtFrame(currentFrame()), colorLayer->getBitmapImageAtFrame(currentFrame())); + mObject->updateActiveFrames(currentFrame()); mScribbleArea->updateFrame(currentFrame()); } } From 347548937b6eeda5977072b5152c5a6ecbe13340 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Thu, 28 Feb 2019 20:30:32 +0100 Subject: [PATCH 038/100] Coloring working with colored lines --- app/ui/bitmapcoloringwidget.ui | 109 +++++++++---------- core_lib/src/graphics/bitmap/bitmapimage.cpp | 23 ++-- core_lib/src/interface/editor.cpp | 6 +- 3 files changed, 67 insertions(+), 71 deletions(-) diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index 7d3ade47ce..ea61c2267f 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -241,62 +241,59 @@ 2 - - - - - - - Fill area: - - - - - - - px - - - 1 - - - 20 - - - 6 - - - - - - - - - Apply to ALL lines... - - - - - - - [Apply to Active...] - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - + + + + 9 + 41 + 127 + 23 + + + + Apply to ALL lines... + + + + + + 9 + 70 + 120 + 23 + + + + [Apply to Active...] + + + + + + + + Fill area: + + + + + + + px + + + 1 + + + 20 + + + 6 + + + + + diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 010beeca88..46b0aaa7e7 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -661,8 +661,8 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, Q_ASSERT(bitmapimage != nullptr); BitmapImage* img = bitmapimage; - img->enableAutoCrop(true); - img->autoCrop(); + img->enableAutoCrop(false); + QRgb rgba; for (int x = img->left(); x <= img->right(); x++) { @@ -715,7 +715,6 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, } } } - img->autoCrop(); img->modification(); return img; } @@ -754,25 +753,25 @@ void BitmapImage::toBlackLine(BitmapImage* bitmapimage) void BitmapImage::fillWhiteAreas(BitmapImage *bitmapimage) { - Q_ASSERT(bitmapimage != nullptr); -// BitmapImage* img = bitmapimage; + if(bitmapimage == nullptr) { return; } + BitmapImage* img = bitmapimage; // fill areas size 'area' or less with black QVector points; points.clear(); QRgb active, previous = thinline; - for (int x = bitmapimage->left(); x < bitmapimage->right(); x++) + for (int x = img->left(); x < img->right(); x++) { - for (int y = bitmapimage->top(); y < bitmapimage->bottom(); y++) + for (int y = img->top(); y < img->bottom(); y++) { - active =bitmapimage->constScanLine(x, y); + active =img->pixel(x, y); if (qAlpha(active) < 1) { points.append(QPoint(x, y)); - int areaSize = fillWithColor(QPoint(x, y), transp, rosa, bitmapimage); + int areaSize = fillWithColor(QPoint(x, y), transp, rosa, img); if (areaSize <= mWhiteArea) { // replace rosa with last color - fillWithColor(points.last(), rosa, previous, bitmapimage); + fillWithColor(points.last(), rosa, previous, img); points.removeLast(); } } @@ -781,10 +780,10 @@ void BitmapImage::fillWhiteAreas(BitmapImage *bitmapimage) } // replace rosa with trans while (!points.isEmpty()) { - fillWithColor(points[0], rosa, transp, bitmapimage); + fillWithColor(points[0], rosa, transp, img); points.removeFirst(); } - bitmapimage->modification(); + img->modification(); } void BitmapImage::toThinBlackLine(BitmapImage* colorImage) diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 5b2042ab66..85c261d7c8 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -621,9 +621,9 @@ void Editor::fillWhiteAreasRest() if (layerBitmap->keyExists(i)) { scrubTo(i); - layerBitmap->getBitmapImageAtFrame(currentFrame())->fillWhiteAreas(layerBitmap->getBitmapImageAtFrame(currentFrame())); - mObject->updateActiveFrames(currentFrame()); - mScribbleArea->updateFrame(currentFrame()); + layerBitmap->getBitmapImageAtFrame(i)->fillWhiteAreas(layerBitmap->getBitmapImageAtFrame(i)); + mObject->updateActiveFrames(i); + mScribbleArea->updateFrame(i); } } } From 16cadf37cc42284e3e1e0785bde26fbcaed92a17 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Fri, 1 Mar 2019 21:32:14 +0100 Subject: [PATCH 039/100] Separated initColorLayer to two functions --- app/src/actioncommands.cpp | 3 +++ core_lib/src/interface/editor.cpp | 17 ++++++++++++++--- core_lib/src/managers/layermanager.cpp | 14 ++++++++++++++ core_lib/src/managers/layermanager.h | 1 + core_lib/src/structure/layer.cpp | 20 ++++++++++++++++++++ core_lib/src/structure/layer.h | 1 + 6 files changed, 53 insertions(+), 3 deletions(-) diff --git a/app/src/actioncommands.cpp b/app/src/actioncommands.cpp index 5b1cf9868c..bc8e768cde 100644 --- a/app/src/actioncommands.cpp +++ b/app/src/actioncommands.cpp @@ -652,6 +652,7 @@ Status ActionCommands::addNewSoundLayer() Status ActionCommands::addNewBitmapColorLayer() { + /* QString name = mEditor->layers()->currentLayer()->name() + "_C"; if (!name.isEmpty()) { @@ -662,6 +663,8 @@ Status ActionCommands::addNewBitmapColorLayer() colorlayer->setIsColorLayer(true); emit mEditor->layers()->currentLayerChanged(mEditor->layers()->currentLayerIndex()); } + */ + mEditor->toBlackLine(); return Status::OK; } diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 85c261d7c8..3901892ffa 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -598,10 +598,21 @@ void Editor::scanToTransparent() void Editor::toBlackLine() { - LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); - LayerBitmap* toLayer = static_cast(layers()->findLayerByName(layerBitmap->name() + "_C")); + LayerBitmap* orgLayer = static_cast(layers()->currentLayer()); + orgLayer->setHasColorLayer(true); + LayerBitmap* colorLayer = layers()->createBitmapLayer(orgLayer->name() + "_C"); + colorLayer->setIsColorLayer(true); + layers()->copyLayer(orgLayer, colorLayer); + orgLayer->copyFrames(orgLayer,colorLayer, 1, orgLayer->getMaxKeyFramePosition(), 1); mObject->updateActiveFrames(currentFrame()); - layers()->initColorLayer(layerBitmap, toLayer , currentFrame()); + for (int i = 1; i <= colorLayer->getMaxKeyFramePosition(); i++) + { + if (colorLayer->keyExists(i)) + { + scrubTo(i); + colorLayer->getBitmapImageAtFrame(i)->toBlackLine(colorLayer->getBitmapImageAtFrame(i)); + } + } mScribbleArea->updateFrame(currentFrame()); } diff --git a/core_lib/src/managers/layermanager.cpp b/core_lib/src/managers/layermanager.cpp index 685967b9fb..db4d855aca 100644 --- a/core_lib/src/managers/layermanager.cpp +++ b/core_lib/src/managers/layermanager.cpp @@ -185,6 +185,20 @@ LayerSound* LayerManager::createSoundLayer(const QString& strLayerName) return layer; } +Status LayerManager::copyLayer(Layer *fromLayer, Layer *toLayer) +{ + Q_ASSERT(fromLayer != nullptr && toLayer != nullptr); + int max = fromLayer->getMaxKeyFramePosition(); + for (int i = 1; i <=max; i++) + { + if (fromLayer->keyExists(i)) + { + toLayer->copyFrame(fromLayer, toLayer, i); + } + } + return Status::OK; +} + void LayerManager::initColorLayer(Layer *fromLayer, LayerBitmap *colorlayer, int frame) { Q_ASSERT(fromLayer != nullptr && colorlayer != nullptr); diff --git a/core_lib/src/managers/layermanager.h b/core_lib/src/managers/layermanager.h index a48dceb252..c841b6a836 100644 --- a/core_lib/src/managers/layermanager.h +++ b/core_lib/src/managers/layermanager.h @@ -62,6 +62,7 @@ class LayerManager : public BaseManager LayerSound* createSoundLayer(const QString& strLayerName); // color layer + Status copyLayer(Layer* fromLayer, Layer* toLayer); void initColorLayer(Layer* fromLayer, LayerBitmap* colorlayer, int frame = 0); // KeyFrame Management diff --git a/core_lib/src/structure/layer.cpp b/core_lib/src/structure/layer.cpp index ad00fabfd7..a3dffcf414 100644 --- a/core_lib/src/structure/layer.cpp +++ b/core_lib/src/structure/layer.cpp @@ -50,6 +50,26 @@ Layer::~Layer() mKeyFrames.clear(); } +void Layer::copyFrames(Layer *fromLayer, Layer *toLayer, int firstFrame, int lastFrame, int startAt, int loops) +{ + for (int i = 0; i < loops; i++) + { + for (int j = firstFrame; j <= lastFrame; j++, startAt++) + { + if (fromLayer->keyExists(j)) + { + mObject->updateActiveFrames(j); + KeyFrame* keyframe = fromLayer->getKeyFrameAt(j); + KeyFrame* dupKey = keyframe->clone(); + if (toLayer->keyExists(startAt)) + toLayer->removeKeyFrame(startAt); + toLayer->addKeyFrame(startAt, dupKey); + toLayer->setModified(startAt, true); + } + } + } +} + void Layer::foreachKeyFrame(std::function action) { for (auto pair : mKeyFrames) diff --git a/core_lib/src/structure/layer.h b/core_lib/src/structure/layer.h index 76ffadcb71..7273e7be8f 100644 --- a/core_lib/src/structure/layer.h +++ b/core_lib/src/structure/layer.h @@ -69,6 +69,7 @@ class Layer : public QObject bool getHasColorLayer() { return mHasColorLayer; } void setIsColorLayer(bool b) { mIsColorLayer = b; } bool getIsColorLayer() { return mIsColorLayer; } + void copyFrames(Layer* fromLayer, Layer* toLayer, int firstFrame, int lastFrame, int startAt, int loops = 1); virtual Status saveKeyFrameFile(KeyFrame*, QString dataPath) = 0; From 4836afa9b2bbd9fc88b56e2fa12a4d5eb405e719 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 2 Mar 2019 11:33:09 +0100 Subject: [PATCH 040/100] WIP working on ui --- app/app.pro | 3 +- app/data/app.qrc | 5 + app/data/icons/black.png | Bin 0 -> 154 bytes app/data/icons/blue.png | Bin 0 -> 164 bytes app/data/icons/green.png | Bin 0 -> 162 bytes app/data/icons/red.png | Bin 0 -> 160 bytes app/data/icons/select.png | Bin 0 -> 508 bytes app/src/bitmapcoloring.cpp | 23 +- app/src/bitmapcoloring.h | 3 + app/ui/bitmapcoloringwidget.ui | 373 +------------------------ app/ui/bitmaptwolayercoloring.ui | 251 +++++++++++++++++ app/ui/mainwindow2.ui | 8 +- core_lib/src/managers/layermanager.cpp | 25 -- core_lib/src/managers/layermanager.h | 1 - 14 files changed, 292 insertions(+), 400 deletions(-) create mode 100644 app/data/icons/black.png create mode 100644 app/data/icons/blue.png create mode 100644 app/data/icons/green.png create mode 100644 app/data/icons/red.png create mode 100644 app/data/icons/select.png create mode 100644 app/ui/bitmaptwolayercoloring.ui diff --git a/app/app.pro b/app/app.pro index 598ddc7d3e..09548bf1ed 100644 --- a/app/app.pro +++ b/app/app.pro @@ -114,7 +114,8 @@ FORMS += \ ui/filespage.ui \ ui/toolspage.ui \ ui/toolboxwidget.ui \ - ui/bitmapcoloringwidget.ui + ui/bitmapcoloringwidget.ui \ + ui/bitmaptwolayercoloring.ui diff --git a/app/data/app.qrc b/app/data/app.qrc index 78158697ef..57457e1f36 100644 --- a/app/data/app.qrc +++ b/app/data/app.qrc @@ -56,6 +56,11 @@ icons/new/arrow-horizontal.png icons/new/arrow-selectmove.png icons/new/arrow-vertical.png + icons/select.png + icons/blue.png + icons/green.png + icons/red.png + icons/black.png icons/onion-blue.png diff --git a/app/data/icons/black.png b/app/data/icons/black.png new file mode 100644 index 0000000000000000000000000000000000000000..942f74e5b5481983e8df35dfd7f8b5c021e8c092 GIT binary patch literal 154 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|oCO|{#S9GG!XV7ZFl&wkP>{XE z)7O>#F*6gVrADi7K1fJ5GbEzKIX^cyHLnE7WngeFN=+{XE z)7O>#F*6gV7Q;pHwgRA#Y-UJAiF1B#Zfaf$kjuc}T$GwvlA5AWo>`Ki;O^-gkfN8$ z4iuO2ba4#PIG>!7@Z-D#S3;74U{99BRf7@}1_nC=M){I?pB8|$d%F6$taD0e0swSp BCdvQ+ literal 0 HcmV?d00001 diff --git a/app/data/icons/green.png b/app/data/icons/green.png new file mode 100644 index 0000000000000000000000000000000000000000..f442c52d74d2a493a2f63cb3b0b658dce08f7154 GIT binary patch literal 162 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|oCO|{#S9GG!XV7ZFl&wkP>{XE z)7O>#F*6gVrphr(!z7@PY-UJAiF1B#Zfaf$kjuc}T$GwvlA5AWo>`Ki;O^-gkfN8$ z4iuO0ba4#PIG>#I{XE z)7O>#F*6gVhI#ZH$G<=!+02lL66gHf+|;}hAeVu`xhOTUBsE2$JhLQ2!QIn0AVn{g x9Vjm5>EaloaX$Iac?YS4B#EmAs}gTyF)%pjG0Jb8aL5;=)zj6_Wt~$(696FgCd>c; literal 0 HcmV?d00001 diff --git a/app/data/icons/select.png b/app/data/icons/select.png new file mode 100644 index 0000000000000000000000000000000000000000..317f6f85e95eca64c93cd1d9b00f9e1a2f27f8ea GIT binary patch literal 508 zcmV-3|LrLz?wibHaQT082}JKjMxJ4?c29-=Ywb_CME_k zF)^%x2oOL_(b3WWU%Yt1@cQ*@xFF1SHa0c}4h{}5jSBz-5EICsAb(**4^#|9Bg=pM z_>tlL`}YhoGBRMN0|XEg%rD4ZfoT9a9fZ*h24R>!fB<4zvt|uS6v7mNG$OkKJ%(Tg z00a;VvY+Apg4&A9Yl4D;3~%1N0ZRe|5R<2;=YLqVp*s_sA?SR700M^rvSyeIVBSD> z5sdxi%NGVNE-rAO0R#{W$N*4GVDkdjXoJeZ!VMsR7;S89{)3V-$RJSW012w8slhW0 yEHeSq30RJsoBKb=LJ$VZGXewlayers()->currentLayer()->type() == Layer::BITMAP) mLayerBitmap = static_cast(mEditor->layers()->currentLayer()); mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); - +/* connect(ui->btn1Select, &QPushButton::clicked, mEditor, &Editor::copyFromScan); connect(ui->btn1Next, &QPushButton::clicked, mEditor, &Editor::scrubNextKeyFrame); // connect(ui->sb1_Threshold, static_cast(&QSpinBox::valueChanged) , mBitmapImage, &BitmapImage::setThreshold); @@ -46,6 +45,7 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : connect(ui->btn3_thinRest, &QPushButton::clicked, mEditor, &Editor::toThinBlackLineRest); connect(ui->btn3_repairs, &QPushButton::clicked, mEditor, &Editor::toThinBlackLine); connect(ui->btn4_replaceThinLines, &QPushButton::clicked, mEditor, &Editor::replaceThinLines); + */ } BitmapColoring::~BitmapColoring() @@ -66,32 +66,32 @@ void BitmapColoring::updateUI() setEnabled(true); if (layer->type() == Layer::BITMAP && !layer->getIsColorLayer()) { - ui->tabWidgetColor->setEnabled(false); + /* ui->tabWidgetColor->setEnabled(false); ui->tabWidgetScans->setEnabled(true); ui->labcp_1->setEnabled(true); ui->labcp_1x->setEnabled(true); ui->labcp_2->setEnabled(false); ui->labcp_3->setEnabled(false); - ui->labcp_4->setEnabled(false); + ui->labcp_4->setEnabled(false); */ if (layer->getHasColorLayer()) { - ui->labx_3->setText(tr("To Layer: %1").arg(layer->name())); - ui->btnx_blackLine->setEnabled(true); + /* ui->labx_3->setText(tr("To Layer: %1").arg(layer->name())); + ui->btnx_blackLine->setEnabled(true); */ } else { - ui->btnx_blackLine->setEnabled(false); +// ui->btnx_blackLine->setEnabled(false); } } else if (layer->type() == Layer::BITMAP && layer->getIsColorLayer()) { - ui->tabWidgetColor->setEnabled(true); +/* ui->tabWidgetColor->setEnabled(true); ui->tabWidgetScans->setEnabled(false); ui->labcp_1->setEnabled(false); ui->labcp_1x->setEnabled(false); ui->labcp_2->setEnabled(true); ui->labcp_3->setEnabled(true); - ui->labcp_4->setEnabled(true); + ui->labcp_4->setEnabled(true); */ } else { @@ -104,3 +104,8 @@ void BitmapColoring::visibilityChanged(bool visibility) Q_UNUSED(visibility); updateUI(); } + +QTabWidget *BitmapColoring::getTabwidget() +{ + return +} diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 019332015b..8eae2c27d5 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -5,12 +5,14 @@ #include "editor.h" #include "layerbitmap.h" #include "bitmapimage.h" +#include class Layer; namespace Ui { class BitmapColoringWidget; +class BitmapTwoLayerColoring; } class BitmapColoring : public BaseDockWidget @@ -24,6 +26,7 @@ class BitmapColoring : public BaseDockWidget void initUI() override; void updateUI() override; void visibilityChanged(bool visibility); + QTabWidget* getTabwidget(); signals: diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index ea61c2267f..fa1ed39e7a 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -6,371 +6,26 @@ 0 0 - 247 - 585 + 224 + 41 Form - + - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - 75 - true - - - - Coloring process: - - - - - - - 1. Select from scan - - - - - - - [x. Black line repairs...] - - - - - - - Qt::Horizontal - - - - - - - 2. Remove white areas - - - - - - - 3. Thin the lines... - - - - - - - 4. Remove black line - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - 0 - - - - 1 - - - - - - Select coloring area. - - - - - - - Use select tool! - - - - - - - - - Threshold: - - - - - - - 150 - - - 250 - - - 200 - - - - - - - - - - - Select - - - - - - - Next - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - x - - - - - - Recreate black line - - - - - - - - 75 - true - true - - - - Bitmap to Color layer - - - - - - - - - - - - - - To Black line - - - - - - - Qt::Vertical - - - - 20 - 21 - - - - - - - - - - - - 0 - - - - 2 - - - - - 9 - 41 - 127 - 23 - - - - Apply to ALL lines... - - - - - - 9 - 70 - 120 - 23 - - - - [Apply to Active...] - - - - - - - - Fill area: - - - - - - - px - - - 1 - - - 20 - - - 6 - - - - - - - - - 3 - - - - - - Thin ALL Lines... - - - - - - - [Thin Active line] - - - - - - - Qt::Vertical - - - - 20 - 31 - - - - - - - - - 4 - - - - - - Finished coloring? - - - - - - - Only then... - - - - - - - Replace ALL thin lines... -Remove colored lines... - - - - - - - Qt::Vertical - - - - 20 - 62 - - - - - - + + + + Enhanced Standard coloring + + + + + Two-layer coloring + + diff --git a/app/ui/bitmaptwolayercoloring.ui b/app/ui/bitmaptwolayercoloring.ui new file mode 100644 index 0000000000..420d5785a4 --- /dev/null +++ b/app/ui/bitmaptwolayercoloring.ui @@ -0,0 +1,251 @@ + + + twoLayerColoring + + + + 0 + 0 + 228 + 585 + + + + TabWidget + + + 0 + + + + Tracing + + + + + + Coloring Method + + + + + + Same Layer + + + true + + + + + + + New Layer + + + + + + + + + + Scanned Drawings + + + + + + Whole Drawing + + + true + + + + + + + Select areas + + + + + + + + + Threshold + + + + + + + 160 + + + 245 + + + 220 + + + + + + + + + + + + Filters + + + + + + + + Trace Black + + + + + + + + + + :/icons/black.png + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + Trace Red + + + + + + + + + + :/icons/red.png + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + Trace Green + + + + + + + + + + :/icons/green.png + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + Trace Blue + + + + + + + + + + :/icons/blue.png + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + Repeat Process + + + + + + All keyframes + + + + + + + + + + Qt::Vertical + + + + 20 + 84 + + + + + + + + + Thinning + + + + + Finishing + + + + + + + + diff --git a/app/ui/mainwindow2.ui b/app/ui/mainwindow2.ui index d60f6c7e0e..0a87747868 100644 --- a/app/ui/mainwindow2.ui +++ b/app/ui/mainwindow2.ui @@ -49,7 +49,7 @@ 0 0 800 - 21 + 20 @@ -211,8 +211,6 @@ - - @@ -969,8 +967,8 @@ Add Bitmap Color Layer - - + + Flip In-Between diff --git a/core_lib/src/managers/layermanager.cpp b/core_lib/src/managers/layermanager.cpp index db4d855aca..ad00deadf2 100644 --- a/core_lib/src/managers/layermanager.cpp +++ b/core_lib/src/managers/layermanager.cpp @@ -199,31 +199,6 @@ Status LayerManager::copyLayer(Layer *fromLayer, Layer *toLayer) return Status::OK; } -void LayerManager::initColorLayer(Layer *fromLayer, LayerBitmap *colorlayer, int frame) -{ - Q_ASSERT(fromLayer != nullptr && colorlayer != nullptr); - if (frame == 0) - { // init color layer, all drawings - int max = fromLayer->getMaxKeyFramePosition(); - for (int i = 1; i <=max; i++) - { - if (fromLayer->keyExists(i)) - { - colorlayer->copyFrame(fromLayer, colorlayer, i); - colorlayer->getBitmapImageAtFrame(i)->toBlackLine(colorlayer->getBitmapImageAtFrame(i)); - } - } - } - else - { // single keyframe to color layer - if (fromLayer->keyExists(frame)) - { - colorlayer->copyFrame(fromLayer, colorlayer, frame); - colorlayer->getBitmapImageAtFrame(frame)->toBlackLine(colorlayer->getBitmapImageAtFrame(frame)); - } - } -} - int LayerManager::LastFrameAtFrame(int frameIndex) { Object* o = object(); diff --git a/core_lib/src/managers/layermanager.h b/core_lib/src/managers/layermanager.h index c841b6a836..07198be944 100644 --- a/core_lib/src/managers/layermanager.h +++ b/core_lib/src/managers/layermanager.h @@ -63,7 +63,6 @@ class LayerManager : public BaseManager // color layer Status copyLayer(Layer* fromLayer, Layer* toLayer); - void initColorLayer(Layer* fromLayer, LayerBitmap* colorlayer, int frame = 0); // KeyFrame Management int LastFrameAtFrame(int frameIndex); From 197d92504d381181ac9dee51986d6cb4b6688fbf Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 2 Mar 2019 14:32:42 +0100 Subject: [PATCH 041/100] Dock redesigned --- app/app.pro | 3 +- app/src/bitmapcoloring.cpp | 5 - app/src/bitmapcoloring.h | 2 - app/ui/bitmapcoloringwidget.ui | 924 ++++++++++++++++++++++++++++++- app/ui/bitmaptwolayercoloring.ui | 251 --------- 5 files changed, 918 insertions(+), 267 deletions(-) delete mode 100644 app/ui/bitmaptwolayercoloring.ui diff --git a/app/app.pro b/app/app.pro index 09548bf1ed..598ddc7d3e 100644 --- a/app/app.pro +++ b/app/app.pro @@ -114,8 +114,7 @@ FORMS += \ ui/filespage.ui \ ui/toolspage.ui \ ui/toolboxwidget.ui \ - ui/bitmapcoloringwidget.ui \ - ui/bitmaptwolayercoloring.ui + ui/bitmapcoloringwidget.ui diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index e160211ae3..2cbc7d6b01 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -104,8 +104,3 @@ void BitmapColoring::visibilityChanged(bool visibility) Q_UNUSED(visibility); updateUI(); } - -QTabWidget *BitmapColoring::getTabwidget() -{ - return -} diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 8eae2c27d5..a58c9e487e 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -12,7 +12,6 @@ class Layer; namespace Ui { class BitmapColoringWidget; -class BitmapTwoLayerColoring; } class BitmapColoring : public BaseDockWidget @@ -26,7 +25,6 @@ class BitmapColoring : public BaseDockWidget void initUI() override; void updateUI() override; void visibilityChanged(bool visibility); - QTabWidget* getTabwidget(); signals: diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index fa1ed39e7a..dea8b8754e 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -6,30 +6,940 @@ 0 0 - 224 - 41 + 250 + 450 Form - + + + 2 + + + 4 + + + 4 + + + 4 + + + 4 + - + - Enhanced Standard coloring + Same Layer - Two-layer coloring + Separate Layer + + + + 0 + + + + Prepare + + + + + + Scanned Drawings + + + + 2 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + + + Trace + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Select area from scanned Drawings + + + + + + + :/icons/select.png:/icons/select.png + + + + + + + + + + + Threshold + + + + + + + 160 + + + 245 + + + 220 + + + + + + + + + + + + Filters + + + + 2 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + + + Trace Black + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + :/icons/black.png + + + + + + + + + + + Trace Red + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + :/icons/red.png + + + + + + + + + + + Trace Green + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + :/icons/green.png + + + + + + + + + + + Trace Blue + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + :/icons/blue.png + + + + + + + + + + + + Repeat Process + + + + 2 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + All keyframes + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Apply + + + + + + + + + Qt::Vertical + + + + 20 + 49 + + + + + + + + + Thinning + + + + + + Thin Lines? + + + + 2 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + + + Thin Lines + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + Filters + + + + 2 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + + + Thin Black + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + :/icons/black.png + + + + + + + + + + + Thin Red + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + :/icons/red.png + + + + + + + + + + + Thin Green + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + :/icons/green.png + + + + + + + + + + + Thin Blue + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + :/icons/blue.png + + + + + + + + + + + + Repeat Process + + + + 2 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + All keyframes + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Apply + + + + + + + + + Qt::Vertical + + + + 20 + 80 + + + + + + + + + Finish + + + + + + Line finish... + + + + + + + Smoothing line + + + + + Replace with chosen color + + + + + + + + + + Line color: + + + + + + + Color... + + + + + + + + + + + + Filters + + + + 2 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + + + Apply to Black + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + :/icons/black.png + + + + + + + + + + + Apply to Red + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + :/icons/red.png + + + + + + + + + + + Apply to Green + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + :/icons/green.png + + + + + + + + + + + Apply to Blue + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + :/icons/blue.png + + + + + + + + + + + + Repeat Process + + + + 2 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + All keyframes + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Apply + + + + + + + + + Qt::Vertical + + + + 20 + 39 + + + + + + + + - + + + diff --git a/app/ui/bitmaptwolayercoloring.ui b/app/ui/bitmaptwolayercoloring.ui deleted file mode 100644 index 420d5785a4..0000000000 --- a/app/ui/bitmaptwolayercoloring.ui +++ /dev/null @@ -1,251 +0,0 @@ - - - twoLayerColoring - - - - 0 - 0 - 228 - 585 - - - - TabWidget - - - 0 - - - - Tracing - - - - - - Coloring Method - - - - - - Same Layer - - - true - - - - - - - New Layer - - - - - - - - - - Scanned Drawings - - - - - - Whole Drawing - - - true - - - - - - - Select areas - - - - - - - - - Threshold - - - - - - - 160 - - - 245 - - - 220 - - - - - - - - - - - - Filters - - - - - - - - Trace Black - - - - - - - - - - :/icons/black.png - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - Trace Red - - - - - - - - - - :/icons/red.png - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - Trace Green - - - - - - - - - - :/icons/green.png - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - Trace Blue - - - - - - - - - - :/icons/blue.png - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - - Repeat Process - - - - - - All keyframes - - - - - - - - - - Qt::Vertical - - - - 20 - 84 - - - - - - - - - Thinning - - - - - Finishing - - - - - - - - From 787ba8a9212d32cf5b757deefb0e571e1247bd7a Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 2 Mar 2019 16:44:39 +0100 Subject: [PATCH 042/100] Setting up color widget interactions --- app/data/app.qrc | 3 + app/data/icons/select_no.png | Bin 0 -> 547 bytes app/data/icons/select_ok.png | Bin 0 -> 540 bytes app/data/icons/select_yes.png | Bin 0 -> 540 bytes app/src/bitmapcoloring.cpp | 117 +++++++++++++++++++++++---------- app/src/bitmapcoloring.h | 9 +++ app/ui/bitmapcoloringwidget.ui | 66 +++++++++++++------ 7 files changed, 141 insertions(+), 54 deletions(-) create mode 100644 app/data/icons/select_no.png create mode 100644 app/data/icons/select_ok.png create mode 100644 app/data/icons/select_yes.png diff --git a/app/data/app.qrc b/app/data/app.qrc index 57457e1f36..347e2ced6e 100644 --- a/app/data/app.qrc +++ b/app/data/app.qrc @@ -61,6 +61,9 @@ icons/green.png icons/red.png icons/black.png + icons/select_ok.png + icons/select_no.png + icons/select_yes.png icons/onion-blue.png diff --git a/app/data/icons/select_no.png b/app/data/icons/select_no.png new file mode 100644 index 0000000000000000000000000000000000000000..6589dda78e13235fffadfb513534587076f3c5f4 GIT binary patch literal 547 zcmV+;0^I$HP)zS&es$5@R3qZHqwGaZ^HX4ltpwsDC2m$XsaktyG z>2%6$Hp9#?Gm4_%;o*UzC|Dnz+4|_rl5gL#7$YL`_jp8j_WHd6{QCN_3Ro_e6h%R+ z)!INzf7zzJogBV@mi@vaQZdMe!{N>d0cx+_?Idq2OcUCHxJ^9Kj(1m*Z6&66xx13X z!$TH}g#ctHCnx5dBhT|HNPm2h)ODZF{@sNT$n(6CU7y@YS(cbtB{$15>XRD*D9e)7 zYDKfzwDo!|E`&gg5&!Lz92^{Mz+~BfmnZoWH)*%q=DjC`z<4|sfaBxiYGKkc&F6Cg lXfzrYW85_LUgW9k{2OnPFmD?*L7@Nu002ovPDHLkV1mVL`kDX$ literal 0 HcmV?d00001 diff --git a/app/data/icons/select_ok.png b/app/data/icons/select_ok.png new file mode 100644 index 0000000000000000000000000000000000000000..ca717315734a24fc0daed50cefa8a01b5929100d GIT binary patch literal 540 zcmV+%0^|LOP)A-^F1;Hy$;u!*Jl307wx#m)~BxP*L>G4uh&y+EqR`krm4i< zd#2N=c<&3;*=!~O^pfFXu@L7R!{JZ?V(&e9o|kEfpsG0M@ZJ+eQStW7d{PYDvG&%t zN`uX2Qvd{Ox7)O@uN2_3K9_#Kuj}<%DgpNUeL>%Qk1>X)zdtI#kJei`_ci13Shw3P zS(X)-Q4|r!F-ek8tJO%7gsNZwd7$l-9H)oLk#v46$* zlDv@1U}Fr%m{N8TK|}~~X1QFJO4z=>QW3!zgNX3(_+G0jQ~;d+Ib?bCbD_qVB6!_= zSz_00HrefV0$>J%fyQxM)H;AXxOt}lU+=z>O9mwot+k~_0r+A-^F1;Hy$;u!*Jl307wx#m)~BxP*L>G4uh&y+EqR`krm4i< zd#2N=c<&3;*=!~O^pfFXu@L7R!{JZ?V(&e9o|kEfpsG0M@ZJ+eQStW7d{PYDvG&%t zN`uX2Qvd{Ox7)O@uN2_3K9_#Kuj}<%DgpNUeL>%Qk1>X)zdtI#kJei`_ci13Shw3P zS(X)-Q4|r!F-ek8tJO%7gsNZwd7$l-9H)oLk#v46$* zlDv@1U}Fr%m{N8TK|}~~X1QFJO4z=>QW3!zgNX3(_+G0jQ~;d+Ib?bCbD_qVB6!_= zSz_00HrefV0$>J%fyQxM)H;AXxOt}lU+=z>O9mwot+k~_0r+layers()->currentLayer()->type() == Layer::BITMAP) mLayerBitmap = static_cast(mEditor->layers()->currentLayer()); mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); + ui->btnSelectAreas->setIcon(QIcon(":/icons/select.png")); + connect(ui->cb1Trace, &QCheckBox::stateChanged, this, &BitmapColoring::updateTraceBoxes); + connect(ui->cbLayerSelector, QOverload::of(&QComboBox::currentIndexChanged), this, &BitmapColoring::colorMethodChanged); + connect(ui->btnSelectAreas, &QPushButton::clicked, this, &BitmapColoring::selectAreasChanged); + connect(ui->cb1Thin, &QCheckBox::stateChanged, this, &BitmapColoring::updateThinBoxes); + connect(ui->cb1FinishMethod, QOverload::of(&QComboBox::currentIndexChanged), this, &BitmapColoring::finishMethodChanged); /* connect(ui->btn1Select, &QPushButton::clicked, mEditor, &Editor::copyFromScan); connect(ui->btn1Next, &QPushButton::clicked, mEditor, &Editor::scrubNextKeyFrame); @@ -55,52 +61,97 @@ BitmapColoring::~BitmapColoring() void BitmapColoring::initUI() { - updateUI(); + ui->btn1FinishLineColor->setEnabled(false); } void BitmapColoring::updateUI() { - if (!isVisible()) { return; } - Layer* layer = mEditor->layers()->currentLayer(); - setEnabled(true); - if (layer->type() == Layer::BITMAP && !layer->getIsColorLayer()) +} + +void BitmapColoring::visibilityChanged(bool visibility) +{ + Q_UNUSED(visibility); + updateUI(); +} + +void BitmapColoring::colorMethodChanged() +{ + if (ui->cbLayerSelector->currentIndex() == 0) { - /* ui->tabWidgetColor->setEnabled(false); - ui->tabWidgetScans->setEnabled(true); - ui->labcp_1->setEnabled(true); - ui->labcp_1x->setEnabled(true); - ui->labcp_2->setEnabled(false); - ui->labcp_3->setEnabled(false); - ui->labcp_4->setEnabled(false); */ - if (layer->getHasColorLayer()) - { - /* ui->labx_3->setText(tr("To Layer: %1").arg(layer->name())); - ui->btnx_blackLine->setEnabled(true); */ - } - else - { -// ui->btnx_blackLine->setEnabled(false); - } + ui->cb2TraceBlack->setChecked(false); + ui->cb2TraceBlack->setEnabled(false); + ui->cb2ThinBlack->setChecked(false); + ui->cb2ThinBlack->setEnabled(false); + ui->cb2FinishBlack->setChecked(false); + ui->cb2FinishBlack->setEnabled(false); } - else if (layer->type() == Layer::BITMAP && layer->getIsColorLayer()) + else + { + ui->cb2TraceBlack->setEnabled(true); + ui->cb2ThinBlack->setEnabled(true); + ui->cb2FinishBlack->setEnabled(true); + } +} + +void BitmapColoring::updateTraceBoxes() +{ + if (ui->cb1Trace->isChecked()) { -/* ui->tabWidgetColor->setEnabled(true); - ui->tabWidgetScans->setEnabled(false); - ui->labcp_1->setEnabled(false); - ui->labcp_1x->setEnabled(false); - ui->labcp_2->setEnabled(true); - ui->labcp_3->setEnabled(true); - ui->labcp_4->setEnabled(true); */ + ui->gb2Prepare->setEnabled(true); + if (ui->cbLayerSelector->currentIndex() == 0) + ui->cb2TraceBlack->setEnabled(false); } else { - setEnabled(false); + ui->cb2TraceBlack->setChecked(false); + ui->cb2TraceRed->setChecked(false); + ui->cb2TraceGreen->setChecked(false); + ui->cb2TraceBlue->setChecked(false); + ui->gb2Prepare->setEnabled(false); } } -void BitmapColoring::visibilityChanged(bool visibility) +void BitmapColoring::selectAreasChanged() { - Q_UNUSED(visibility); - updateUI(); + if (mSelectAreas) + { + ui->btnSelectAreas->setIcon(QIcon(":/icons/select.png")); + mSelectAreas = false; + } + else { + ui->btnSelectAreas->setIcon(QIcon(":/icons/select_yes.png")); + mSelectAreas = true; + } + +} + +void BitmapColoring::updateThinBoxes() +{ + if (ui->cb1Thin->isChecked()) + { + ui->gb2Thin->setEnabled(true); + if (ui->cbLayerSelector->currentIndex() == 0) + ui->cb2ThinBlack->setEnabled(false); + } + else + { + ui->cb2ThinBlack->setChecked(false); + ui->cb2ThinRed->setChecked(false); + ui->cb2ThinGreen->setChecked(false); + ui->cb2ThinBlue->setChecked(false); + ui->gb2Thin->setEnabled(false); + } +} + +void BitmapColoring::finishMethodChanged() +{ + if (ui->cb1FinishMethod->currentIndex() == 0) + { + ui->btn1FinishLineColor->setEnabled(false); + } + else + { + ui->btn1FinishLineColor->setEnabled(true); + } } diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index a58c9e487e..3decb2c12f 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -29,12 +29,21 @@ class BitmapColoring : public BaseDockWidget signals: public slots: + void colorMethodChanged(); + // Prepare + void updateTraceBoxes(); + void selectAreasChanged(); + // Thin + void updateThinBoxes(); + // Finish + void finishMethodChanged(); private: Ui::BitmapColoringWidget* ui = nullptr; Editor* mEditor = nullptr; LayerBitmap* mLayerBitmap = nullptr; BitmapImage* mBitmapImage; + bool mSelectAreas = false; }; diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index dea8b8754e..ec5afafeed 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -6,7 +6,7 @@ 0 0 - 250 + 230 450 @@ -30,7 +30,7 @@ 4 - + Same Layer @@ -54,7 +54,7 @@ - + Scanned Drawings @@ -77,7 +77,7 @@ - + Trace @@ -118,14 +118,14 @@ - + Threshold - + 160 @@ -143,7 +143,7 @@ - + Filters @@ -164,9 +164,12 @@ 4 - + + + false + Trace Black @@ -198,7 +201,7 @@ - + @@ -232,7 +235,7 @@ - + @@ -266,7 +269,7 @@ - + @@ -303,7 +306,7 @@ - + Repeat Process @@ -372,9 +375,9 @@ - + - Thinning + Thin line @@ -401,7 +404,7 @@ - + Thin Lines @@ -453,6 +456,9 @@ + + false + Thin Black @@ -664,21 +670,36 @@ - + Line finish... + + 2 + + + 4 + + + 4 + + + 4 + + + 4 + - + - Smoothing line + Blended line... - Replace with chosen color + Replace line with color @@ -686,14 +707,14 @@ - + Line color: - + Color... @@ -729,6 +750,9 @@ + + false + Apply to Black From 6c888c905d6859d15969443e26d4c0e64574f5f6 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 3 Mar 2019 19:16:20 +0100 Subject: [PATCH 043/100] Blend lines working. --- app/src/actioncommands.cpp | 18 -- app/src/actioncommands.h | 1 - app/src/bitmapcoloring.cpp | 306 +++++++++++++++++-- app/src/bitmapcoloring.h | 15 +- app/src/mainwindow2.cpp | 1 - app/ui/bitmapcoloringwidget.ui | 215 +++++++++---- core_lib/src/graphics/bitmap/bitmapimage.cpp | 118 ++++--- core_lib/src/graphics/bitmap/bitmapimage.h | 16 +- core_lib/src/interface/editor.cpp | 130 -------- core_lib/src/interface/editor.h | 9 - core_lib/src/managers/layermanager.cpp | 10 + core_lib/src/structure/layer.cpp | 20 -- core_lib/src/structure/layer.h | 2 - 13 files changed, 539 insertions(+), 322 deletions(-) diff --git a/app/src/actioncommands.cpp b/app/src/actioncommands.cpp index bc8e768cde..87a224b0bc 100644 --- a/app/src/actioncommands.cpp +++ b/app/src/actioncommands.cpp @@ -650,24 +650,6 @@ Status ActionCommands::addNewSoundLayer() return Status::OK; } -Status ActionCommands::addNewBitmapColorLayer() -{ - /* - QString name = mEditor->layers()->currentLayer()->name() + "_C"; - if (!name.isEmpty()) - { - LayerBitmap* parentlayer = static_cast(mEditor->layers()->currentLayer()); - parentlayer->setHasColorLayer(true); - LayerBitmap* colorlayer = mEditor->layers()->createBitmapLayer(name); - mEditor->layers()->initColorLayer(parentlayer, colorlayer); - colorlayer->setIsColorLayer(true); - emit mEditor->layers()->currentLayerChanged(mEditor->layers()->currentLayerIndex()); - } - */ - mEditor->toBlackLine(); - return Status::OK; -} - Status ActionCommands::deleteCurrentLayer() { LayerManager* layerMgr = mEditor->layers(); diff --git a/app/src/actioncommands.h b/app/src/actioncommands.h index 1f2bf681dc..3911ea8975 100644 --- a/app/src/actioncommands.h +++ b/app/src/actioncommands.h @@ -72,7 +72,6 @@ class ActionCommands : public QObject Status addNewVectorLayer(); Status addNewCameraLayer(); Status addNewSoundLayer(); - Status addNewBitmapColorLayer(); Status deleteCurrentLayer(); QString nameSuggest(QString s); diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 209f3df961..fddd90d4f1 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -16,8 +16,7 @@ GNU General Public License for more details. #include "bitmapcoloring.h" #include "ui_bitmapcoloringwidget.h" #include "layermanager.h" -#include "qdebug.h" - +#include "scribblearea.h" BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : BaseDockWidget(parent) @@ -34,24 +33,27 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : mLayerBitmap = static_cast(mEditor->layers()->currentLayer()); mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); ui->btnSelectAreas->setIcon(QIcon(":/icons/select.png")); - connect(ui->cb1Trace, &QCheckBox::stateChanged, this, &BitmapColoring::updateTraceBoxes); + connect(ui->cbLayerSelector, QOverload::of(&QComboBox::currentIndexChanged), this, &BitmapColoring::colorMethodChanged); - connect(ui->btnSelectAreas, &QPushButton::clicked, this, &BitmapColoring::selectAreasChanged); + connect(mEditor->layers(), &LayerManager::currentLayerChanged, this, &BitmapColoring::layerChanged); + + // Prepare + connect(ui->cb0Trace, &QCheckBox::stateChanged, this, &BitmapColoring::updateTraceBoxes); + connect(ui->cb1Threshold, &QCheckBox::stateChanged, this, &BitmapColoring::updateBtnSelect); + connect(ui->sb1Threshold, QOverload::of(&QSpinBox::valueChanged), this, &BitmapColoring::setThreshold); + connect(ui->btnSelectAreas, &QPushButton::clicked, this, &BitmapColoring::selectAreas); + connect(ui->btnSelectNext, &QPushButton::clicked, this, &BitmapColoring::selectFromScans); + connect(ui->btnSelectCancel, &QPushButton::clicked, this, &BitmapColoring::cancelSelectAreas); + connect(ui->btnApplyPrepare, &QPushButton::clicked, this, &BitmapColoring::prepareLines); + // Thin connect(ui->cb1Thin, &QCheckBox::stateChanged, this, &BitmapColoring::updateThinBoxes); - connect(ui->cb1FinishMethod, QOverload::of(&QComboBox::currentIndexChanged), this, &BitmapColoring::finishMethodChanged); -/* - connect(ui->btn1Select, &QPushButton::clicked, mEditor, &Editor::copyFromScan); - connect(ui->btn1Next, &QPushButton::clicked, mEditor, &Editor::scrubNextKeyFrame); -// connect(ui->sb1_Threshold, static_cast(&QSpinBox::valueChanged) , mBitmapImage, &BitmapImage::setThreshold); - connect(ui->btnx_blackLine, &QPushButton::clicked, mEditor, &Editor::toBlackLine); + connect(ui->sbSpotAreas, QOverload::of(&QSpinBox::valueChanged), this, &BitmapColoring::setSpotArea); + connect(ui->btnApplyThin, &QPushButton::clicked, this, &BitmapColoring::thinLines); + // Finish + connect(ui->cb1Finish, &QCheckBox::stateChanged, this, &BitmapColoring::updateFinishBoxes); + connect(ui->btnApplyFinish, &QPushButton::clicked, this, &BitmapColoring::blendLines); -// connect(ui->sb2_fillArea, QOverload::of(&QSpinBox::valueChanged) , mBitmapImage, &BitmapImage::setWhiteArea); - connect(ui->btn2_fillRest, &QPushButton::clicked, mEditor, &Editor::fillWhiteAreasRest); - connect(ui->btn2_repairs, &QPushButton::clicked, mEditor, &Editor::fillWhiteAreas); - connect(ui->btn3_thinRest, &QPushButton::clicked, mEditor, &Editor::toThinBlackLineRest); - connect(ui->btn3_repairs, &QPushButton::clicked, mEditor, &Editor::toThinBlackLine); - connect(ui->btn4_replaceThinLines, &QPushButton::clicked, mEditor, &Editor::replaceThinLines); - */ + updateUI(); } BitmapColoring::~BitmapColoring() @@ -61,18 +63,48 @@ BitmapColoring::~BitmapColoring() void BitmapColoring::initUI() { - ui->btn1FinishLineColor->setEnabled(false); + updateUI(); } void BitmapColoring::updateUI() { + if (mEditor->layers()->currentLayer()->type() == Layer::BITMAP) + mLayerBitmap = static_cast(mEditor->layers()->currentLayer()); + if (mLayerBitmap == nullptr) { return; } + if (mEditor->layers()->currentLayer()->type() == Layer::BITMAP) + { + if (mLayerBitmap->getHasColorLayer()) + { + ui->tabPrepare->setEnabled(true); + ui->tabThinLine->setEnabled(false); + ui->tabFinish->setEnabled(false); + } + else if (mLayerBitmap->getIsColorLayer()) + { + ui->tabPrepare->setEnabled(false); + ui->tabThinLine->setEnabled(true); + ui->tabFinish->setEnabled(true); + } + else + { + ui->tabPrepare->setEnabled(true); + ui->tabThinLine->setEnabled(true); + ui->tabFinish->setEnabled(true); + } + } + else + { + ui->tabPrepare->setEnabled(false); + ui->tabThinLine->setEnabled(false); + ui->tabFinish->setEnabled(false); + } } void BitmapColoring::visibilityChanged(bool visibility) { - Q_UNUSED(visibility); - updateUI(); + if (visibility) + updateUI(); } void BitmapColoring::colorMethodChanged() @@ -94,9 +126,15 @@ void BitmapColoring::colorMethodChanged() } } +void BitmapColoring::layerChanged(int index) +{ + Q_UNUSED(index); + updateUI(); +} + void BitmapColoring::updateTraceBoxes() { - if (ui->cb1Trace->isChecked()) + if (ui->cb0Trace->isChecked()) { ui->gb2Prepare->setEnabled(true); if (ui->cbLayerSelector->currentIndex() == 0) @@ -112,18 +150,122 @@ void BitmapColoring::updateTraceBoxes() } } -void BitmapColoring::selectAreasChanged() +void BitmapColoring::updateBtnSelect() { - if (mSelectAreas) + if (ui->cb1Threshold->isChecked()) { - ui->btnSelectAreas->setIcon(QIcon(":/icons/select.png")); - mSelectAreas = false; + ui->btnSelectAreas->setEnabled(true); } - else { - ui->btnSelectAreas->setIcon(QIcon(":/icons/select_yes.png")); - mSelectAreas = true; + else + { + ui->btnSelectAreas->setEnabled(false); } +} +void BitmapColoring::setThreshold(int threshold) +{ + mBitmapImage->setThreshold(threshold); +} + +void BitmapColoring::selectAreas() +{ + ui->gb0Prepare->setEnabled(false); + ui->gb1Prepare->setEnabled(false); + ui->gb2Prepare->setEnabled(false); + ui->gb3Prepare->setEnabled(false); + ui->btnApplyPrepare->setEnabled(false); + ui->btnSelectNext->setEnabled(true); + ui->btnSelectCancel->setEnabled(true); + mEditor->scrubTo(1); +} + +void BitmapColoring::cancelSelectAreas() +{ + ui->gb0Prepare->setEnabled(true); + ui->gb1Prepare->setEnabled(true); + ui->gb2Prepare->setEnabled(true); + ui->gb3Prepare->setEnabled(true); + ui->btnApplyPrepare->setEnabled(true); + ui->btnSelectNext->setEnabled(false); + ui->btnSelectCancel->setEnabled(false); +} + +void BitmapColoring::selectFromScans() +{ + ScribbleArea* scribble = mEditor->getScribbleArea(); + if (scribble->isSomethingSelected()) + { + mEditor->copy(); + mEditor->layers()->currentLayer()->removeKeyFrame(mEditor->currentFrame()); + mEditor->layers()->currentLayer()->addNewKeyFrameAt(mEditor->currentFrame()); + mEditor->paste(); + mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); + mBitmapImage = mBitmapImage->scanToTransparent(mBitmapImage, + true, + ui->cb2TraceRed->isChecked(), + ui->cb2TraceGreen->isChecked(), + ui->cb2TraceBlue->isChecked()); + if (mEditor->currentFrame() < mEditor->layers()->currentLayer()->getMaxKeyFramePosition()) + { + mEditor->scrubNextKeyFrame(); + } + else + { + cancelSelectAreas(); + ui->cb1Threshold->setChecked(false); + } + } +} + +void BitmapColoring::prepareLines() +{ + if (mLayerBitmap == nullptr) { return; } + + ui->tabPrepare->setEnabled(false); + + // if a separate layer is needed, we make one + LayerBitmap* colorLayer = nullptr; + if (ui->cbLayerSelector->currentIndex() == 0) + { + colorLayer = mLayerBitmap; + } + else + { + if (!mLayerBitmap->getHasColorLayer()) + { + colorLayer = mEditor->layers()->createBitmapLayer(mLayerBitmap->name() + "_C"); + mLayerBitmap->setHasColorLayer(true); + colorLayer->setIsColorLayer(true); + mEditor->layers()->copyLayer(mLayerBitmap, colorLayer); + } + else { + colorLayer = static_cast(mEditor->layers()->findLayerByName(mLayerBitmap->name() + "_C")); + } + } + + int firstFrame = 1, lastFrame = 1; + if (ui->cb3TraceAllKeyframes->isChecked()) + { + lastFrame = colorLayer->getMaxKeyFramePosition(); + } + else + { + firstFrame = mEditor->currentFrame(); + lastFrame = firstFrame; + } + for (int i = firstFrame; i <= lastFrame; i++) + { + if (colorLayer->keyExists(i)) + { + mEditor->scrubTo(i); + colorLayer->getBitmapImageAtFrame(i)->traceLine(colorLayer->getBitmapImageAtFrame(i), + ui->cb2TraceBlack->isChecked(), + ui->cb2TraceRed->isChecked(), + ui->cb2TraceGreen->isChecked(), + ui->cb2TraceBlue->isChecked()); + } + } + updateUI(); } void BitmapColoring::updateThinBoxes() @@ -144,14 +286,114 @@ void BitmapColoring::updateThinBoxes() } } -void BitmapColoring::finishMethodChanged() +void BitmapColoring::setSpotArea(int size) +{ + mBitmapImage->setSpotArea(size); +} + +void BitmapColoring::thinLines() { - if (ui->cb1FinishMethod->currentIndex() == 0) + if (mLayerBitmap == nullptr) { return; } + mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->layers()->currentLayer()->getMaxKeyFramePosition()); + + ui->tabThinLine->setEnabled(false); + + int firstFrame = 1, lastFrame = 1; + if (ui->cb3ThinAllKeyframes->isChecked()) { - ui->btn1FinishLineColor->setEnabled(false); + lastFrame = mLayerBitmap->getMaxKeyFramePosition(); } else { - ui->btn1FinishLineColor->setEnabled(true); + firstFrame = mEditor->currentFrame(); + lastFrame = firstFrame; } + mBitmapImage->setSpotArea(ui->sbSpotAreas->value()); + for (int i = firstFrame; i <= lastFrame; i++) + { + if (mLayerBitmap->keyExists(i)) + { + mEditor->scrubTo(i); + mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(i); + if (ui->cbSpotAreas->isChecked()) + { + mBitmapImage->fillSpotAreas(mLayerBitmap->getBitmapImageAtFrame(i)); + } + + if (ui->cb1Thin->isChecked()) + { + mBitmapImage->toThinBlackLine(mBitmapImage, + ui->cb2ThinBlack->isChecked(), + ui->cb2ThinRed->isChecked(), + ui->cb2ThinGreen->isChecked(), + ui->cb2ThinBlue->isChecked()); + } + } + } + updateUI(); } + +void BitmapColoring::updateFinishBoxes() +{ + if (ui->cb1Finish->isChecked()) + { + ui->gb2Finish->setEnabled(true); + if (ui->cbLayerSelector->currentIndex() == 0) + ui->cb2FinishBlack->setEnabled(false); + } + else + { + ui->cb2FinishBlack->setChecked(false); + ui->cb2FinishRed->setChecked(false); + ui->cb2FinishGreen->setChecked(false); + ui->cb2FinishBlue->setChecked(false); + ui->gb2Finish->setEnabled(false); + } +} + +void BitmapColoring::blendLines() +{ + if (mLayerBitmap == nullptr) { return; } + mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->layers()->currentLayer()->getMaxKeyFramePosition()); + + QString orgName = mLayerBitmap->name(); + orgName.chop(2); + LayerBitmap* artLayer = static_cast(mEditor->layers()->findLayerByName(orgName)); + + ui->tabFinish->setEnabled(false); + + int firstFrame = 1, lastFrame = 1; + if (ui->cb3FinishAllKeyframes->isChecked()) + { + lastFrame = mLayerBitmap->getMaxKeyFramePosition(); + } + else + { + firstFrame = mEditor->currentFrame(); + lastFrame = firstFrame; + } + for (int i = firstFrame; i <= lastFrame; i++) + { + if (mLayerBitmap->keyExists(i)) + { + mEditor->scrubTo(i); + if (ui->cb1Finish->isChecked()) + { + mLayerBitmap->getBitmapImageAtFrame(i)->blendLines(mLayerBitmap->getBitmapImageAtFrame(i), + ui->cb2FinishBlack->isChecked(), + ui->cb2FinishRed->isChecked(), + ui->cb2FinishGreen->isChecked(), + ui->cb2FinishBlue->isChecked()); + if (ui->cbLayerSelector->currentIndex() == 1 && artLayer != nullptr) + { + artLayer->getBitmapImageAtFrame(i)->blendLines(artLayer->getBitmapImageAtFrame(i), + false, // don't mess with the original + ui->cb2FinishRed->isChecked(), + ui->cb2FinishGreen->isChecked(), + ui->cb2FinishBlue->isChecked()); + } + } + } + } +} + diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 3decb2c12f..283bf9a074 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -30,19 +30,28 @@ class BitmapColoring : public BaseDockWidget public slots: void colorMethodChanged(); + void layerChanged(int index); // Prepare void updateTraceBoxes(); - void selectAreasChanged(); + void updateBtnSelect(); + void setThreshold(int threshold); + void selectAreas(); + void cancelSelectAreas(); + void selectFromScans(); + void prepareLines(); // Thin void updateThinBoxes(); + void setSpotArea(int size); + void thinLines(); // Finish - void finishMethodChanged(); + void updateFinishBoxes(); + void blendLines(); private: Ui::BitmapColoringWidget* ui = nullptr; Editor* mEditor = nullptr; LayerBitmap* mLayerBitmap = nullptr; - BitmapImage* mBitmapImage; + BitmapImage* mBitmapImage = nullptr; bool mSelectAreas = false; }; diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index 41ea24ff92..063a0f94d2 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -276,7 +276,6 @@ void MainWindow2::createMenus() connect(ui->actionNew_Vector_Layer, &QAction::triggered, mCommands, &ActionCommands::addNewVectorLayer); connect(ui->actionNew_Sound_Layer, &QAction::triggered, mCommands, &ActionCommands::addNewSoundLayer); connect(ui->actionNew_Camera_Layer, &QAction::triggered, mCommands, &ActionCommands::addNewCameraLayer); - connect(ui->actionAdd_Bitmap_Color_Layer, &QAction::triggered, mCommands, &ActionCommands::addNewBitmapColorLayer); connect(ui->actionDelete_Current_Layer, &QAction::triggered, mCommands, &ActionCommands::deleteCurrentLayer); /// --- View Menu --- diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index ec5afafeed..4e9c040426 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -7,13 +7,13 @@ 0 0 230 - 450 + 495 Form - + 2 @@ -31,14 +31,17 @@ + + Colorize on Same or Separate layer? + - Same Layer + On the Same Layer - Separate Layer + On a Separate Layer @@ -52,13 +55,13 @@ Prepare - + - + - Scanned Drawings + Trace lines? - + 2 @@ -77,9 +80,9 @@ - + - Trace + Trace lines true @@ -99,22 +102,32 @@ - - - - Select area from scanned Drawings - - - - - - - :/icons/select.png:/icons/select.png - - - + + + + + + + Scanned Drawings? + + + + 2 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -137,6 +150,23 @@ + + + + false + + + Select areas from scanned Drawings + + + + + + + :/icons/select.png:/icons/select.png + + + @@ -336,6 +366,49 @@ + + + + + + false + + + Select - and go to next keyframe + + + Select - Next + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + Cancel select areas + + + Cancel + + + + + @@ -379,7 +452,7 @@ Thin line - + @@ -431,6 +504,60 @@ + + + + Fill spot areas? + + + + 2 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + + + Fill small, unwanted areas in lines + + + Fill spots areas + + + + + + + Size of area to fill (1-15) + + + 1 + + + 15 + + + 6 + + + + + + + + @@ -672,7 +799,7 @@ - Line finish... + Blend lines? @@ -691,37 +818,15 @@ 4 - - - - Blended line... - - - - - Replace line with color - - + + + Blend lines + + + true + - - - - - - Line color: - - - - - - - Color... - - - - - diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 46b0aaa7e7..acd8ff1544 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -656,7 +656,7 @@ void BitmapImage::setBounds(QRect rect) updateBounds(rect); } -BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, bool green, bool blue) +BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool black, bool red, bool green, bool blue) { Q_ASSERT(bitmapimage != nullptr); @@ -706,7 +706,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool red, img->setPixel(x, y, transp); } } // IF in grayscale graduation area - else if(qGray(rgba) >= mLowThreshold && qGray(rgba) < mThreshold) + else if(qGray(rgba) >= mLowThreshold && qGray(rgba) < mThreshold && black) { qreal factor = qreal(mThreshold - qGray(rgba)) / qreal(mThreshold - mLowThreshold); int alpha = static_cast(255 * factor); @@ -724,7 +724,7 @@ void BitmapImage::getThresholdSuggestion(BitmapImage* img) Q_ASSERT(img != nullptr); // TODO } -void BitmapImage::toBlackLine(BitmapImage* bitmapimage) +void BitmapImage::traceLine(BitmapImage* bitmapimage, bool black, bool red, bool green, bool blue) { Q_ASSERT(bitmapimage != nullptr); @@ -738,25 +738,42 @@ void BitmapImage::toBlackLine(BitmapImage* bitmapimage) if (qAlpha(img->constScanLine(x, y)) > 0) { if(qRed(rgba) - 50 > qGreen(rgba)) + { + if(red) img->setPixel(x, y, redline); + else + img->setPixel(x, y, transp); + } else if(qBlue(rgba) - 50 > qRed(rgba) && qBlue(rgba) > qGreen(rgba)) + { + if(blue) img->setPixel(x, y, blueline); + else + img->setPixel(x, y, transp); + } else if(qGreen(rgba) - 50 > qRed(rgba) && qGreen(rgba) > qBlue(rgba)) + { + if(green) img->setPixel(x, y, greenline); - else + else + img->setPixel(x, y, transp); + } + else if(black) + { img->setPixel(x, y, thinline); + } } } } img->modification(); } -void BitmapImage::fillWhiteAreas(BitmapImage *bitmapimage) +void BitmapImage::fillSpotAreas(BitmapImage *bitmapimage) { if(bitmapimage == nullptr) { return; } BitmapImage* img = bitmapimage; - // fill areas size 'area' or less with black + // fill areas size 'area' or less with appropriate color QVector points; points.clear(); QRgb active, previous = thinline; @@ -764,12 +781,12 @@ void BitmapImage::fillWhiteAreas(BitmapImage *bitmapimage) { for (int y = img->top(); y < img->bottom(); y++) { - active =img->pixel(x, y); - if (qAlpha(active) < 1) + active = img->constScanLine(x, y); + if (qAlpha(active) == 0) { points.append(QPoint(x, y)); int areaSize = fillWithColor(QPoint(x, y), transp, rosa, img); - if (areaSize <= mWhiteArea) + if (areaSize <= mSpotArea) { // replace rosa with last color fillWithColor(points.last(), rosa, previous, img); points.removeLast(); @@ -786,19 +803,27 @@ void BitmapImage::fillWhiteAreas(BitmapImage *bitmapimage) img->modification(); } -void BitmapImage::toThinBlackLine(BitmapImage* colorImage) +void BitmapImage::toThinBlackLine(BitmapImage* colorImage, bool black, bool red, bool green, bool blue) { Q_ASSERT(colorImage != nullptr); BitmapImage* img = colorImage; - bool N = true, E = true, S = true, W = true, black, search; + bool N = true, E = true, S = true, W = true, pixelRemoved, search; + + QList colors; + if (black) colors.append(thinline); + if (red) colors.append(redline); + if (green) colors.append(greenline); + if (blue) colors.append(blueline); + + QRgb pixColor; while (N || E || S || W) { if (N) // from NORTH { - // set 'black' to false. 'black' is set to true whenever a black pixel is removed - black = false; + // set 'pixelRemoved' to false. 'pixelRemoved' is set to true whenever a pixel is removed + pixelRemoved = false; // 'search' is true while pixels are transparent // when thinline pixel is found, 'search' is set to false until next transparent pixel search = true; @@ -808,29 +833,30 @@ void BitmapImage::toThinBlackLine(BitmapImage* colorImage) { if (search) { - if (qAlpha(img->constScanLine(x,y)) > 0) + pixColor = img->constScanLine(x,y); + if (qAlpha(pixColor) > 0) { search = false; - if (qAlpha(img->constScanLine(x,y+1)) > 0) + if (qAlpha(img->constScanLine(x,y+1)) > 0 && colors.contains(pixColor)) { if ((qAlpha(img->constScanLine(x-1,y-1)) == 0 && qAlpha(img->constScanLine(x+1,y-1)) == 0) && (qAlpha(img->constScanLine(x+1, y)) > 0 || qAlpha(img->constScanLine(x-1, y)) >0 || qAlpha(img->constScanLine(x+1, y+1)) > 0 || qAlpha(img->constScanLine(x-1, y+1)) >0)) { img->setPixel(x, y, transp); - black = true; + pixelRemoved = true; } else if ((qAlpha(img->constScanLine(x-1,y-1)) > 0 && qAlpha(img->constScanLine(x+1,y-1)) > 0) && (qAlpha(img->constScanLine(x+1,y)) > 0 && qAlpha(img->constScanLine(x-1,y)) > 0)) { img->setPixel(x, y, transp); - black = true; + pixelRemoved = true; } else if ((qAlpha(img->constScanLine(x-1,y-1)) > 0 && qAlpha(img->constScanLine(x-1,y)) > 0) || (qAlpha(img->constScanLine(x+1,y-1)) > 0 && qAlpha(img->constScanLine(x+1,y)) > 0)) { img->setPixel(x, y, transp); - black = true; + pixelRemoved = true; } } } @@ -842,11 +868,11 @@ void BitmapImage::toThinBlackLine(BitmapImage* colorImage) } } } - N = black; // if none 'black' is removed, N = false + N = pixelRemoved; // if none is removed, N = false } if (E) // from EAST { - black = false; + pixelRemoved = false; search = true; for (int y = img->top(); y < img->bottom(); y++) { @@ -854,29 +880,30 @@ void BitmapImage::toThinBlackLine(BitmapImage* colorImage) { if (search) { - if (qAlpha(img->constScanLine(x,y)) > 0) + pixColor = img->constScanLine(x,y); + if (qAlpha(pixColor) > 0) { search = false; - if (qAlpha(img->constScanLine(x-1,y)) > 0) + if (qAlpha(img->constScanLine(x-1,y)) > 0 && colors.contains(pixColor)) { if ((qAlpha(img->constScanLine(x+1,y-1)) == 0 && qAlpha(img->constScanLine(x+1,y+1)) == 0) && (qAlpha(img->constScanLine(x,y-1)) > 0 || qAlpha(img->constScanLine(x,y+1)) >0 || qAlpha(img->constScanLine(x-1,y-1)) > 0 || qAlpha(img->constScanLine(x-1,y+1)) >0)) { img->setPixel(x, y, transp); - black = true; + pixelRemoved = true; } else if ((qAlpha(img->constScanLine(x+1,y+1)) > 0 && qAlpha(img->constScanLine(x+1,y-1)) > 0) && (qAlpha(img->constScanLine(x,y+1)) > 0 && qAlpha(img->constScanLine(x,y-1)) > 0)) { img->setPixel(x, y, transp); - black = true; + pixelRemoved = true; } else if ((qAlpha(img->constScanLine(x+1,y+1)) > 0 && qAlpha(img->constScanLine(x,y+1)) > 0) || (qAlpha(img->constScanLine(x+1,y-1)) > 0 && qAlpha(img->constScanLine(x,y-1)) > 0)) { img->setPixel(x, y, transp); - black = true; + pixelRemoved = true; } } } @@ -888,11 +915,11 @@ void BitmapImage::toThinBlackLine(BitmapImage* colorImage) } } } - E = black; // if none 'black' is removed, E = false + E = pixelRemoved; // if none is removed, E = false } if (S) // from SOUTH { - black = false; + pixelRemoved = false; search = true; for (int x = img->left(); x < img->right(); x++) { @@ -900,29 +927,30 @@ void BitmapImage::toThinBlackLine(BitmapImage* colorImage) { if (search) { - if (qAlpha(img->constScanLine(x,y)) > 0) + pixColor = img->constScanLine(x,y); + if (qAlpha(pixColor) > 0) { search = false; - if (qAlpha(img->constScanLine(x,y-1)) > 0) + if (qAlpha(img->constScanLine(x,y-1)) > 0 && colors.contains(pixColor)) { if ((qAlpha(img->constScanLine(x-1,y+1)) == 0 && qAlpha(img->constScanLine(x+1,y+1)) == 0) && (qAlpha(img->constScanLine(x-1, y)) > 0 || qAlpha(img->constScanLine(x+1, y)) >0 || qAlpha(img->constScanLine(x-1, y-1)) > 0 || qAlpha(img->constScanLine(x+1, y-1)) >0)) { img->setPixel(x, y, transp); - black = true; + pixelRemoved = true; } else if ((qAlpha(img->constScanLine(x-1,y+1)) > 0 && qAlpha(img->constScanLine(x+1,y+1)) > 0) && (qAlpha(img->constScanLine(x+1,y)) > 0 && qAlpha(img->constScanLine(x-1,y)) > 0)) { img->setPixel(x, y, transp); - black = true; + pixelRemoved = true; } else if ((qAlpha(img->constScanLine(x-1,y+1)) > 0 && qAlpha(img->constScanLine(x-1,y)) > 0) || (qAlpha(img->constScanLine(x+1,y+1)) > 0 && qAlpha(img->constScanLine(x+1,y)) > 0)) { img->setPixel(x, y, transp); - black = true; + pixelRemoved = true; } } } @@ -934,11 +962,11 @@ void BitmapImage::toThinBlackLine(BitmapImage* colorImage) } } } - S = black; // if none 'black' is removed, S = false + S = pixelRemoved; // if none is removed, S = false } if (W) // from WEST { - black = false; + pixelRemoved = false; search = true; for (int y = img->top(); y <= img->bottom(); y++) { @@ -946,29 +974,30 @@ void BitmapImage::toThinBlackLine(BitmapImage* colorImage) { if (search) { - if (qAlpha(img->constScanLine(x,y)) > 0) + pixColor = img->constScanLine(x,y); + if (qAlpha(pixColor) > 0) { search = false; - if (qAlpha(img->constScanLine(x+1,y)) > 0) + if (qAlpha(img->constScanLine(x+1,y)) > 0 && colors.contains(pixColor)) { if ((qAlpha(img->constScanLine(x-1,y-1)) == 0 && qAlpha(img->constScanLine(x-1,y+1)) == 0) && (qAlpha(img->constScanLine(x,y-1)) > 0 || qAlpha(img->constScanLine(x,y+1)) >0 || qAlpha(img->constScanLine(x+1,y-1)) > 0 || qAlpha(img->constScanLine(x+1,y+1)) >0)) { img->setPixel(x, y, transp); - black = true; + pixelRemoved = true; } else if ((qAlpha(img->constScanLine(x-1,y+1)) > 0 && qAlpha(img->constScanLine(x-1,y-1)) > 0) && (qAlpha(img->constScanLine(x,y+1)) > 0 && qAlpha(img->constScanLine(x,y-1)) > 0)) { img->setPixel(x, y, transp); - black = true; + pixelRemoved = true; } else if ((qAlpha(img->constScanLine(x-1,y+1)) > 0 && qAlpha(img->constScanLine(x,y+1)) > 0) || (qAlpha(img->constScanLine(x-1,y-1)) > 0 && qAlpha(img->constScanLine(x,y-1)) > 0)) { img->setPixel(x, y, transp); - black = true; + pixelRemoved = true; } } } @@ -980,7 +1009,7 @@ void BitmapImage::toThinBlackLine(BitmapImage* colorImage) } } } - W = black; // if none 'black' is removed, W = false + W = pixelRemoved; // if none is removed, W = false } } img->modification(); @@ -1002,7 +1031,7 @@ void BitmapImage::restoreColoredLines(BitmapImage *orgImage, BitmapImage *colorI } } -void BitmapImage::replaceThinLine(BitmapImage *bitmapimage) +void BitmapImage::blendLines(BitmapImage *bitmapimage, bool black, bool red, bool green, bool blue) { Q_ASSERT(bitmapimage != nullptr); @@ -1011,14 +1040,17 @@ void BitmapImage::replaceThinLine(BitmapImage *bitmapimage) int r, g, b, a; //red, green, blue, alpha QList points; // QPoints to add in calculation QList rgblist; // QRgb's that should be excluded - rgblist << thinline << redline << greenline << blueline; + if (black) rgblist << thinline; + if (red) rgblist << redline; + if (green) rgblist << greenline; + if (blue) rgblist << blueline; for (int x = img->left(); x <= img->right(); x++) { for (int y = img->top(); y <= img->bottom(); y++) { points.clear(); r=0; g=0; b=0; a=0; - if (rgblist.contains(img->pixel(x,y))) + if (rgblist.contains(img->constScanLine(x,y))) { if (!rgblist.contains(img->pixel(x-1, y-1))) points.append(QPoint(x-1, y-1)); if (!rgblist.contains(img->pixel(x-1, y ))) points.append(QPoint(x-1, y )); diff --git a/core_lib/src/graphics/bitmap/bitmapimage.h b/core_lib/src/graphics/bitmap/bitmapimage.h index 9954545a29..dec88692f3 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.h +++ b/core_lib/src/graphics/bitmap/bitmapimage.h @@ -106,16 +106,16 @@ class BitmapImage : public KeyFrame // coloring methods int getThreshold() { return mThreshold; } - int getWhiteArea() { return mWhiteArea; } - BitmapImage* scanToTransparent(BitmapImage* bitmapimage, bool red, bool green, bool blue); + int getSpotArea() { return mSpotArea; } + BitmapImage* scanToTransparent(BitmapImage* bitmapimage, bool black, bool red, bool green, bool blue); void getThresholdSuggestion(BitmapImage* img); - void toBlackLine(BitmapImage* bitmapimage); + void traceLine(BitmapImage* bitmapimage, bool black, bool red, bool green, bool blue); - void fillWhiteAreas(BitmapImage* bitmapimage); - void toThinBlackLine(BitmapImage* colorImage); + void fillSpotAreas(BitmapImage* bitmapimage); + void toThinBlackLine(BitmapImage* colorImage, bool black, bool red, bool green, bool blue); void restoreColoredLines(BitmapImage* orgImage, BitmapImage* colorImage); - void replaceThinLine(BitmapImage* bitmapimage); + void blendLines(BitmapImage* bitmapimage, bool black, bool red, bool green, bool blue); void removeColoredLines(BitmapImage* bitmapimage); int fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, BitmapImage* bitmapimage); // coloring methods end @@ -138,7 +138,7 @@ class BitmapImage : public KeyFrame public slots: void setThreshold(int threshold) { mThreshold = threshold; } - void setWhiteArea(int whiteArea) { mWhiteArea = whiteArea; } + void setSpotArea(int spotArea) { mSpotArea = spotArea; } protected: void updateBounds(QRect rectangle); @@ -158,7 +158,7 @@ public slots: int mThreshold = 200; const int mLowThreshold = 30; // threshold for images to be given transparency - int mWhiteArea = 6; + int mSpotArea = 6; }; diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 3901892ffa..7698a0d1e6 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -566,136 +566,6 @@ void Editor::flipSelection(bool flipVertical) mScribbleArea->flipSelection(flipVertical); } -/** - * @brief Editor::copyFromScan - * Selecting from a scanned drawing imported to Pencil2d. - * Can only be used by Layer::BITMAP type layers. - */ -void Editor::copyFromScan() -{ - Layer* layer = mObject->getLayer(layers()->currentLayerIndex()); - if (layer == nullptr) { return; } - - if (!layer->keyExists(currentFrame())) { return; } - - if (mScribbleArea->isSomethingSelected()) - { - copy(); - layer->removeKeyFrame(currentFrame()); - layer->addNewKeyFrameAt(currentFrame()); - paste(); - g_clipboardBitmapImage.clear(); - scanToTransparent(); - } -} - -void Editor::scanToTransparent() -{ - BitmapImage* bitmapimage = static_cast(layers()->currentLayer()->getKeyFrameAt(currentFrame())); - bitmapimage = bitmapimage->scanToTransparent(bitmapimage,true, true, true); // TODO - mScribbleArea->updateFrame(currentFrame()); -} - -void Editor::toBlackLine() -{ - LayerBitmap* orgLayer = static_cast(layers()->currentLayer()); - orgLayer->setHasColorLayer(true); - LayerBitmap* colorLayer = layers()->createBitmapLayer(orgLayer->name() + "_C"); - colorLayer->setIsColorLayer(true); - layers()->copyLayer(orgLayer, colorLayer); - orgLayer->copyFrames(orgLayer,colorLayer, 1, orgLayer->getMaxKeyFramePosition(), 1); - mObject->updateActiveFrames(currentFrame()); - for (int i = 1; i <= colorLayer->getMaxKeyFramePosition(); i++) - { - if (colorLayer->keyExists(i)) - { - scrubTo(i); - colorLayer->getBitmapImageAtFrame(i)->toBlackLine(colorLayer->getBitmapImageAtFrame(i)); - } - } - mScribbleArea->updateFrame(currentFrame()); -} - -void Editor::fillWhiteAreas() -{ - LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); - mObject->updateActiveFrames(currentFrame()); - layerBitmap->getBitmapImageAtFrame(currentFrame())->fillWhiteAreas(layerBitmap->getBitmapImageAtFrame(currentFrame())); - mScribbleArea->updateFrame(currentFrame()); -} - -void Editor::fillWhiteAreasRest() -{ - LayerBitmap* layerBitmap = static_cast(layers()->currentLayer()); - for (int i = 1; i <= layerBitmap->getMaxKeyFramePosition(); i++) - { - if (layerBitmap->keyExists(i)) - { - scrubTo(i); - layerBitmap->getBitmapImageAtFrame(i)->fillWhiteAreas(layerBitmap->getBitmapImageAtFrame(i)); - mObject->updateActiveFrames(i); - mScribbleArea->updateFrame(i); - } - } -} - -void Editor::toThinBlackLine() -{ - LayerBitmap* colorLayer = static_cast(layers()->currentLayer()); - QString tmp = colorLayer->name(); - tmp.chop(2); - LayerBitmap* orgLayer = static_cast(layers()->findLayerByName(tmp)); - mObject->updateActiveFrames(currentFrame()); - if (colorLayer != nullptr) - { - colorLayer->getBitmapImageAtFrame(currentFrame())->toThinBlackLine(colorLayer->getBitmapImageAtFrame(currentFrame())); - orgLayer->getBitmapImageAtFrame(currentFrame())->restoreColoredLines(orgLayer->getBitmapImageAtFrame(currentFrame()), colorLayer->getBitmapImageAtFrame(currentFrame())); - mObject->updateActiveFrames(currentFrame()); - mScribbleArea->updateFrame(currentFrame()); - } -} - -void Editor::toThinBlackLineRest() -{ - LayerBitmap* colorLayer = static_cast(layers()->currentLayer()); - QString tmp = colorLayer->name(); - tmp.chop(2); - LayerBitmap* orgLayer = static_cast(layers()->findLayerByName(tmp)); - mObject->updateActiveFrames(currentFrame()); - for (int i = 1; i <= colorLayer->getMaxKeyFramePosition(); i++) - { - if (colorLayer->keyExists(i)) - { - scrubTo(i); - colorLayer->getBitmapImageAtFrame(currentFrame())->toThinBlackLine(colorLayer->getBitmapImageAtFrame(currentFrame())); - orgLayer->getBitmapImageAtFrame(currentFrame())->restoreColoredLines(orgLayer->getBitmapImageAtFrame(currentFrame()), colorLayer->getBitmapImageAtFrame(currentFrame())); - mObject->updateActiveFrames(currentFrame()); - mScribbleArea->updateFrame(currentFrame()); - } - } -} - -void Editor::replaceThinLines() -{ - LayerBitmap* colorBitmap = static_cast(layers()->currentLayer()); - QString tmp = colorBitmap->name(); - tmp.chop(2); - LayerBitmap* orgBitmap = static_cast(layers()->findLayerByName(tmp)); - for (int i = 1; i <= colorBitmap->getMaxKeyFramePosition(); i++) - { - if (colorBitmap->keyExists(i) && orgBitmap->keyExists(i)) - { - scrubTo(i); - colorBitmap->getBitmapImageAtFrame(currentFrame())->replaceThinLine(colorBitmap->getBitmapImageAtFrame(currentFrame())); - colorBitmap->setModified(currentFrame(),true); - orgBitmap->getBitmapImageAtFrame(currentFrame())->removeColoredLines(orgBitmap->getBitmapImageAtFrame(currentFrame())); - orgBitmap->setModified(currentFrame(), true); - mObject->updateActiveFrames(currentFrame()); - mScribbleArea->updateFrame(currentFrame()); - } - } -} - void Editor::clipboardChanged() { if (clipboardBitmapOk == false) diff --git a/core_lib/src/interface/editor.h b/core_lib/src/interface/editor.h index 6f9c5d7edb..9f50ff1ac2 100644 --- a/core_lib/src/interface/editor.h +++ b/core_lib/src/interface/editor.h @@ -151,15 +151,6 @@ class Editor : public QObject void toggleShowAllLayers(); void flipSelection(bool flipVertical); - void copyFromScan(); - void scanToTransparent(); - void toBlackLine(); - void fillWhiteAreas(); - void fillWhiteAreasRest(); - void toThinBlackLine(); - void toThinBlackLineRest(); - void replaceThinLines(); - void toogleOnionSkinType(); void settingUpdated(SETTING); diff --git a/core_lib/src/managers/layermanager.cpp b/core_lib/src/managers/layermanager.cpp index ad00deadf2..e080202143 100644 --- a/core_lib/src/managers/layermanager.cpp +++ b/core_lib/src/managers/layermanager.cpp @@ -266,6 +266,16 @@ Status LayerManager::deleteLayer(int index) return Status::ERROR_NEED_AT_LEAST_ONE_CAMERA_LAYER; } + // resets layer flag, if color layer is deleted + if (layer->getIsColorLayer()) + { + QString s = layer->name(); + s.chop(2); + Layer* artLayer = findLayerByName(s); + if (artLayer != nullptr) + artLayer->setHasColorLayer(false); + } + object()->deleteLayer(layer); // current layer is the last layer && we are deleting it diff --git a/core_lib/src/structure/layer.cpp b/core_lib/src/structure/layer.cpp index a3dffcf414..ad00fabfd7 100644 --- a/core_lib/src/structure/layer.cpp +++ b/core_lib/src/structure/layer.cpp @@ -50,26 +50,6 @@ Layer::~Layer() mKeyFrames.clear(); } -void Layer::copyFrames(Layer *fromLayer, Layer *toLayer, int firstFrame, int lastFrame, int startAt, int loops) -{ - for (int i = 0; i < loops; i++) - { - for (int j = firstFrame; j <= lastFrame; j++, startAt++) - { - if (fromLayer->keyExists(j)) - { - mObject->updateActiveFrames(j); - KeyFrame* keyframe = fromLayer->getKeyFrameAt(j); - KeyFrame* dupKey = keyframe->clone(); - if (toLayer->keyExists(startAt)) - toLayer->removeKeyFrame(startAt); - toLayer->addKeyFrame(startAt, dupKey); - toLayer->setModified(startAt, true); - } - } - } -} - void Layer::foreachKeyFrame(std::function action) { for (auto pair : mKeyFrames) diff --git a/core_lib/src/structure/layer.h b/core_lib/src/structure/layer.h index 7273e7be8f..e70ae4219d 100644 --- a/core_lib/src/structure/layer.h +++ b/core_lib/src/structure/layer.h @@ -69,8 +69,6 @@ class Layer : public QObject bool getHasColorLayer() { return mHasColorLayer; } void setIsColorLayer(bool b) { mIsColorLayer = b; } bool getIsColorLayer() { return mIsColorLayer; } - void copyFrames(Layer* fromLayer, Layer* toLayer, int firstFrame, int lastFrame, int startAt, int loops = 1); - virtual Status saveKeyFrameFile(KeyFrame*, QString dataPath) = 0; virtual void loadDomElement(QDomElement element, QString dataDirPath, ProgressCallback progressForward) = 0; From 1ad01acf67d4d8a876b9f4a964df45ceae0673d3 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 3 Mar 2019 23:03:19 +0100 Subject: [PATCH 044/100] Clean up: code, functions, includes, icons --- app/data/app.qrc | 3 -- app/data/icons/select_no.png | Bin 547 -> 0 bytes app/data/icons/select_ok.png | Bin 540 -> 0 bytes app/data/icons/select_yes.png | Bin 540 -> 0 bytes app/src/actioncommands.cpp | 1 - app/src/bitmapcoloring.cpp | 15 +++---- app/src/bitmapcoloring.h | 1 - app/src/mainwindow2.cpp | 10 ----- app/src/mainwindow2.h | 1 - app/ui/mainwindow2.ui | 5 --- core_lib/src/graphics/bitmap/bitmapimage.cpp | 42 +------------------ core_lib/src/graphics/bitmap/bitmapimage.h | 9 +--- core_lib/src/interface/editor.cpp | 1 - core_lib/src/structure/layerbitmap.h | 1 - 14 files changed, 8 insertions(+), 81 deletions(-) delete mode 100644 app/data/icons/select_no.png delete mode 100644 app/data/icons/select_ok.png delete mode 100644 app/data/icons/select_yes.png diff --git a/app/data/app.qrc b/app/data/app.qrc index 347e2ced6e..57457e1f36 100644 --- a/app/data/app.qrc +++ b/app/data/app.qrc @@ -61,9 +61,6 @@ icons/green.png icons/red.png icons/black.png - icons/select_ok.png - icons/select_no.png - icons/select_yes.png icons/onion-blue.png diff --git a/app/data/icons/select_no.png b/app/data/icons/select_no.png deleted file mode 100644 index 6589dda78e13235fffadfb513534587076f3c5f4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 547 zcmV+;0^I$HP)zS&es$5@R3qZHqwGaZ^HX4ltpwsDC2m$XsaktyG z>2%6$Hp9#?Gm4_%;o*UzC|Dnz+4|_rl5gL#7$YL`_jp8j_WHd6{QCN_3Ro_e6h%R+ z)!INzf7zzJogBV@mi@vaQZdMe!{N>d0cx+_?Idq2OcUCHxJ^9Kj(1m*Z6&66xx13X z!$TH}g#ctHCnx5dBhT|HNPm2h)ODZF{@sNT$n(6CU7y@YS(cbtB{$15>XRD*D9e)7 zYDKfzwDo!|E`&gg5&!Lz92^{Mz+~BfmnZoWH)*%q=DjC`z<4|sfaBxiYGKkc&F6Cg lXfzrYW85_LUgW9k{2OnPFmD?*L7@Nu002ovPDHLkV1mVL`kDX$ diff --git a/app/data/icons/select_ok.png b/app/data/icons/select_ok.png deleted file mode 100644 index ca717315734a24fc0daed50cefa8a01b5929100d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 540 zcmV+%0^|LOP)A-^F1;Hy$;u!*Jl307wx#m)~BxP*L>G4uh&y+EqR`krm4i< zd#2N=c<&3;*=!~O^pfFXu@L7R!{JZ?V(&e9o|kEfpsG0M@ZJ+eQStW7d{PYDvG&%t zN`uX2Qvd{Ox7)O@uN2_3K9_#Kuj}<%DgpNUeL>%Qk1>X)zdtI#kJei`_ci13Shw3P zS(X)-Q4|r!F-ek8tJO%7gsNZwd7$l-9H)oLk#v46$* zlDv@1U}Fr%m{N8TK|}~~X1QFJO4z=>QW3!zgNX3(_+G0jQ~;d+Ib?bCbD_qVB6!_= zSz_00HrefV0$>J%fyQxM)H;AXxOt}lU+=z>O9mwot+k~_0r+A-^F1;Hy$;u!*Jl307wx#m)~BxP*L>G4uh&y+EqR`krm4i< zd#2N=c<&3;*=!~O^pfFXu@L7R!{JZ?V(&e9o|kEfpsG0M@ZJ+eQStW7d{PYDvG&%t zN`uX2Qvd{Ox7)O@uN2_3K9_#Kuj}<%DgpNUeL>%Qk1>X)zdtI#kJei`_ci13Shw3P zS(X)-Q4|r!F-ek8tJO%7gsNZwd7$l-9H)oLk#v46$* zlDv@1U}Fr%m{N8TK|}~~X1QFJO4z=>QW3!zgNX3(_+G0jQ~;d+Ib?bCbD_qVB6!_= zSz_00HrefV0$>J%fyQxM)H;AXxOt}lU+=z>O9mwot+k~_0r+btnSelectAreas->setIcon(QIcon(":/icons/select.png")); connect(ui->cbLayerSelector, QOverload::of(&QComboBox::currentIndexChanged), this, &BitmapColoring::colorMethodChanged); - connect(mEditor->layers(), &LayerManager::currentLayerChanged, this, &BitmapColoring::layerChanged); // Prepare connect(ui->cb0Trace, &QCheckBox::stateChanged, this, &BitmapColoring::updateTraceBoxes); @@ -94,7 +93,7 @@ void BitmapColoring::updateUI() } } else - { + { // If it is not a Bitmap Layer - disable ui->tabPrepare->setEnabled(false); ui->tabThinLine->setEnabled(false); ui->tabFinish->setEnabled(false); @@ -126,12 +125,6 @@ void BitmapColoring::colorMethodChanged() } } -void BitmapColoring::layerChanged(int index) -{ - Q_UNUSED(index); - updateUI(); -} - void BitmapColoring::updateTraceBoxes() { if (ui->cb0Trace->isChecked()) @@ -215,6 +208,7 @@ void BitmapColoring::selectFromScans() ui->cb1Threshold->setChecked(false); } } + mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Select from scan")); } void BitmapColoring::prepareLines() @@ -263,6 +257,7 @@ void BitmapColoring::prepareLines() ui->cb2TraceRed->isChecked(), ui->cb2TraceGreen->isChecked(), ui->cb2TraceBlue->isChecked()); + mEditor->backup(mEditor->layers()->currentLayerIndex() ,mEditor->currentFrame(), tr("Preparelines")); } } updateUI(); @@ -322,12 +317,13 @@ void BitmapColoring::thinLines() if (ui->cb1Thin->isChecked()) { - mBitmapImage->toThinBlackLine(mBitmapImage, + mBitmapImage->toThinLine(mBitmapImage, ui->cb2ThinBlack->isChecked(), ui->cb2ThinRed->isChecked(), ui->cb2ThinGreen->isChecked(), ui->cb2ThinBlue->isChecked()); } + mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Thin lines")); } } updateUI(); @@ -392,6 +388,7 @@ void BitmapColoring::blendLines() ui->cb2FinishGreen->isChecked(), ui->cb2FinishBlue->isChecked()); } + mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Blend lines")); } } } diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 283bf9a074..519a4d89a3 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -30,7 +30,6 @@ class BitmapColoring : public BaseDockWidget public slots: void colorMethodChanged(); - void layerChanged(int index); // Prepare void updateTraceBoxes(); void updateBtnSelect(); diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index 063a0f94d2..bdaa46a0b4 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -1353,7 +1353,6 @@ void MainWindow2::makeConnections(Editor* pEditor, TimeLine* pTimeline) connect(pEditor->layers(), &LayerManager::currentLayerChanged, mToolOptions, &ToolOptionWidget::updateUI); connect(pEditor->layers(), &LayerManager::currentLayerChanged, mBitmapColoring, &BitmapColoring::updateUI); connect(mBitmapColoring, &QDockWidget::visibilityChanged, mBitmapColoring, &BitmapColoring::visibilityChanged); - connect(pEditor->layers(), &LayerManager::currentLayerChanged, this, &MainWindow2::updateLayerMenu); } void MainWindow2::makeConnections(Editor*, DisplayOptionWidget*) @@ -1409,15 +1408,6 @@ void MainWindow2::updateZoomLabel() statusBar()->showMessage(QString("Zoom: %0%1").arg(static_cast(zoom), 0, 'f', 1).arg("%")); } -void MainWindow2::updateLayerMenu() -{ - Layer* layer = mEditor->layers()->currentLayer(); - if (layer->type() == Layer::BITMAP && !layer->getHasColorLayer() && !layer->getIsColorLayer()) - ui->actionAdd_Bitmap_Color_Layer->setEnabled(true); - else - ui->actionAdd_Bitmap_Color_Layer->setEnabled(false); -} - void MainWindow2::changePlayState(bool isPlaying) { if (isPlaying) diff --git a/app/src/mainwindow2.h b/app/src/mainwindow2.h index 474f8b443b..881b2af628 100644 --- a/app/src/mainwindow2.h +++ b/app/src/mainwindow2.h @@ -112,7 +112,6 @@ private slots: void setupKeyboardShortcuts(); void clearKeyboardShortcuts(); void updateZoomLabel(); - void updateLayerMenu(); void importPalette(); void exportPalette(); diff --git a/app/ui/mainwindow2.ui b/app/ui/mainwindow2.ui index 0a87747868..763cd89509 100644 --- a/app/ui/mainwindow2.ui +++ b/app/ui/mainwindow2.ui @@ -964,11 +964,6 @@ 100% - - - Add Bitmap Color Layer - - Flip In-Between diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index acd8ff1544..d3ea35742b 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -20,7 +20,6 @@ GNU General Public License for more details. #include #include #include -#include #include "util.h" BitmapImage::BitmapImage() @@ -719,11 +718,6 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool black return img; } -void BitmapImage::getThresholdSuggestion(BitmapImage* img) -{ - Q_ASSERT(img != nullptr); // TODO -} - void BitmapImage::traceLine(BitmapImage* bitmapimage, bool black, bool red, bool green, bool blue) { Q_ASSERT(bitmapimage != nullptr); @@ -803,7 +797,7 @@ void BitmapImage::fillSpotAreas(BitmapImage *bitmapimage) img->modification(); } -void BitmapImage::toThinBlackLine(BitmapImage* colorImage, bool black, bool red, bool green, bool blue) +void BitmapImage::toThinLine(BitmapImage * colorImage, bool black, bool red, bool green, bool blue) { Q_ASSERT(colorImage != nullptr); @@ -1015,22 +1009,6 @@ void BitmapImage::toThinBlackLine(BitmapImage* colorImage, bool black, bool red, img->modification(); } -void BitmapImage::restoreColoredLines(BitmapImage *orgImage, BitmapImage *colorImage) -{ - Q_ASSERT(colorImage != nullptr); - - for (int x = colorImage->left(); x <= colorImage->right(); x++) - { - for (int y = colorImage->top(); y <= colorImage->bottom(); y++) - { - if (colorImage->constScanLine(x, y) == thinline) - if (orgImage->constScanLine(x,y) == redline || - orgImage->constScanLine(x,y) == blueline || orgImage->constScanLine(x,y) == greenline) - colorImage->setPixel(x, y, orgImage->constScanLine(x, y)); - } - } -} - void BitmapImage::blendLines(BitmapImage *bitmapimage, bool black, bool red, bool green, bool blue) { Q_ASSERT(bitmapimage != nullptr); @@ -1078,24 +1056,6 @@ void BitmapImage::blendLines(BitmapImage *bitmapimage, bool black, bool red, boo img->modification(); } -void BitmapImage::removeColoredLines(BitmapImage *bitmapimage) -{ - Q_ASSERT(bitmapimage != nullptr); - - BitmapImage* img = bitmapimage; - for (int x = img->left(); x <= img->right(); x++) - { - for (int y = img->top(); y <= img->bottom(); y++) - { - if (qRed(img->constScanLine(x, y)) == 254 || - qBlue(img->constScanLine(x,y)) == 254 || - qGreen(img->constScanLine(x, y) == 254)) - img->setPixel(x, y, transp); - } - } - img->modification(); -} - int BitmapImage::fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, BitmapImage *bitmapimage) { Q_ASSERT(bitmapimage != nullptr); diff --git a/core_lib/src/graphics/bitmap/bitmapimage.h b/core_lib/src/graphics/bitmap/bitmapimage.h index dec88692f3..858d3199f3 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.h +++ b/core_lib/src/graphics/bitmap/bitmapimage.h @@ -108,18 +108,11 @@ class BitmapImage : public KeyFrame int getThreshold() { return mThreshold; } int getSpotArea() { return mSpotArea; } BitmapImage* scanToTransparent(BitmapImage* bitmapimage, bool black, bool red, bool green, bool blue); - - void getThresholdSuggestion(BitmapImage* img); void traceLine(BitmapImage* bitmapimage, bool black, bool red, bool green, bool blue); - void fillSpotAreas(BitmapImage* bitmapimage); - void toThinBlackLine(BitmapImage* colorImage, bool black, bool red, bool green, bool blue); - void restoreColoredLines(BitmapImage* orgImage, BitmapImage* colorImage); + void toThinLine(BitmapImage* colorImage, bool black, bool red, bool green, bool blue); void blendLines(BitmapImage* bitmapimage, bool black, bool red, bool green, bool blue); - void removeColoredLines(BitmapImage* bitmapimage); int fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, BitmapImage* bitmapimage); - // coloring methods end - /** Determines if the BitmapImage is minimally bounded. * diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 7698a0d1e6..80c7132716 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -772,7 +772,6 @@ bool Editor::importBitmapImage(QString filePath, int space) BitmapImage importedBitmapImage(mScribbleArea->getCentralPoint().toPoint() - QPoint(img.width() / 2, img.height() / 2), img); bitmapImage->paste(&importedBitmapImage); -// layer->toTransparentScan(currentFrame()); if (space > 1) { scrubTo(currentFrame() + space); diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index d90782bb3b..1af09053f9 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -47,7 +47,6 @@ class LayerBitmap : public Layer QString filePath(KeyFrame* key, const QDir& dataFolder) const; QString fileName(KeyFrame* key) const; bool needSaveFrame(KeyFrame* key, const QString& strSavePath); - }; #endif From 04b83f3b7f89ca5d8a888fd5389814db4a227ebd Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Mon, 4 Mar 2019 12:57:06 +0100 Subject: [PATCH 045/100] Check/Uncheck on Prepare tab, are copied to other tabs --- app/src/bitmapcoloring.cpp | 35 +++++++++++++++++++++++++++++++++++ app/src/bitmapcoloring.h | 5 +++++ 2 files changed, 40 insertions(+) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index ef39b246ef..be405314f1 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -35,6 +35,11 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : ui->btnSelectAreas->setIcon(QIcon(":/icons/select.png")); connect(ui->cbLayerSelector, QOverload::of(&QComboBox::currentIndexChanged), this, &BitmapColoring::colorMethodChanged); + connect(ui->cb2TraceBlack, &QCheckBox::stateChanged, this, &BitmapColoring::checkBlackBoxes); + connect(ui->cb2TraceRed, &QCheckBox::stateChanged, this, &BitmapColoring::checkRedBoxes); + connect(ui->cb2TraceGreen, &QCheckBox::stateChanged, this, &BitmapColoring::checkGreenBoxes); + connect(ui->cb2TraceBlue, &QCheckBox::stateChanged, this, &BitmapColoring::checkBlueBoxes); + connect(ui->cb3TraceAllKeyframes, &QCheckBox::stateChanged, this, &BitmapColoring::checkAllKeyframes); // Prepare connect(ui->cb0Trace, &QCheckBox::stateChanged, this, &BitmapColoring::updateTraceBoxes); @@ -125,6 +130,36 @@ void BitmapColoring::colorMethodChanged() } } +void BitmapColoring::checkBlackBoxes() +{ + ui->cb2ThinBlack->setChecked(ui->cb2TraceBlack->isChecked()); + ui->cb2FinishBlack->setChecked(ui->cb2TraceBlack->isChecked()); +} + +void BitmapColoring::checkRedBoxes() +{ + ui->cb2ThinRed->setChecked(ui->cb2TraceRed->isChecked()); + ui->cb2FinishRed->setChecked(ui->cb2TraceRed->isChecked()); +} + +void BitmapColoring::checkGreenBoxes() +{ + ui->cb2ThinGreen->setChecked(ui->cb2TraceGreen->isChecked()); + ui->cb2FinishGreen->setChecked(ui->cb2TraceGreen->isChecked()); +} + +void BitmapColoring::checkBlueBoxes() +{ + ui->cb2ThinBlue->setChecked(ui->cb2TraceBlue->isChecked()); + ui->cb2FinishBlue->setChecked(ui->cb2TraceBlue->isChecked()); +} + +void BitmapColoring::checkAllKeyframes() +{ + ui->cb3ThinAllKeyframes->setChecked(ui->cb3TraceAllKeyframes->isChecked()); + ui->cb3FinishAllKeyframes->setChecked(ui->cb3TraceAllKeyframes->isChecked()); +} + void BitmapColoring::updateTraceBoxes() { if (ui->cb0Trace->isChecked()) diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 519a4d89a3..c4bbf5bb32 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -30,6 +30,11 @@ class BitmapColoring : public BaseDockWidget public slots: void colorMethodChanged(); + void checkBlackBoxes(); + void checkRedBoxes(); + void checkGreenBoxes(); + void checkBlueBoxes(); + void checkAllKeyframes(); // Prepare void updateTraceBoxes(); void updateBtnSelect(); From f695d775079182af1f5c3a54392a5fae90c752cd Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Mon, 4 Mar 2019 19:13:13 +0100 Subject: [PATCH 046/100] Select and trace in one go --- app/data/app.qrc | 1 + app/data/icons/select_ok.png | Bin 0 -> 542 bytes app/src/bitmapcoloring.cpp | 77 +++++++++++++++++++++++++---------- app/src/bitmapcoloring.h | 2 + 4 files changed, 59 insertions(+), 21 deletions(-) create mode 100644 app/data/icons/select_ok.png diff --git a/app/data/app.qrc b/app/data/app.qrc index 57457e1f36..e90838d7d2 100644 --- a/app/data/app.qrc +++ b/app/data/app.qrc @@ -61,6 +61,7 @@ icons/green.png icons/red.png icons/black.png + icons/select_ok.png icons/onion-blue.png diff --git a/app/data/icons/select_ok.png b/app/data/icons/select_ok.png new file mode 100644 index 0000000000000000000000000000000000000000..b5fa4a21178b564966bdc130ef36b612dc54c032 GIT binary patch literal 542 zcmV+(0^$9MP)MFT@zOlQc?UwCD9D)eQ&-g}&L6h$FcRhiG{qN=s(VzH1UdY<8GwUQ75`2S`NT{J0TJQ)=ZARCA?;V+-__2C!-4&N zPp{XD04BjWO))teV|e}TZ6mUXAR;wHvtF+oCA?T&MiIdn!>g~?5#a9gZ#l0}5|9`p zyWI|JEpL9jf6|usH@5=N>2v_7s)}y6`^aE48pTw$b3peux01ed&ZZXd-ZvWMR3w!z z?de=q743HW*ooeILI{nfdH8ZC{~Mkpmbl4aFo@1My!RAEApre;zaE%0Ol4Un7BPfC g2m$Au$aBZ}FKcbcb0Trace, &QCheckBox::stateChanged, this, &BitmapColoring::updateTraceBoxes); connect(ui->cb1Threshold, &QCheckBox::stateChanged, this, &BitmapColoring::updateBtnSelect); connect(ui->sb1Threshold, QOverload::of(&QSpinBox::valueChanged), this, &BitmapColoring::setThreshold); - connect(ui->btnSelectAreas, &QPushButton::clicked, this, &BitmapColoring::selectAreas); + connect(ui->btnSelectAreas, &QPushButton::clicked, this, &BitmapColoring::updateSelectButtonIcon); connect(ui->btnSelectNext, &QPushButton::clicked, this, &BitmapColoring::selectFromScans); connect(ui->btnSelectCancel, &QPushButton::clicked, this, &BitmapColoring::cancelSelectAreas); - connect(ui->btnApplyPrepare, &QPushButton::clicked, this, &BitmapColoring::prepareLines); + connect(ui->btnApplyPrepare, &QPushButton::clicked, this, &BitmapColoring::traceLines); // Thin connect(ui->cb1Thin, &QCheckBox::stateChanged, this, &BitmapColoring::updateThinBoxes); connect(ui->sbSpotAreas, QOverload::of(&QSpinBox::valueChanged), this, &BitmapColoring::setSpotArea); @@ -130,6 +130,20 @@ void BitmapColoring::colorMethodChanged() } } +void BitmapColoring::updateSelectButtonIcon() +{ + if (mSelectAreas) + { + mSelectAreas = false; + ui->btnSelectAreas->setIcon(QIcon(":/icons/select.png")); + } + else + { + mSelectAreas = true; + ui->btnSelectAreas->setIcon(QIcon(":/icons/select_ok.png")); + } +} + void BitmapColoring::checkBlackBoxes() { ui->cb2ThinBlack->setChecked(ui->cb2TraceBlack->isChecked()); @@ -218,6 +232,18 @@ void BitmapColoring::cancelSelectAreas() ui->btnSelectCancel->setEnabled(false); } +void BitmapColoring::traceLines() +{ + if (ui->cb1Threshold->isChecked()) + { + selectAreas(); + } + else + { + prepareLines(); + } +} + void BitmapColoring::selectFromScans() { ScribbleArea* scribble = mEditor->getScribbleArea(); @@ -233,60 +259,69 @@ void BitmapColoring::selectFromScans() ui->cb2TraceRed->isChecked(), ui->cb2TraceGreen->isChecked(), ui->cb2TraceBlue->isChecked()); - if (mEditor->currentFrame() < mEditor->layers()->currentLayer()->getMaxKeyFramePosition()) - { - mEditor->scrubNextKeyFrame(); - } - else - { - cancelSelectAreas(); - ui->cb1Threshold->setChecked(false); - } + } + if (ui->cb0Trace->isChecked()) + { + prepareLines(); } mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Select from scan")); + if (mEditor->currentFrame() < mEditor->layers()->currentLayer()->getMaxKeyFramePosition()) + { + mEditor->scrubNextKeyFrame(); + } + else + { + cancelSelectAreas(); + ui->cb1Threshold->setChecked(false); + } } void BitmapColoring::prepareLines() { if (mLayerBitmap == nullptr) { return; } - ui->tabPrepare->setEnabled(false); + if (!ui->cb1Threshold->isChecked()) + ui->tabPrepare->setEnabled(false); // if a separate layer is needed, we make one LayerBitmap* colorLayer = nullptr; if (ui->cbLayerSelector->currentIndex() == 0) - { + { // if coloring is on same layer... colorLayer = mLayerBitmap; } else - { + { // if coloring is on separate layer... if (!mLayerBitmap->getHasColorLayer()) { colorLayer = mEditor->layers()->createBitmapLayer(mLayerBitmap->name() + "_C"); mLayerBitmap->setHasColorLayer(true); colorLayer->setIsColorLayer(true); - mEditor->layers()->copyLayer(mLayerBitmap, colorLayer); } else { colorLayer = static_cast(mEditor->layers()->findLayerByName(mLayerBitmap->name() + "_C")); } } + if (ui->cbLayerSelector->currentIndex() == 1) + colorLayer->setVisible(false); int firstFrame = 1, lastFrame = 1; - if (ui->cb3TraceAllKeyframes->isChecked()) + if (!ui->cb3TraceAllKeyframes->isChecked() || ui->cb1Threshold->isChecked()) { - lastFrame = colorLayer->getMaxKeyFramePosition(); + firstFrame = mEditor->currentFrame(); + lastFrame = firstFrame; } else { - firstFrame = mEditor->currentFrame(); - lastFrame = firstFrame; + lastFrame = mLayerBitmap->getMaxKeyFramePosition(); } for (int i = firstFrame; i <= lastFrame; i++) { - if (colorLayer->keyExists(i)) + if (mLayerBitmap->keyExists(i)) { mEditor->scrubTo(i); + emit mEditor->updateTimeLine(); + if (ui->cbLayerSelector->currentIndex() == 1) + mLayerBitmap->copyFrame(mLayerBitmap, colorLayer, i); colorLayer->getBitmapImageAtFrame(i)->traceLine(colorLayer->getBitmapImageAtFrame(i), ui->cb2TraceBlack->isChecked(), ui->cb2TraceRed->isChecked(), @@ -295,7 +330,7 @@ void BitmapColoring::prepareLines() mEditor->backup(mEditor->layers()->currentLayerIndex() ,mEditor->currentFrame(), tr("Preparelines")); } } - updateUI(); +// updateUI(); } void BitmapColoring::updateThinBoxes() diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index c4bbf5bb32..89f76430ad 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -30,6 +30,7 @@ class BitmapColoring : public BaseDockWidget public slots: void colorMethodChanged(); + void updateSelectButtonIcon(); void checkBlackBoxes(); void checkRedBoxes(); void checkGreenBoxes(); @@ -41,6 +42,7 @@ public slots: void setThreshold(int threshold); void selectAreas(); void cancelSelectAreas(); + void traceLines(); void selectFromScans(); void prepareLines(); // Thin From 2108de18c0077f1eea354eb050341d3f791cfd80 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Mon, 4 Mar 2019 19:45:56 +0100 Subject: [PATCH 047/100] Cleaning up code --- app/src/bitmapcoloring.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 9f1e5af664..37b02120b8 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -280,9 +280,6 @@ void BitmapColoring::prepareLines() { if (mLayerBitmap == nullptr) { return; } - if (!ui->cb1Threshold->isChecked()) - ui->tabPrepare->setEnabled(false); - // if a separate layer is needed, we make one LayerBitmap* colorLayer = nullptr; if (ui->cbLayerSelector->currentIndex() == 0) @@ -319,7 +316,6 @@ void BitmapColoring::prepareLines() if (mLayerBitmap->keyExists(i)) { mEditor->scrubTo(i); - emit mEditor->updateTimeLine(); if (ui->cbLayerSelector->currentIndex() == 1) mLayerBitmap->copyFrame(mLayerBitmap, colorLayer, i); colorLayer->getBitmapImageAtFrame(i)->traceLine(colorLayer->getBitmapImageAtFrame(i), @@ -330,7 +326,6 @@ void BitmapColoring::prepareLines() mEditor->backup(mEditor->layers()->currentLayerIndex() ,mEditor->currentFrame(), tr("Preparelines")); } } -// updateUI(); } void BitmapColoring::updateThinBoxes() @@ -361,8 +356,6 @@ void BitmapColoring::thinLines() if (mLayerBitmap == nullptr) { return; } mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->layers()->currentLayer()->getMaxKeyFramePosition()); - ui->tabThinLine->setEnabled(false); - int firstFrame = 1, lastFrame = 1; if (ui->cb3ThinAllKeyframes->isChecked()) { @@ -426,8 +419,6 @@ void BitmapColoring::blendLines() orgName.chop(2); LayerBitmap* artLayer = static_cast(mEditor->layers()->findLayerByName(orgName)); - ui->tabFinish->setEnabled(false); - int firstFrame = 1, lastFrame = 1; if (ui->cb3FinishAllKeyframes->isChecked()) { From c53ee44fb39caa98651fcfe55fb5e5452fe18df8 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Tue, 5 Mar 2019 13:35:04 +0100 Subject: [PATCH 048/100] Select integrated in trace feature --- app/src/bitmapcoloring.cpp | 141 ++++++++++--------- app/src/bitmapcoloring.h | 13 +- app/ui/bitmapcoloringwidget.ui | 75 +++++----- core_lib/src/graphics/bitmap/bitmapimage.cpp | 10 +- core_lib/src/graphics/bitmap/bitmapimage.h | 2 +- core_lib/src/interface/scribblearea.h | 1 + core_lib/src/tool/selecttool.cpp | 1 + 7 files changed, 120 insertions(+), 123 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 37b02120b8..854e82bf5c 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -13,10 +13,12 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ + +#include #include "bitmapcoloring.h" #include "ui_bitmapcoloringwidget.h" #include "layermanager.h" -#include "scribblearea.h" + BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : BaseDockWidget(parent) @@ -29,6 +31,7 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : setWidget(innerWidget); mEditor = editor; + mScribblearea = mEditor->getScribbleArea(); if (mEditor->layers()->currentLayer()->type() == Layer::BITMAP) mLayerBitmap = static_cast(mEditor->layers()->currentLayer()); mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); @@ -40,14 +43,13 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : connect(ui->cb2TraceGreen, &QCheckBox::stateChanged, this, &BitmapColoring::checkGreenBoxes); connect(ui->cb2TraceBlue, &QCheckBox::stateChanged, this, &BitmapColoring::checkBlueBoxes); connect(ui->cb3TraceAllKeyframes, &QCheckBox::stateChanged, this, &BitmapColoring::checkAllKeyframes); + connect(mScribblearea, &ScribbleArea::newSelectionMade, this, &BitmapColoring::selectYesNo); // Prepare connect(ui->cb0Trace, &QCheckBox::stateChanged, this, &BitmapColoring::updateTraceBoxes); connect(ui->cb1Threshold, &QCheckBox::stateChanged, this, &BitmapColoring::updateBtnSelect); connect(ui->sb1Threshold, QOverload::of(&QSpinBox::valueChanged), this, &BitmapColoring::setThreshold); - connect(ui->btnSelectAreas, &QPushButton::clicked, this, &BitmapColoring::updateSelectButtonIcon); - connect(ui->btnSelectNext, &QPushButton::clicked, this, &BitmapColoring::selectFromScans); - connect(ui->btnSelectCancel, &QPushButton::clicked, this, &BitmapColoring::cancelSelectAreas); + connect(ui->btnSelectAreas, &QPushButton::clicked, this, &BitmapColoring::updateSelectButton); connect(ui->btnApplyPrepare, &QPushButton::clicked, this, &BitmapColoring::traceLines); // Thin connect(ui->cb1Thin, &QCheckBox::stateChanged, this, &BitmapColoring::updateThinBoxes); @@ -130,7 +132,7 @@ void BitmapColoring::colorMethodChanged() } } -void BitmapColoring::updateSelectButtonIcon() +void BitmapColoring::updateSelectButton() { if (mSelectAreas) { @@ -200,6 +202,8 @@ void BitmapColoring::updateBtnSelect() } else { + mSelectAreas = false; + ui->btnSelectAreas->setIcon(QIcon(":/icons/select.png")); ui->btnSelectAreas->setEnabled(false); } } @@ -209,79 +213,94 @@ void BitmapColoring::setThreshold(int threshold) mBitmapImage->setThreshold(threshold); } -void BitmapColoring::selectAreas() +void BitmapColoring::traceLines() { - ui->gb0Prepare->setEnabled(false); - ui->gb1Prepare->setEnabled(false); - ui->gb2Prepare->setEnabled(false); - ui->gb3Prepare->setEnabled(false); - ui->btnApplyPrepare->setEnabled(false); - ui->btnSelectNext->setEnabled(true); - ui->btnSelectCancel->setEnabled(true); - mEditor->scrubTo(1); -} + if (mSelectAreas) + { + QMessageBox::information( + this, + tr("Please select"), + tr("Select from scanned drawings...")); + mEditor->scrubTo(1); + return; + } + + if (ui->cb3TraceAllKeyframes->isChecked()) + { + for (int i = 1; i <= mLayerBitmap->getMaxKeyFramePosition(); i++) + { + if (mLayerBitmap->keyExists(i)) + { + mEditor->scrubTo(i); + if (ui->cb1Threshold->isChecked()) + { + traceScansToTransparent(); + } + prepareLines(); + emit mEditor->updateTimeLine(); + } + } + } + else if (mLayerBitmap->keyExists(mEditor->currentFrame())) + { + if (ui->cb1Threshold->isChecked()) + traceScansToTransparent(); + prepareLines(); + emit mEditor->updateTimeLine(); + } -void BitmapColoring::cancelSelectAreas() -{ - ui->gb0Prepare->setEnabled(true); - ui->gb1Prepare->setEnabled(true); - ui->gb2Prepare->setEnabled(true); - ui->gb3Prepare->setEnabled(true); - ui->btnApplyPrepare->setEnabled(true); - ui->btnSelectNext->setEnabled(false); - ui->btnSelectCancel->setEnabled(false); } -void BitmapColoring::traceLines() +void BitmapColoring::selectYesNo() { - if (ui->cb1Threshold->isChecked()) - { - selectAreas(); - } - else + if (mSelectAreas && mLayerBitmap->keyExists(mEditor->currentFrame())) { + traceScansToTransparent(); prepareLines(); + nextKey(); } } -void BitmapColoring::selectFromScans() +void BitmapColoring::traceScansToTransparent() { - ScribbleArea* scribble = mEditor->getScribbleArea(); - if (scribble->isSomethingSelected()) + if (mSelectAreas) { mEditor->copy(); mEditor->layers()->currentLayer()->removeKeyFrame(mEditor->currentFrame()); mEditor->layers()->currentLayer()->addNewKeyFrameAt(mEditor->currentFrame()); mEditor->paste(); - mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); - mBitmapImage = mBitmapImage->scanToTransparent(mBitmapImage, - true, - ui->cb2TraceRed->isChecked(), - ui->cb2TraceGreen->isChecked(), - ui->cb2TraceBlue->isChecked()); - } - if (ui->cb0Trace->isChecked()) - { - prepareLines(); } + mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); + mBitmapImage = mBitmapImage->scanToTransparent(mBitmapImage, + true, + ui->cb2TraceRed->isChecked(), + ui->cb2TraceGreen->isChecked(), + ui->cb2TraceBlue->isChecked()); + mScribblearea->deselectAll(); + mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Select from scan")); +} + +void BitmapColoring::nextKey() +{ if (mEditor->currentFrame() < mEditor->layers()->currentLayer()->getMaxKeyFramePosition()) { mEditor->scrubNextKeyFrame(); } else { - cancelSelectAreas(); ui->cb1Threshold->setChecked(false); + updateBtnSelect(); // includes 'mSelectAreas = false' } } void BitmapColoring::prepareLines() { if (mLayerBitmap == nullptr) { return; } + if (!mLayerBitmap->keyExists(mEditor->currentFrame())) { return; } - // if a separate layer is needed, we make one LayerBitmap* colorLayer = nullptr; + // if a separate layer is needed, we make one if (ui->cbLayerSelector->currentIndex() == 0) { // if coloring is on same layer... colorLayer = mLayerBitmap; @@ -300,32 +319,16 @@ void BitmapColoring::prepareLines() } if (ui->cbLayerSelector->currentIndex() == 1) - colorLayer->setVisible(false); - int firstFrame = 1, lastFrame = 1; - if (!ui->cb3TraceAllKeyframes->isChecked() || ui->cb1Threshold->isChecked()) { - firstFrame = mEditor->currentFrame(); - lastFrame = firstFrame; - } - else - { - lastFrame = mLayerBitmap->getMaxKeyFramePosition(); - } - for (int i = firstFrame; i <= lastFrame; i++) - { - if (mLayerBitmap->keyExists(i)) - { - mEditor->scrubTo(i); - if (ui->cbLayerSelector->currentIndex() == 1) - mLayerBitmap->copyFrame(mLayerBitmap, colorLayer, i); - colorLayer->getBitmapImageAtFrame(i)->traceLine(colorLayer->getBitmapImageAtFrame(i), - ui->cb2TraceBlack->isChecked(), - ui->cb2TraceRed->isChecked(), - ui->cb2TraceGreen->isChecked(), - ui->cb2TraceBlue->isChecked()); - mEditor->backup(mEditor->layers()->currentLayerIndex() ,mEditor->currentFrame(), tr("Preparelines")); - } + colorLayer->setVisible(false); + mLayerBitmap->copyFrame(mLayerBitmap, colorLayer, mEditor->currentFrame()); } + colorLayer->getBitmapImageAtFrame(mEditor->currentFrame())->traceLine(colorLayer->getBitmapImageAtFrame(mEditor->currentFrame()), + ui->cb2TraceBlack->isChecked(), + ui->cb2TraceRed->isChecked(), + ui->cb2TraceGreen->isChecked(), + ui->cb2TraceBlue->isChecked()); + mEditor->backup(mEditor->layers()->currentLayerIndex() ,mEditor->currentFrame(), tr("Preparelines")); } void BitmapColoring::updateThinBoxes() diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 89f76430ad..adcee40b63 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -6,6 +6,7 @@ #include "layerbitmap.h" #include "bitmapimage.h" #include +#include "scribblearea.h" class Layer; @@ -26,11 +27,13 @@ class BitmapColoring : public BaseDockWidget void updateUI() override; void visibilityChanged(bool visibility); + void prepareLines(); + signals: public slots: void colorMethodChanged(); - void updateSelectButtonIcon(); + void updateSelectButton(); void checkBlackBoxes(); void checkRedBoxes(); void checkGreenBoxes(); @@ -40,11 +43,10 @@ public slots: void updateTraceBoxes(); void updateBtnSelect(); void setThreshold(int threshold); - void selectAreas(); - void cancelSelectAreas(); void traceLines(); - void selectFromScans(); - void prepareLines(); + void selectYesNo(); + void traceScansToTransparent(); + void nextKey(); // Thin void updateThinBoxes(); void setSpotArea(int size); @@ -56,6 +58,7 @@ public slots: private: Ui::BitmapColoringWidget* ui = nullptr; Editor* mEditor = nullptr; + ScribbleArea* mScribblearea = nullptr; LayerBitmap* mLayerBitmap = nullptr; BitmapImage* mBitmapImage = nullptr; bool mSelectAreas = false; diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index 4e9c040426..6876ca4752 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -137,6 +137,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -150,11 +163,30 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + false + + + 24 + 16777215 + + Select areas from scanned Drawings @@ -366,49 +398,6 @@ - - - - - - false - - - Select - and go to next keyframe - - - Select - Next - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - false - - - Cancel select areas - - - Cancel - - - - - diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index d3ea35742b..5371247921 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -754,7 +754,7 @@ void BitmapImage::traceLine(BitmapImage* bitmapimage, bool black, bool red, bool } else if(black) { - img->setPixel(x, y, thinline); + img->setPixel(x, y, blackline); } } } @@ -770,7 +770,7 @@ void BitmapImage::fillSpotAreas(BitmapImage *bitmapimage) // fill areas size 'area' or less with appropriate color QVector points; points.clear(); - QRgb active, previous = thinline; + QRgb active, previous = blackline; for (int x = img->left(); x < img->right(); x++) { for (int y = img->top(); y < img->bottom(); y++) @@ -805,7 +805,7 @@ void BitmapImage::toThinLine(BitmapImage * colorImage, bool black, bool red, boo bool N = true, E = true, S = true, W = true, pixelRemoved, search; QList colors; - if (black) colors.append(thinline); + if (black) colors.append(blackline); if (red) colors.append(redline); if (green) colors.append(greenline); if (blue) colors.append(blueline); @@ -819,7 +819,7 @@ void BitmapImage::toThinLine(BitmapImage * colorImage, bool black, bool red, boo // set 'pixelRemoved' to false. 'pixelRemoved' is set to true whenever a pixel is removed pixelRemoved = false; // 'search' is true while pixels are transparent - // when thinline pixel is found, 'search' is set to false until next transparent pixel + // when blackline pixel is found, 'search' is set to false until next transparent pixel search = true; for (int x = img->left(); x < img->right(); x++) { @@ -1018,7 +1018,7 @@ void BitmapImage::blendLines(BitmapImage *bitmapimage, bool black, bool red, boo int r, g, b, a; //red, green, blue, alpha QList points; // QPoints to add in calculation QList rgblist; // QRgb's that should be excluded - if (black) rgblist << thinline; + if (black) rgblist << blackline; if (red) rgblist << redline; if (green) rgblist << greenline; if (blue) rgblist << blueline; diff --git a/core_lib/src/graphics/bitmap/bitmapimage.h b/core_lib/src/graphics/bitmap/bitmapimage.h index 858d3199f3..783a5ac5d5 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.h +++ b/core_lib/src/graphics/bitmap/bitmapimage.h @@ -29,8 +29,8 @@ class BitmapImage : public KeyFrame { public: const QRgb transp = qRgba(0, 0, 0, 0); - const QRgb thinline = qRgba(1, 0, 0, 255); const QRgb rosa = qRgba(255,230,230,255); + const QRgb blackline = qRgba(1, 0, 0, 255); const QRgb redline = qRgba(254,0,0,255); const QRgb greenline = qRgba(0,254,0,255); const QRgb blueline = qRgba(0,0,254,255); diff --git a/core_lib/src/interface/scribblearea.h b/core_lib/src/interface/scribblearea.h index 800e362e20..a8683a1b36 100644 --- a/core_lib/src/interface/scribblearea.h +++ b/core_lib/src/interface/scribblearea.h @@ -141,6 +141,7 @@ class ScribbleArea : public QWidget void modification(int); void multiLayerOnionSkinChanged(bool); void refreshPreview(); + void newSelectionMade(); public slots: void clearImage(); diff --git a/core_lib/src/tool/selecttool.cpp b/core_lib/src/tool/selecttool.cpp index 956387920c..34875c2b22 100644 --- a/core_lib/src/tool/selecttool.cpp +++ b/core_lib/src/tool/selecttool.cpp @@ -138,6 +138,7 @@ void SelectTool::pointerReleaseEvent(PointerEvent* event) else { keepSelection(); + emit mScribbleArea->newSelectionMade(); } mScribbleArea->updateToolCursor(); From 373a4cd836e89a88c616e4b8127c91a95a1b483e Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Tue, 5 Mar 2019 19:40:09 +0100 Subject: [PATCH 049/100] Set flag to avoid unwanted select --- app/src/bitmapcoloring.cpp | 12 ++++++------ app/src/bitmapcoloring.h | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 854e82bf5c..aac9801d50 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -43,7 +43,7 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : connect(ui->cb2TraceGreen, &QCheckBox::stateChanged, this, &BitmapColoring::checkGreenBoxes); connect(ui->cb2TraceBlue, &QCheckBox::stateChanged, this, &BitmapColoring::checkBlueBoxes); connect(ui->cb3TraceAllKeyframes, &QCheckBox::stateChanged, this, &BitmapColoring::checkAllKeyframes); - connect(mScribblearea, &ScribbleArea::newSelectionMade, this, &BitmapColoring::selectYesNo); + connect(mScribblearea, &ScribbleArea::newSelectionMade, this, &BitmapColoring::selectarea); // Prepare connect(ui->cb0Trace, &QCheckBox::stateChanged, this, &BitmapColoring::updateTraceBoxes); @@ -215,6 +215,7 @@ void BitmapColoring::setThreshold(int threshold) void BitmapColoring::traceLines() { + mApplyPressed = true; // to give access to select from scan if (mSelectAreas) { QMessageBox::information( @@ -224,6 +225,7 @@ void BitmapColoring::traceLines() mEditor->scrubTo(1); return; } + mApplyPressed = false; // to close access to select from scan if (ui->cb3TraceAllKeyframes->isChecked()) { @@ -248,12 +250,11 @@ void BitmapColoring::traceLines() prepareLines(); emit mEditor->updateTimeLine(); } - } -void BitmapColoring::selectYesNo() +void BitmapColoring::selectarea() { - if (mSelectAreas && mLayerBitmap->keyExists(mEditor->currentFrame())) + if (mApplyPressed && mSelectAreas && mLayerBitmap->keyExists(mEditor->currentFrame())) { traceScansToTransparent(); prepareLines(); @@ -277,7 +278,6 @@ void BitmapColoring::traceScansToTransparent() ui->cb2TraceGreen->isChecked(), ui->cb2TraceBlue->isChecked()); mScribblearea->deselectAll(); - mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Select from scan")); } @@ -291,6 +291,7 @@ void BitmapColoring::nextKey() { ui->cb1Threshold->setChecked(false); updateBtnSelect(); // includes 'mSelectAreas = false' + mApplyPressed = false; } } @@ -369,7 +370,6 @@ void BitmapColoring::thinLines() firstFrame = mEditor->currentFrame(); lastFrame = firstFrame; } - mBitmapImage->setSpotArea(ui->sbSpotAreas->value()); for (int i = firstFrame; i <= lastFrame; i++) { if (mLayerBitmap->keyExists(i)) diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index adcee40b63..4474aa138a 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -44,7 +44,7 @@ public slots: void updateBtnSelect(); void setThreshold(int threshold); void traceLines(); - void selectYesNo(); + void selectarea(); void traceScansToTransparent(); void nextKey(); // Thin @@ -62,6 +62,7 @@ public slots: LayerBitmap* mLayerBitmap = nullptr; BitmapImage* mBitmapImage = nullptr; bool mSelectAreas = false; + bool mApplyPressed = false; }; From 7447ba38e5f50521b128263f371fbe79ab74600e Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Wed, 6 Mar 2019 21:54:37 +0100 Subject: [PATCH 050/100] New select routine consistent to Apply --- app/src/bitmapcoloring.cpp | 164 +++++++++++++------------- app/src/bitmapcoloring.h | 17 ++- app/ui/bitmapcoloringwidget.ui | 60 ++++++---- core_lib/src/interface/scribblearea.h | 1 - core_lib/src/tool/selecttool.cpp | 1 - 5 files changed, 124 insertions(+), 119 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index aac9801d50..0f1d3d3599 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -18,6 +18,7 @@ GNU General Public License for more details. #include "bitmapcoloring.h" #include "ui_bitmapcoloringwidget.h" #include "layermanager.h" +#include "toolmanager.h" BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : @@ -36,20 +37,23 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : mLayerBitmap = static_cast(mEditor->layers()->currentLayer()); mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); ui->btnSelectAreas->setIcon(QIcon(":/icons/select.png")); + checkBlackBoxes(); + checkRedBoxes(); + checkGreenBoxes(); + checkBlueBoxes(); - connect(ui->cbLayerSelector, QOverload::of(&QComboBox::currentIndexChanged), this, &BitmapColoring::colorMethodChanged); + connect(ui->cbMethodSelector, QOverload::of(&QComboBox::currentIndexChanged), this, &BitmapColoring::colorMethodChanged); connect(ui->cb2TraceBlack, &QCheckBox::stateChanged, this, &BitmapColoring::checkBlackBoxes); connect(ui->cb2TraceRed, &QCheckBox::stateChanged, this, &BitmapColoring::checkRedBoxes); connect(ui->cb2TraceGreen, &QCheckBox::stateChanged, this, &BitmapColoring::checkGreenBoxes); connect(ui->cb2TraceBlue, &QCheckBox::stateChanged, this, &BitmapColoring::checkBlueBoxes); connect(ui->cb3TraceAllKeyframes, &QCheckBox::stateChanged, this, &BitmapColoring::checkAllKeyframes); - connect(mScribblearea, &ScribbleArea::newSelectionMade, this, &BitmapColoring::selectarea); // Prepare connect(ui->cb0Trace, &QCheckBox::stateChanged, this, &BitmapColoring::updateTraceBoxes); connect(ui->cb1Threshold, &QCheckBox::stateChanged, this, &BitmapColoring::updateBtnSelect); connect(ui->sb1Threshold, QOverload::of(&QSpinBox::valueChanged), this, &BitmapColoring::setThreshold); - connect(ui->btnSelectAreas, &QPushButton::clicked, this, &BitmapColoring::updateSelectButton); + connect(ui->btnSelectAreas, &QPushButton::clicked, this, &BitmapColoring::activateSelectTool); connect(ui->btnApplyPrepare, &QPushButton::clicked, this, &BitmapColoring::traceLines); // Thin connect(ui->cb1Thin, &QCheckBox::stateChanged, this, &BitmapColoring::updateThinBoxes); @@ -82,28 +86,28 @@ void BitmapColoring::updateUI() { if (mLayerBitmap->getHasColorLayer()) { - ui->tabPrepare->setEnabled(true); - ui->tabThinLine->setEnabled(false); - ui->tabFinish->setEnabled(false); + ui->tab1->setEnabled(true); + ui->tab2->setEnabled(false); + ui->tab3->setEnabled(false); } else if (mLayerBitmap->getIsColorLayer()) { - ui->tabPrepare->setEnabled(false); - ui->tabThinLine->setEnabled(true); - ui->tabFinish->setEnabled(true); + ui->tab1->setEnabled(false); + ui->tab2->setEnabled(true); + ui->tab3->setEnabled(true); } else { - ui->tabPrepare->setEnabled(true); - ui->tabThinLine->setEnabled(true); - ui->tabFinish->setEnabled(true); + ui->tab1->setEnabled(true); + ui->tab2->setEnabled(true); + ui->tab3->setEnabled(true); } } else { // If it is not a Bitmap Layer - disable - ui->tabPrepare->setEnabled(false); - ui->tabThinLine->setEnabled(false); - ui->tabFinish->setEnabled(false); + ui->tab1->setEnabled(false); + ui->tab2->setEnabled(false); + ui->tab3->setEnabled(false); } } @@ -115,7 +119,7 @@ void BitmapColoring::visibilityChanged(bool visibility) void BitmapColoring::colorMethodChanged() { - if (ui->cbLayerSelector->currentIndex() == 0) + if (ui->cbMethodSelector->currentIndex() == 0) { ui->cb2TraceBlack->setChecked(false); ui->cb2TraceBlack->setEnabled(false); @@ -132,42 +136,74 @@ void BitmapColoring::colorMethodChanged() } } -void BitmapColoring::updateSelectButton() +void BitmapColoring::activateSelectTool() { - if (mSelectAreas) + ToolManager* tool = mEditor->tools(); + tool->setCurrentTool(SELECT); +} + +void BitmapColoring::checkBlackBoxes() +{ + if (ui->cb2TraceBlack->isChecked()) { - mSelectAreas = false; - ui->btnSelectAreas->setIcon(QIcon(":/icons/select.png")); + ui->cb2ThinBlack->show(); + ui->cb2FinishBlack->show(); + ui->cb2ThinBlack->setChecked(ui->cb2TraceBlack->isChecked()); + ui->cb2FinishBlack->setChecked(ui->cb2TraceBlack->isChecked()); } else { - mSelectAreas = true; - ui->btnSelectAreas->setIcon(QIcon(":/icons/select_ok.png")); + ui->cb2ThinBlack->hide(); + ui->cb2FinishBlack->hide(); } } -void BitmapColoring::checkBlackBoxes() -{ - ui->cb2ThinBlack->setChecked(ui->cb2TraceBlack->isChecked()); - ui->cb2FinishBlack->setChecked(ui->cb2TraceBlack->isChecked()); -} - void BitmapColoring::checkRedBoxes() { - ui->cb2ThinRed->setChecked(ui->cb2TraceRed->isChecked()); - ui->cb2FinishRed->setChecked(ui->cb2TraceRed->isChecked()); + if (ui->cb2TraceRed->isChecked()) + { + ui->cb2ThinRed->show(); + ui->cb2FinishRed->show(); + ui->cb2ThinRed->setChecked(ui->cb2TraceRed->isChecked()); + ui->cb2FinishRed->setChecked(ui->cb2TraceRed->isChecked()); + } + else + { + ui->cb2ThinRed->hide(); + ui->cb2FinishRed->hide(); + } } void BitmapColoring::checkGreenBoxes() { - ui->cb2ThinGreen->setChecked(ui->cb2TraceGreen->isChecked()); - ui->cb2FinishGreen->setChecked(ui->cb2TraceGreen->isChecked()); + if (ui->cb2TraceGreen->isChecked()) + { + ui->cb2ThinGreen->show(); + ui->cb2FinishGreen->show(); + ui->cb2ThinGreen->setChecked(ui->cb2TraceGreen->isChecked()); + ui->cb2FinishGreen->setChecked(ui->cb2TraceGreen->isChecked()); + } + else + { + ui->cb2ThinGreen->hide(); + ui->cb2FinishGreen->hide(); + } } void BitmapColoring::checkBlueBoxes() { - ui->cb2ThinBlue->setChecked(ui->cb2TraceBlue->isChecked()); - ui->cb2FinishBlue->setChecked(ui->cb2TraceBlue->isChecked()); + if (ui->cb2TraceBlue->isChecked()) + { + ui->cb2ThinBlue->show(); + ui->cb2FinishBlue->show(); + ui->cb2ThinBlue->setChecked(ui->cb2TraceBlue->isChecked()); + ui->cb2FinishBlue->setChecked(ui->cb2TraceBlue->isChecked()); + } + else + { + ui->cb2ThinBlue->hide(); + ui->cb2FinishBlue->hide(); + } } void BitmapColoring::checkAllKeyframes() @@ -181,7 +217,7 @@ void BitmapColoring::updateTraceBoxes() if (ui->cb0Trace->isChecked()) { ui->gb2Prepare->setEnabled(true); - if (ui->cbLayerSelector->currentIndex() == 0) + if (ui->cbMethodSelector->currentIndex() == 0) ui->cb2TraceBlack->setEnabled(false); } else @@ -215,31 +251,18 @@ void BitmapColoring::setThreshold(int threshold) void BitmapColoring::traceLines() { - mApplyPressed = true; // to give access to select from scan - if (mSelectAreas) - { - QMessageBox::information( - this, - tr("Please select"), - tr("Select from scanned drawings...")); - mEditor->scrubTo(1); - return; - } - mApplyPressed = false; // to close access to select from scan + if (ui->cb1Threshold->isChecked() && !mScribblearea->isSomethingSelected()) { return; } if (ui->cb3TraceAllKeyframes->isChecked()) { - for (int i = 1; i <= mLayerBitmap->getMaxKeyFramePosition(); i++) + for (int i = mLayerBitmap->firstKeyFramePosition(); i <= mLayerBitmap->getMaxKeyFramePosition(); i++) { if (mLayerBitmap->keyExists(i)) { mEditor->scrubTo(i); if (ui->cb1Threshold->isChecked()) - { traceScansToTransparent(); - } prepareLines(); - emit mEditor->updateTimeLine(); } } } @@ -248,23 +271,12 @@ void BitmapColoring::traceLines() if (ui->cb1Threshold->isChecked()) traceScansToTransparent(); prepareLines(); - emit mEditor->updateTimeLine(); - } -} - -void BitmapColoring::selectarea() -{ - if (mApplyPressed && mSelectAreas && mLayerBitmap->keyExists(mEditor->currentFrame())) - { - traceScansToTransparent(); - prepareLines(); - nextKey(); } } void BitmapColoring::traceScansToTransparent() { - if (mSelectAreas) + if (ui->cb1Threshold->isChecked()) { mEditor->copy(); mEditor->layers()->currentLayer()->removeKeyFrame(mEditor->currentFrame()); @@ -277,22 +289,6 @@ void BitmapColoring::traceScansToTransparent() ui->cb2TraceRed->isChecked(), ui->cb2TraceGreen->isChecked(), ui->cb2TraceBlue->isChecked()); - mScribblearea->deselectAll(); - mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Select from scan")); -} - -void BitmapColoring::nextKey() -{ - if (mEditor->currentFrame() < mEditor->layers()->currentLayer()->getMaxKeyFramePosition()) - { - mEditor->scrubNextKeyFrame(); - } - else - { - ui->cb1Threshold->setChecked(false); - updateBtnSelect(); // includes 'mSelectAreas = false' - mApplyPressed = false; - } } void BitmapColoring::prepareLines() @@ -301,8 +297,7 @@ void BitmapColoring::prepareLines() if (!mLayerBitmap->keyExists(mEditor->currentFrame())) { return; } LayerBitmap* colorLayer = nullptr; - // if a separate layer is needed, we make one - if (ui->cbLayerSelector->currentIndex() == 0) + if (ui->cbMethodSelector->currentIndex() == 0) { // if coloring is on same layer... colorLayer = mLayerBitmap; } @@ -319,7 +314,7 @@ void BitmapColoring::prepareLines() } } - if (ui->cbLayerSelector->currentIndex() == 1) + if (ui->cbMethodSelector->currentIndex() == 1) { colorLayer->setVisible(false); mLayerBitmap->copyFrame(mLayerBitmap, colorLayer, mEditor->currentFrame()); @@ -329,7 +324,6 @@ void BitmapColoring::prepareLines() ui->cb2TraceRed->isChecked(), ui->cb2TraceGreen->isChecked(), ui->cb2TraceBlue->isChecked()); - mEditor->backup(mEditor->layers()->currentLayerIndex() ,mEditor->currentFrame(), tr("Preparelines")); } void BitmapColoring::updateThinBoxes() @@ -337,7 +331,7 @@ void BitmapColoring::updateThinBoxes() if (ui->cb1Thin->isChecked()) { ui->gb2Thin->setEnabled(true); - if (ui->cbLayerSelector->currentIndex() == 0) + if (ui->cbMethodSelector->currentIndex() == 0) ui->cb2ThinBlack->setEnabled(false); } else @@ -400,7 +394,7 @@ void BitmapColoring::updateFinishBoxes() if (ui->cb1Finish->isChecked()) { ui->gb2Finish->setEnabled(true); - if (ui->cbLayerSelector->currentIndex() == 0) + if (ui->cbMethodSelector->currentIndex() == 0) ui->cb2FinishBlack->setEnabled(false); } else @@ -444,7 +438,7 @@ void BitmapColoring::blendLines() ui->cb2FinishRed->isChecked(), ui->cb2FinishGreen->isChecked(), ui->cb2FinishBlue->isChecked()); - if (ui->cbLayerSelector->currentIndex() == 1 && artLayer != nullptr) + if (ui->cbMethodSelector->currentIndex() == 1 && artLayer != nullptr) { artLayer->getBitmapImageAtFrame(i)->blendLines(artLayer->getBitmapImageAtFrame(i), false, // don't mess with the original diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 4474aa138a..a42685c20c 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -27,34 +27,33 @@ class BitmapColoring : public BaseDockWidget void updateUI() override; void visibilityChanged(bool visibility); - void prepareLines(); - signals: public slots: void colorMethodChanged(); - void updateSelectButton(); + void activateSelectTool(); void checkBlackBoxes(); void checkRedBoxes(); void checkGreenBoxes(); void checkBlueBoxes(); void checkAllKeyframes(); - // Prepare + // 1: Prepare void updateTraceBoxes(); void updateBtnSelect(); void setThreshold(int threshold); void traceLines(); - void selectarea(); - void traceScansToTransparent(); - void nextKey(); - // Thin + // 2: Thin void updateThinBoxes(); void setSpotArea(int size); void thinLines(); - // Finish + // 3: Finish void updateFinishBoxes(); void blendLines(); +protected: + void traceScansToTransparent(); + void prepareLines(); + private: Ui::BitmapColoringWidget* ui = nullptr; Editor* mEditor = nullptr; diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index 6876ca4752..852fb117df 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -6,14 +6,14 @@ 0 0 - 230 + 234 495 Form - + 2 @@ -30,30 +30,41 @@ 4 - - - Colorize on Same or Separate layer? - + - - On the Same Layer - + + + Methods: + + - - On a Separate Layer - + + + Colorize on Same or Separate layer? + + + + On the Same Layer + + + + + On a Separate Layer + + + - + 0 - + - Prepare + 1 @@ -188,7 +199,7 @@ - Select areas from scanned Drawings + Activate Select tool @@ -437,11 +448,11 @@ - + - Thin line + 2 - + @@ -465,6 +476,9 @@ + + 6 + @@ -742,7 +756,7 @@ - + @@ -773,16 +787,16 @@ 20 - 80 + 59 - + - Finish + 3 diff --git a/core_lib/src/interface/scribblearea.h b/core_lib/src/interface/scribblearea.h index a8683a1b36..800e362e20 100644 --- a/core_lib/src/interface/scribblearea.h +++ b/core_lib/src/interface/scribblearea.h @@ -141,7 +141,6 @@ class ScribbleArea : public QWidget void modification(int); void multiLayerOnionSkinChanged(bool); void refreshPreview(); - void newSelectionMade(); public slots: void clearImage(); diff --git a/core_lib/src/tool/selecttool.cpp b/core_lib/src/tool/selecttool.cpp index 34875c2b22..956387920c 100644 --- a/core_lib/src/tool/selecttool.cpp +++ b/core_lib/src/tool/selecttool.cpp @@ -138,7 +138,6 @@ void SelectTool::pointerReleaseEvent(PointerEvent* event) else { keepSelection(); - emit mScribbleArea->newSelectionMade(); } mScribbleArea->updateToolCursor(); From 596e3c3eca23e453702d407b9b24d1e4367ceeb1 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Thu, 7 Mar 2019 14:48:20 +0100 Subject: [PATCH 051/100] WIP not quite ok when method is changing --- app/src/bitmapcoloring.cpp | 154 +++++++++++++++++++++------------ app/src/bitmapcoloring.h | 1 + app/ui/bitmapcoloringwidget.ui | 149 ++----------------------------- 3 files changed, 106 insertions(+), 198 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 0f1d3d3599..8bd4a0fffe 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -15,10 +15,12 @@ GNU General Public License for more details. */ #include +#include #include "bitmapcoloring.h" #include "ui_bitmapcoloringwidget.h" #include "layermanager.h" #include "toolmanager.h" +#include "app_util.h" BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : @@ -50,17 +52,15 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : connect(ui->cb3TraceAllKeyframes, &QCheckBox::stateChanged, this, &BitmapColoring::checkAllKeyframes); // Prepare - connect(ui->cb0Trace, &QCheckBox::stateChanged, this, &BitmapColoring::updateTraceBoxes); + connect(ui->tabWidget, &QTabWidget::tabBarClicked, this, &BitmapColoring::tabClicked); connect(ui->cb1Threshold, &QCheckBox::stateChanged, this, &BitmapColoring::updateBtnSelect); connect(ui->sb1Threshold, QOverload::of(&QSpinBox::valueChanged), this, &BitmapColoring::setThreshold); connect(ui->btnSelectAreas, &QPushButton::clicked, this, &BitmapColoring::activateSelectTool); connect(ui->btnApplyPrepare, &QPushButton::clicked, this, &BitmapColoring::traceLines); // Thin - connect(ui->cb1Thin, &QCheckBox::stateChanged, this, &BitmapColoring::updateThinBoxes); connect(ui->sbSpotAreas, QOverload::of(&QSpinBox::valueChanged), this, &BitmapColoring::setSpotArea); connect(ui->btnApplyThin, &QPushButton::clicked, this, &BitmapColoring::thinLines); // Finish - connect(ui->cb1Finish, &QCheckBox::stateChanged, this, &BitmapColoring::updateFinishBoxes); connect(ui->btnApplyFinish, &QPushButton::clicked, this, &BitmapColoring::blendLines); updateUI(); @@ -133,6 +133,7 @@ void BitmapColoring::colorMethodChanged() ui->cb2TraceBlack->setEnabled(true); ui->cb2ThinBlack->setEnabled(true); ui->cb2FinishBlack->setEnabled(true); + ui->cb2TraceBlack->setChecked(true); } } @@ -212,21 +213,36 @@ void BitmapColoring::checkAllKeyframes() ui->cb3FinishAllKeyframes->setChecked(ui->cb3TraceAllKeyframes->isChecked()); } +void BitmapColoring::tabClicked(int index) +{ + switch (index) + { + case 0: + updateTraceBoxes(); + break; + case 1: + updateThinBoxes(); + break; + case 2: + updateFinishBoxes(); + break; + default: + updateTraceBoxes(); + } +} + void BitmapColoring::updateTraceBoxes() { - if (ui->cb0Trace->isChecked()) + if (mLayerBitmap->getIsColorLayer()) { - ui->gb2Prepare->setEnabled(true); - if (ui->cbMethodSelector->currentIndex() == 0) - ui->cb2TraceBlack->setEnabled(false); + ui->tab1->setEnabled(false); } else { - ui->cb2TraceBlack->setChecked(false); - ui->cb2TraceRed->setChecked(false); - ui->cb2TraceGreen->setChecked(false); - ui->cb2TraceBlue->setChecked(false); - ui->gb2Prepare->setEnabled(false); + ui->tab1->setEnabled(true); + ui->gb2Prepare->setEnabled(true); + if (ui->cbMethodSelector->currentIndex() == 0) + ui->cb2TraceBlack->setEnabled(false); } } @@ -251,20 +267,33 @@ void BitmapColoring::setThreshold(int threshold) void BitmapColoring::traceLines() { - if (ui->cb1Threshold->isChecked() && !mScribblearea->isSomethingSelected()) { return; } - if (ui->cb3TraceAllKeyframes->isChecked()) { + QProgressDialog progress(tr("Tracing lines in bitmaps..."), tr("Abort"), 0, 100, this); + hideQuestionMark(progress); + progress.setWindowModality(Qt::WindowModal); + progress.show(); + int keysToTrace = mLayerBitmap->keyFrameCount(); + progress.setMaximum(keysToTrace); + int keysTraced = 0; + for (int i = mLayerBitmap->firstKeyFramePosition(); i <= mLayerBitmap->getMaxKeyFramePosition(); i++) { if (mLayerBitmap->keyExists(i)) { + progress.setValue(keysTraced++); + QApplication::processEvents(); mEditor->scrubTo(i); if (ui->cb1Threshold->isChecked()) traceScansToTransparent(); prepareLines(); + if (progress.wasCanceled()) + { + break; + } } } + progress.close(); } else if (mLayerBitmap->keyExists(mEditor->currentFrame())) { @@ -328,19 +357,16 @@ void BitmapColoring::prepareLines() void BitmapColoring::updateThinBoxes() { - if (ui->cb1Thin->isChecked()) + if (mLayerBitmap->getHasColorLayer()) { - ui->gb2Thin->setEnabled(true); - if (ui->cbMethodSelector->currentIndex() == 0) - ui->cb2ThinBlack->setEnabled(false); + ui->tab2->setEnabled(false); } else { - ui->cb2ThinBlack->setChecked(false); - ui->cb2ThinRed->setChecked(false); - ui->cb2ThinGreen->setChecked(false); - ui->cb2ThinBlue->setChecked(false); - ui->gb2Thin->setEnabled(false); + ui->tab2->setEnabled(true); + ui->gb2Thin->setEnabled(true); + if (ui->cbMethodSelector->currentIndex() == 0) + ui->cb2ThinBlack->setEnabled(false); } } @@ -364,10 +390,21 @@ void BitmapColoring::thinLines() firstFrame = mEditor->currentFrame(); lastFrame = firstFrame; } + + QProgressDialog progress(tr("Thinning lines in bitmaps..."), tr("Abort"), 0, 100, this); + hideQuestionMark(progress); + progress.setWindowModality(Qt::WindowModal); + progress.show(); + int keysToThin = mLayerBitmap->keyFrameCount(); + progress.setMaximum(keysToThin); + int keysThinned = 0; + for (int i = firstFrame; i <= lastFrame; i++) { if (mLayerBitmap->keyExists(i)) { + progress.setValue(keysThinned++); + QApplication::processEvents(); mEditor->scrubTo(i); mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(i); if (ui->cbSpotAreas->isChecked()) @@ -375,15 +412,16 @@ void BitmapColoring::thinLines() mBitmapImage->fillSpotAreas(mLayerBitmap->getBitmapImageAtFrame(i)); } - if (ui->cb1Thin->isChecked()) + mBitmapImage->toThinLine(mBitmapImage, + ui->cb2ThinBlack->isChecked(), + ui->cb2ThinRed->isChecked(), + ui->cb2ThinGreen->isChecked(), + ui->cb2ThinBlue->isChecked()); + mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Thin lines")); + if (progress.wasCanceled()) { - mBitmapImage->toThinLine(mBitmapImage, - ui->cb2ThinBlack->isChecked(), - ui->cb2ThinRed->isChecked(), - ui->cb2ThinGreen->isChecked(), - ui->cb2ThinBlue->isChecked()); + break; } - mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Thin lines")); } } updateUI(); @@ -391,19 +429,15 @@ void BitmapColoring::thinLines() void BitmapColoring::updateFinishBoxes() { - if (ui->cb1Finish->isChecked()) + if (mLayerBitmap->getHasColorLayer()) { - ui->gb2Finish->setEnabled(true); - if (ui->cbMethodSelector->currentIndex() == 0) - ui->cb2FinishBlack->setEnabled(false); + ui->gb2Finish->setEnabled(false); } else { - ui->cb2FinishBlack->setChecked(false); - ui->cb2FinishRed->setChecked(false); - ui->cb2FinishGreen->setChecked(false); - ui->cb2FinishBlue->setChecked(false); - ui->gb2Finish->setEnabled(false); + ui->gb2Finish->setEnabled(true); + if (ui->cbMethodSelector->currentIndex() == 0) + ui->cb2FinishBlack->setEnabled(false); } } @@ -426,27 +460,39 @@ void BitmapColoring::blendLines() firstFrame = mEditor->currentFrame(); lastFrame = firstFrame; } + + QProgressDialog progress(tr("Blending lines in bitmaps..."), tr("Abort"), 0, 100, this); + hideQuestionMark(progress); + progress.setWindowModality(Qt::WindowModal); + progress.show(); + int keysToBlend = mLayerBitmap->keyFrameCount(); + progress.setMaximum(keysToBlend); + int keysBlended = 0; + for (int i = firstFrame; i <= lastFrame; i++) { if (mLayerBitmap->keyExists(i)) { + progress.setValue(keysBlended++); + QApplication::processEvents(); mEditor->scrubTo(i); - if (ui->cb1Finish->isChecked()) + mLayerBitmap->getBitmapImageAtFrame(i)->blendLines(mLayerBitmap->getBitmapImageAtFrame(i), + ui->cb2FinishBlack->isChecked(), + ui->cb2FinishRed->isChecked(), + ui->cb2FinishGreen->isChecked(), + ui->cb2FinishBlue->isChecked()); + if (ui->cbMethodSelector->currentIndex() == 1 && artLayer != nullptr) { - mLayerBitmap->getBitmapImageAtFrame(i)->blendLines(mLayerBitmap->getBitmapImageAtFrame(i), - ui->cb2FinishBlack->isChecked(), - ui->cb2FinishRed->isChecked(), - ui->cb2FinishGreen->isChecked(), - ui->cb2FinishBlue->isChecked()); - if (ui->cbMethodSelector->currentIndex() == 1 && artLayer != nullptr) - { - artLayer->getBitmapImageAtFrame(i)->blendLines(artLayer->getBitmapImageAtFrame(i), - false, // don't mess with the original - ui->cb2FinishRed->isChecked(), - ui->cb2FinishGreen->isChecked(), - ui->cb2FinishBlue->isChecked()); - } - mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Blend lines")); + artLayer->getBitmapImageAtFrame(i)->blendLines(artLayer->getBitmapImageAtFrame(i), + false, // don't mess with the original + ui->cb2FinishRed->isChecked(), + ui->cb2FinishGreen->isChecked(), + ui->cb2FinishBlue->isChecked()); + } + mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Blend lines")); + if (progress.wasCanceled()) + { + break; } } } diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index a42685c20c..819383dd8b 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -37,6 +37,7 @@ public slots: void checkGreenBoxes(); void checkBlueBoxes(); void checkAllKeyframes(); + void tabClicked(int index); // 1: Prepare void updateTraceBoxes(); void updateBtnSelect(); diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index 852fb117df..a2476bb249 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -7,13 +7,13 @@ 0 0 234 - 495 + 344 Form - + 2 @@ -64,60 +64,9 @@ - 1 + Tracing - - - - Trace lines? - - - - 2 - - - 4 - - - 4 - - - 4 - - - 4 - - - - - - - Trace lines - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - @@ -450,63 +399,9 @@ - 2 + Thinning - - - - Thin Lines? - - - - 2 - - - 4 - - - 4 - - - 4 - - - 4 - - - - - 6 - - - - - Thin Lines - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - @@ -796,43 +691,9 @@ - 3 + Blending - - - - Blend lines? - - - - 2 - - - 4 - - - 4 - - - 4 - - - 4 - - - - - Blend lines - - - true - - - - - - From e076b15a0a9d962464d96ae84124ad80cf4966e5 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Thu, 7 Mar 2019 18:44:13 +0100 Subject: [PATCH 052/100] Deselect all after tracing --- app/src/bitmapcoloring.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 8bd4a0fffe..7d3a5dc5ac 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -301,6 +301,7 @@ void BitmapColoring::traceLines() traceScansToTransparent(); prepareLines(); } + mScribblearea->deselectAll(); } void BitmapColoring::traceScansToTransparent() From 1ecb23af8da463baf07a821e0f7b1110eb89778c Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Fri, 8 Mar 2019 17:31:22 +0100 Subject: [PATCH 053/100] Bug in thin-function gone. Small ui changes --- app/src/bitmapcoloring.cpp | 119 +++++++++++-------- app/src/bitmapcoloring.h | 3 +- app/ui/bitmapcoloringwidget.ui | 51 +++++++- core_lib/src/graphics/bitmap/bitmapimage.cpp | 5 +- 4 files changed, 124 insertions(+), 54 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 7d3a5dc5ac..ea872954c7 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -56,12 +56,12 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : connect(ui->cb1Threshold, &QCheckBox::stateChanged, this, &BitmapColoring::updateBtnSelect); connect(ui->sb1Threshold, QOverload::of(&QSpinBox::valueChanged), this, &BitmapColoring::setThreshold); connect(ui->btnSelectAreas, &QPushButton::clicked, this, &BitmapColoring::activateSelectTool); - connect(ui->btnApplyPrepare, &QPushButton::clicked, this, &BitmapColoring::traceLines); + connect(ui->btnApplyTrace, &QPushButton::clicked, this, &BitmapColoring::traceLines); // Thin connect(ui->sbSpotAreas, QOverload::of(&QSpinBox::valueChanged), this, &BitmapColoring::setSpotArea); connect(ui->btnApplyThin, &QPushButton::clicked, this, &BitmapColoring::thinLines); // Finish - connect(ui->btnApplyFinish, &QPushButton::clicked, this, &BitmapColoring::blendLines); + connect(ui->btnApplyBlend, &QPushButton::clicked, this, &BitmapColoring::blendLines); updateUI(); } @@ -109,6 +109,7 @@ void BitmapColoring::updateUI() ui->tab2->setEnabled(false); ui->tab3->setEnabled(false); } + mScribblearea->updateCurrentFrame(); } void BitmapColoring::visibilityChanged(bool visibility) @@ -137,12 +138,6 @@ void BitmapColoring::colorMethodChanged() } } -void BitmapColoring::activateSelectTool() -{ - ToolManager* tool = mEditor->tools(); - tool->setCurrentTool(SELECT); -} - void BitmapColoring::checkBlackBoxes() { if (ui->cb2TraceBlack->isChecked()) @@ -260,6 +255,21 @@ void BitmapColoring::updateBtnSelect() } } +void BitmapColoring::activateSelectTool() +{ + if (!mSelectAreas) + { + mSelectAreas = true; + ui->btnSelectAreas->setIcon(QIcon(":/icons/select_ok.png")); + ToolManager* tool = mEditor->tools(); + tool->setCurrentTool(SELECT); + } + else { + mSelectAreas = false; + ui->btnSelectAreas->setIcon(QIcon(":/icons/select.png")); + } +} + void BitmapColoring::setThreshold(int threshold) { mBitmapImage->setThreshold(threshold); @@ -267,33 +277,39 @@ void BitmapColoring::setThreshold(int threshold) void BitmapColoring::traceLines() { + if (mSelectAreas && !mScribblearea->isSomethingSelected()) + { + QMessageBox::information(this, tr("No selection!"), tr("Please select area with select tool...")); + return; + } + if (ui->cb3TraceAllKeyframes->isChecked()) { - QProgressDialog progress(tr("Tracing lines in bitmaps..."), tr("Abort"), 0, 100, this); - hideQuestionMark(progress); - progress.setWindowModality(Qt::WindowModal); - progress.show(); + QProgressDialog* mProgress = new QProgressDialog(tr("Tracing lines in bitmaps..."), tr("Abort"), 0, 100, this); + mProgress->setWindowModality(Qt::WindowModal); + mProgress->show(); int keysToTrace = mLayerBitmap->keyFrameCount(); - progress.setMaximum(keysToTrace); + mProgress->setMaximum(keysToTrace); + mProgress->setValue(0); int keysTraced = 0; for (int i = mLayerBitmap->firstKeyFramePosition(); i <= mLayerBitmap->getMaxKeyFramePosition(); i++) { if (mLayerBitmap->keyExists(i)) { - progress.setValue(keysTraced++); + mProgress->setValue(keysTraced++); QApplication::processEvents(); mEditor->scrubTo(i); if (ui->cb1Threshold->isChecked()) traceScansToTransparent(); prepareLines(); - if (progress.wasCanceled()) + if (mProgress->wasCanceled()) { break; } } } - progress.close(); + mProgress->close(); } else if (mLayerBitmap->keyExists(mEditor->currentFrame())) { @@ -379,52 +395,61 @@ void BitmapColoring::setSpotArea(int size) void BitmapColoring::thinLines() { if (mLayerBitmap == nullptr) { return; } - mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->layers()->currentLayer()->getMaxKeyFramePosition()); - int firstFrame = 1, lastFrame = 1; - if (ui->cb3ThinAllKeyframes->isChecked()) + if (!ui->cb3ThinAllKeyframes->isChecked()) { - lastFrame = mLayerBitmap->getMaxKeyFramePosition(); - } - else - { - firstFrame = mEditor->currentFrame(); - lastFrame = firstFrame; - } - - QProgressDialog progress(tr("Thinning lines in bitmaps..."), tr("Abort"), 0, 100, this); - hideQuestionMark(progress); - progress.setWindowModality(Qt::WindowModal); - progress.show(); - int keysToThin = mLayerBitmap->keyFrameCount(); - progress.setMaximum(keysToThin); - int keysThinned = 0; - - for (int i = firstFrame; i <= lastFrame; i++) - { - if (mLayerBitmap->keyExists(i)) + if (mLayerBitmap->keyExists(mEditor->currentFrame())) { - progress.setValue(keysThinned++); - QApplication::processEvents(); - mEditor->scrubTo(i); - mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(i); + mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); if (ui->cbSpotAreas->isChecked()) { - mBitmapImage->fillSpotAreas(mLayerBitmap->getBitmapImageAtFrame(i)); + mBitmapImage->fillSpotAreas(mBitmapImage); } - mBitmapImage->toThinLine(mBitmapImage, ui->cb2ThinBlack->isChecked(), ui->cb2ThinRed->isChecked(), ui->cb2ThinGreen->isChecked(), ui->cb2ThinBlue->isChecked()); - mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Thin lines")); - if (progress.wasCanceled()) + } + } + else + { + QProgressDialog* mProgress = new QProgressDialog(tr("Thinning lines in bitmaps..."), tr("Abort"), 0, 100, this); + mProgress->setWindowModality(Qt::WindowModal); + mProgress->show(); + mProgress->setMaximum(mLayerBitmap->keyFrameCount()); + mProgress->setValue(0); + int keysThinned = 0; + + for (int i = mLayerBitmap->firstKeyFramePosition(); i <= mLayerBitmap->getMaxKeyFramePosition(); i++) + { + if (mLayerBitmap->keyExists(i)) + { + mEditor->scrubTo(i); + mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(i); + if (ui->cbSpotAreas->isChecked()) + { + mBitmapImage->fillSpotAreas(mBitmapImage); + } + + mBitmapImage->toThinLine(mBitmapImage, + ui->cb2ThinBlack->isChecked(), + ui->cb2ThinRed->isChecked(), + ui->cb2ThinGreen->isChecked(), + ui->cb2ThinBlue->isChecked()); + mEditor->backup(tr("Thin lines")); + keysThinned++; + mProgress->setValue(keysThinned); + QApplication::processEvents(); + } + if (mProgress->wasCanceled()) { break; } } + mProgress->close(); } + ui->cbSpotAreas->setChecked(false); updateUI(); } @@ -451,7 +476,7 @@ void BitmapColoring::blendLines() orgName.chop(2); LayerBitmap* artLayer = static_cast(mEditor->layers()->findLayerByName(orgName)); - int firstFrame = 1, lastFrame = 1; + int firstFrame = mLayerBitmap->firstKeyFramePosition(), lastFrame = 1; if (ui->cb3FinishAllKeyframes->isChecked()) { lastFrame = mLayerBitmap->getMaxKeyFramePosition(); diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 819383dd8b..3aea2cd333 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -31,7 +31,6 @@ class BitmapColoring : public BaseDockWidget public slots: void colorMethodChanged(); - void activateSelectTool(); void checkBlackBoxes(); void checkRedBoxes(); void checkGreenBoxes(); @@ -41,6 +40,7 @@ public slots: // 1: Prepare void updateTraceBoxes(); void updateBtnSelect(); + void activateSelectTool(); void setThreshold(int threshold); void traceLines(); // 2: Thin @@ -62,7 +62,6 @@ public slots: LayerBitmap* mLayerBitmap = nullptr; BitmapImage* mBitmapImage = nullptr; bool mSelectAreas = false; - bool mApplyPressed = false; }; diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index a2476bb249..a5b4ec80d2 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -7,7 +7,7 @@ 0 0 234 - 344 + 374 @@ -67,6 +67,21 @@ Tracing + + 2 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -374,7 +389,7 @@ - + Apply @@ -402,6 +417,21 @@ Thinning + + 2 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -694,6 +724,21 @@ Blending + + 2 + + + 4 + + + 4 + + + 4 + + + 4 + @@ -904,7 +949,7 @@ - + Apply diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 5371247921..0233a9f8d3 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -660,7 +660,8 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool black Q_ASSERT(bitmapimage != nullptr); BitmapImage* img = bitmapimage; - img->enableAutoCrop(false); + img->enableAutoCrop(true); + img->autoCrop(); QRgb rgba; for (int x = img->left(); x <= img->right(); x++) @@ -764,7 +765,7 @@ void BitmapImage::traceLine(BitmapImage* bitmapimage, bool black, bool red, bool void BitmapImage::fillSpotAreas(BitmapImage *bitmapimage) { - if(bitmapimage == nullptr) { return; } + if (bitmapimage == nullptr) { return; } BitmapImage* img = bitmapimage; // fill areas size 'area' or less with appropriate color From a04089619dd2369212e0fa204ab44f2f95452192 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Fri, 8 Mar 2019 22:56:33 +0100 Subject: [PATCH 054/100] Optimizing thin and blend functions --- app/src/bitmapcoloring.cpp | 119 ++++++++++++++++++------------------- app/src/bitmapcoloring.h | 2 + 2 files changed, 60 insertions(+), 61 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index ea872954c7..7dcbd5f8bb 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -400,16 +400,7 @@ void BitmapColoring::thinLines() { if (mLayerBitmap->keyExists(mEditor->currentFrame())) { - mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); - if (ui->cbSpotAreas->isChecked()) - { - mBitmapImage->fillSpotAreas(mBitmapImage); - } - mBitmapImage->toThinLine(mBitmapImage, - ui->cb2ThinBlack->isChecked(), - ui->cb2ThinRed->isChecked(), - ui->cb2ThinGreen->isChecked(), - ui->cb2ThinBlue->isChecked()); + thinLayers(); } } else @@ -426,18 +417,7 @@ void BitmapColoring::thinLines() if (mLayerBitmap->keyExists(i)) { mEditor->scrubTo(i); - mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(i); - if (ui->cbSpotAreas->isChecked()) - { - mBitmapImage->fillSpotAreas(mBitmapImage); - } - - mBitmapImage->toThinLine(mBitmapImage, - ui->cb2ThinBlack->isChecked(), - ui->cb2ThinRed->isChecked(), - ui->cb2ThinGreen->isChecked(), - ui->cb2ThinBlue->isChecked()); - mEditor->backup(tr("Thin lines")); + thinLayers(); keysThinned++; mProgress->setValue(keysThinned); QApplication::processEvents(); @@ -450,6 +430,21 @@ void BitmapColoring::thinLines() mProgress->close(); } ui->cbSpotAreas->setChecked(false); +} + +void BitmapColoring::thinLayers() +{ + mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); + if (ui->cbSpotAreas->isChecked()) + { + mBitmapImage->fillSpotAreas(mBitmapImage); + } + mBitmapImage->toThinLine(mBitmapImage, + ui->cb2ThinBlack->isChecked(), + ui->cb2ThinRed->isChecked(), + ui->cb2ThinGreen->isChecked(), + ui->cb2ThinBlue->isChecked()); + mEditor->backup(tr("Thin lines")); updateUI(); } @@ -457,11 +452,11 @@ void BitmapColoring::updateFinishBoxes() { if (mLayerBitmap->getHasColorLayer()) { - ui->gb2Finish->setEnabled(false); + ui->tab3->setEnabled(false); } else { - ui->gb2Finish->setEnabled(true); + ui->tab3->setEnabled(true); if (ui->cbMethodSelector->currentIndex() == 0) ui->cb2FinishBlack->setEnabled(false); } @@ -470,57 +465,59 @@ void BitmapColoring::updateFinishBoxes() void BitmapColoring::blendLines() { if (mLayerBitmap == nullptr) { return; } - mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->layers()->currentLayer()->getMaxKeyFramePosition()); QString orgName = mLayerBitmap->name(); orgName.chop(2); LayerBitmap* artLayer = static_cast(mEditor->layers()->findLayerByName(orgName)); - int firstFrame = mLayerBitmap->firstKeyFramePosition(), lastFrame = 1; - if (ui->cb3FinishAllKeyframes->isChecked()) + if (!ui->cb3FinishAllKeyframes->isChecked()) { - lastFrame = mLayerBitmap->getMaxKeyFramePosition(); + blendLayers(artLayer); } else { - firstFrame = mEditor->currentFrame(); - lastFrame = firstFrame; - } + QProgressDialog progress(tr("Blending lines in bitmaps..."), tr("Abort"), 0, 100, this); + hideQuestionMark(progress); + progress.setWindowModality(Qt::WindowModal); + progress.show(); + int keysToBlend = mLayerBitmap->keyFrameCount(); + progress.setMaximum(keysToBlend); + int keysBlended = 0; - QProgressDialog progress(tr("Blending lines in bitmaps..."), tr("Abort"), 0, 100, this); - hideQuestionMark(progress); - progress.setWindowModality(Qt::WindowModal); - progress.show(); - int keysToBlend = mLayerBitmap->keyFrameCount(); - progress.setMaximum(keysToBlend); - int keysBlended = 0; - - for (int i = firstFrame; i <= lastFrame; i++) - { - if (mLayerBitmap->keyExists(i)) + for (int i = mLayerBitmap->firstKeyFramePosition(); i <= mLayerBitmap->getMaxKeyFramePosition(); i++) { - progress.setValue(keysBlended++); - QApplication::processEvents(); - mEditor->scrubTo(i); - mLayerBitmap->getBitmapImageAtFrame(i)->blendLines(mLayerBitmap->getBitmapImageAtFrame(i), - ui->cb2FinishBlack->isChecked(), - ui->cb2FinishRed->isChecked(), - ui->cb2FinishGreen->isChecked(), - ui->cb2FinishBlue->isChecked()); - if (ui->cbMethodSelector->currentIndex() == 1 && artLayer != nullptr) - { - artLayer->getBitmapImageAtFrame(i)->blendLines(artLayer->getBitmapImageAtFrame(i), - false, // don't mess with the original - ui->cb2FinishRed->isChecked(), - ui->cb2FinishGreen->isChecked(), - ui->cb2FinishBlue->isChecked()); - } - mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Blend lines")); - if (progress.wasCanceled()) + if (mLayerBitmap->keyExists(i)) { - break; + progress.setValue(keysBlended++); + QApplication::processEvents(); + mEditor->scrubTo(i); + blendLayers(artLayer); + if (progress.wasCanceled()) + { + break; + } } } } } +void BitmapColoring::blendLayers(LayerBitmap *artLayer) +{ + mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame())->blendLines(mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()), + ui->cb2FinishBlack->isChecked(), + ui->cb2FinishRed->isChecked(), + ui->cb2FinishGreen->isChecked(), + ui->cb2FinishBlue->isChecked()); + mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Blend lines")); + if (ui->cbMethodSelector->currentIndex() == 1 && artLayer != nullptr) + { + artLayer->getBitmapImageAtFrame(mEditor->currentFrame())->blendLines(artLayer->getBitmapImageAtFrame(mEditor->currentFrame()), + ui->cb2FinishBlack->isChecked(), + ui->cb2FinishRed->isChecked(), + ui->cb2FinishGreen->isChecked(), + ui->cb2FinishBlue->isChecked()); + mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Blend lines")); + } + updateUI(); +} + diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 3aea2cd333..13b92824ea 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -54,6 +54,8 @@ public slots: protected: void traceScansToTransparent(); void prepareLines(); + void thinLayers(); + void blendLayers(LayerBitmap* artLayer); private: Ui::BitmapColoringWidget* ui = nullptr; From c0430f2a51d5d064557151fdd3097400a3c2d350 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 9 Mar 2019 16:47:03 +0100 Subject: [PATCH 055/100] Consistent naming and some cleanup in code --- app/src/bitmapcoloring.cpp | 241 +++++++++++++++++---------------- app/src/bitmapcoloring.h | 15 +- app/ui/bitmapcoloringwidget.ui | 36 ++--- 3 files changed, 151 insertions(+), 141 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 7dcbd5f8bb..260e1ffb9b 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -49,10 +49,10 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : connect(ui->cb2TraceRed, &QCheckBox::stateChanged, this, &BitmapColoring::checkRedBoxes); connect(ui->cb2TraceGreen, &QCheckBox::stateChanged, this, &BitmapColoring::checkGreenBoxes); connect(ui->cb2TraceBlue, &QCheckBox::stateChanged, this, &BitmapColoring::checkBlueBoxes); - connect(ui->cb3TraceAllKeyframes, &QCheckBox::stateChanged, this, &BitmapColoring::checkAllKeyframes); + connect(ui->cb3TraceAllKeyframes, &QCheckBox::stateChanged, this, &BitmapColoring::checkAllKeyframesBoxes); // Prepare - connect(ui->tabWidget, &QTabWidget::tabBarClicked, this, &BitmapColoring::tabClicked); + connect(ui->tabWidget, &QTabWidget::tabBarClicked, this, &BitmapColoring::tabWidgetClicked); connect(ui->cb1Threshold, &QCheckBox::stateChanged, this, &BitmapColoring::updateBtnSelect); connect(ui->sb1Threshold, QOverload::of(&QSpinBox::valueChanged), this, &BitmapColoring::setThreshold); connect(ui->btnSelectAreas, &QPushButton::clicked, this, &BitmapColoring::activateSelectTool); @@ -126,14 +126,14 @@ void BitmapColoring::colorMethodChanged() ui->cb2TraceBlack->setEnabled(false); ui->cb2ThinBlack->setChecked(false); ui->cb2ThinBlack->setEnabled(false); - ui->cb2FinishBlack->setChecked(false); - ui->cb2FinishBlack->setEnabled(false); + ui->cb2BlendBlack->setChecked(false); + ui->cb2BlendBlack->setEnabled(false); } else { ui->cb2TraceBlack->setEnabled(true); ui->cb2ThinBlack->setEnabled(true); - ui->cb2FinishBlack->setEnabled(true); + ui->cb2BlendBlack->setEnabled(true); ui->cb2TraceBlack->setChecked(true); } } @@ -143,14 +143,14 @@ void BitmapColoring::checkBlackBoxes() if (ui->cb2TraceBlack->isChecked()) { ui->cb2ThinBlack->show(); - ui->cb2FinishBlack->show(); + ui->cb2BlendBlack->show(); ui->cb2ThinBlack->setChecked(ui->cb2TraceBlack->isChecked()); - ui->cb2FinishBlack->setChecked(ui->cb2TraceBlack->isChecked()); + ui->cb2BlendBlack->setChecked(ui->cb2TraceBlack->isChecked()); } else { ui->cb2ThinBlack->hide(); - ui->cb2FinishBlack->hide(); + ui->cb2BlendBlack->hide(); } } @@ -159,14 +159,14 @@ void BitmapColoring::checkRedBoxes() if (ui->cb2TraceRed->isChecked()) { ui->cb2ThinRed->show(); - ui->cb2FinishRed->show(); + ui->cb2BlendRed->show(); ui->cb2ThinRed->setChecked(ui->cb2TraceRed->isChecked()); - ui->cb2FinishRed->setChecked(ui->cb2TraceRed->isChecked()); + ui->cb2BlendRed->setChecked(ui->cb2TraceRed->isChecked()); } else { ui->cb2ThinRed->hide(); - ui->cb2FinishRed->hide(); + ui->cb2BlendRed->hide(); } } @@ -175,14 +175,14 @@ void BitmapColoring::checkGreenBoxes() if (ui->cb2TraceGreen->isChecked()) { ui->cb2ThinGreen->show(); - ui->cb2FinishGreen->show(); + ui->cb2BlendGreen->show(); ui->cb2ThinGreen->setChecked(ui->cb2TraceGreen->isChecked()); - ui->cb2FinishGreen->setChecked(ui->cb2TraceGreen->isChecked()); + ui->cb2BlendGreen->setChecked(ui->cb2TraceGreen->isChecked()); } else { ui->cb2ThinGreen->hide(); - ui->cb2FinishGreen->hide(); + ui->cb2BlendGreen->hide(); } } @@ -191,24 +191,24 @@ void BitmapColoring::checkBlueBoxes() if (ui->cb2TraceBlue->isChecked()) { ui->cb2ThinBlue->show(); - ui->cb2FinishBlue->show(); + ui->cb2BlendBlue->show(); ui->cb2ThinBlue->setChecked(ui->cb2TraceBlue->isChecked()); - ui->cb2FinishBlue->setChecked(ui->cb2TraceBlue->isChecked()); + ui->cb2BlendBlue->setChecked(ui->cb2TraceBlue->isChecked()); } else { ui->cb2ThinBlue->hide(); - ui->cb2FinishBlue->hide(); + ui->cb2BlendBlue->hide(); } } -void BitmapColoring::checkAllKeyframes() +void BitmapColoring::checkAllKeyframesBoxes() { ui->cb3ThinAllKeyframes->setChecked(ui->cb3TraceAllKeyframes->isChecked()); - ui->cb3FinishAllKeyframes->setChecked(ui->cb3TraceAllKeyframes->isChecked()); + ui->cb3BlendAllKeyframes->setChecked(ui->cb3TraceAllKeyframes->isChecked()); } -void BitmapColoring::tabClicked(int index) +void BitmapColoring::tabWidgetClicked(int index) { switch (index) { @@ -219,13 +219,14 @@ void BitmapColoring::tabClicked(int index) updateThinBoxes(); break; case 2: - updateFinishBoxes(); + updateBlendBoxes(); break; default: updateTraceBoxes(); } } +// public Trace funtions void BitmapColoring::updateTraceBoxes() { if (mLayerBitmap->getIsColorLayer()) @@ -235,7 +236,7 @@ void BitmapColoring::updateTraceBoxes() else { ui->tab1->setEnabled(true); - ui->gb2Prepare->setEnabled(true); + ui->gb2Trace->setEnabled(true); if (ui->cbMethodSelector->currentIndex() == 0) ui->cb2TraceBlack->setEnabled(false); } @@ -277,6 +278,8 @@ void BitmapColoring::setThreshold(int threshold) void BitmapColoring::traceLines() { + if (mLayerBitmap == nullptr) { return; } + if (mSelectAreas && !mScribblearea->isSomethingSelected()) { QMessageBox::information(this, tr("No selection!"), tr("Please select area with select tool...")); @@ -300,9 +303,7 @@ void BitmapColoring::traceLines() mProgress->setValue(keysTraced++); QApplication::processEvents(); mEditor->scrubTo(i); - if (ui->cb1Threshold->isChecked()) - traceScansToTransparent(); - prepareLines(); + trace(); if (mProgress->wasCanceled()) { break; @@ -313,65 +314,14 @@ void BitmapColoring::traceLines() } else if (mLayerBitmap->keyExists(mEditor->currentFrame())) { - if (ui->cb1Threshold->isChecked()) - traceScansToTransparent(); - prepareLines(); + trace(); } mScribblearea->deselectAll(); + ui->cb1Threshold->setChecked(false); + updateBtnSelect(); } -void BitmapColoring::traceScansToTransparent() -{ - if (ui->cb1Threshold->isChecked()) - { - mEditor->copy(); - mEditor->layers()->currentLayer()->removeKeyFrame(mEditor->currentFrame()); - mEditor->layers()->currentLayer()->addNewKeyFrameAt(mEditor->currentFrame()); - mEditor->paste(); - } - mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); - mBitmapImage = mBitmapImage->scanToTransparent(mBitmapImage, - true, - ui->cb2TraceRed->isChecked(), - ui->cb2TraceGreen->isChecked(), - ui->cb2TraceBlue->isChecked()); -} - -void BitmapColoring::prepareLines() -{ - if (mLayerBitmap == nullptr) { return; } - if (!mLayerBitmap->keyExists(mEditor->currentFrame())) { return; } - - LayerBitmap* colorLayer = nullptr; - if (ui->cbMethodSelector->currentIndex() == 0) - { // if coloring is on same layer... - colorLayer = mLayerBitmap; - } - else - { // if coloring is on separate layer... - if (!mLayerBitmap->getHasColorLayer()) - { - colorLayer = mEditor->layers()->createBitmapLayer(mLayerBitmap->name() + "_C"); - mLayerBitmap->setHasColorLayer(true); - colorLayer->setIsColorLayer(true); - } - else { - colorLayer = static_cast(mEditor->layers()->findLayerByName(mLayerBitmap->name() + "_C")); - } - } - - if (ui->cbMethodSelector->currentIndex() == 1) - { - colorLayer->setVisible(false); - mLayerBitmap->copyFrame(mLayerBitmap, colorLayer, mEditor->currentFrame()); - } - colorLayer->getBitmapImageAtFrame(mEditor->currentFrame())->traceLine(colorLayer->getBitmapImageAtFrame(mEditor->currentFrame()), - ui->cb2TraceBlack->isChecked(), - ui->cb2TraceRed->isChecked(), - ui->cb2TraceGreen->isChecked(), - ui->cb2TraceBlue->isChecked()); -} - +// public Thin functions void BitmapColoring::updateThinBoxes() { if (mLayerBitmap->getHasColorLayer()) @@ -400,7 +350,7 @@ void BitmapColoring::thinLines() { if (mLayerBitmap->keyExists(mEditor->currentFrame())) { - thinLayers(); + thin(); } } else @@ -417,9 +367,8 @@ void BitmapColoring::thinLines() if (mLayerBitmap->keyExists(i)) { mEditor->scrubTo(i); - thinLayers(); - keysThinned++; - mProgress->setValue(keysThinned); + thin(); + mProgress->setValue(keysThinned++); QApplication::processEvents(); } if (mProgress->wasCanceled()) @@ -432,23 +381,8 @@ void BitmapColoring::thinLines() ui->cbSpotAreas->setChecked(false); } -void BitmapColoring::thinLayers() -{ - mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); - if (ui->cbSpotAreas->isChecked()) - { - mBitmapImage->fillSpotAreas(mBitmapImage); - } - mBitmapImage->toThinLine(mBitmapImage, - ui->cb2ThinBlack->isChecked(), - ui->cb2ThinRed->isChecked(), - ui->cb2ThinGreen->isChecked(), - ui->cb2ThinBlue->isChecked()); - mEditor->backup(tr("Thin lines")); - updateUI(); -} - -void BitmapColoring::updateFinishBoxes() +// public Blend functions +void BitmapColoring::updateBlendBoxes() { if (mLayerBitmap->getHasColorLayer()) { @@ -458,7 +392,7 @@ void BitmapColoring::updateFinishBoxes() { ui->tab3->setEnabled(true); if (ui->cbMethodSelector->currentIndex() == 0) - ui->cb2FinishBlack->setEnabled(false); + ui->cb2BlendBlack->setEnabled(false); } } @@ -470,9 +404,9 @@ void BitmapColoring::blendLines() orgName.chop(2); LayerBitmap* artLayer = static_cast(mEditor->layers()->findLayerByName(orgName)); - if (!ui->cb3FinishAllKeyframes->isChecked()) + if (!ui->cb3BlendAllKeyframes->isChecked()) { - blendLayers(artLayer); + blend(artLayer); } else { @@ -488,10 +422,10 @@ void BitmapColoring::blendLines() { if (mLayerBitmap->keyExists(i)) { + mEditor->scrubTo(i); + blend(artLayer); progress.setValue(keysBlended++); QApplication::processEvents(); - mEditor->scrubTo(i); - blendLayers(artLayer); if (progress.wasCanceled()) { break; @@ -501,23 +435,98 @@ void BitmapColoring::blendLines() } } -void BitmapColoring::blendLayers(LayerBitmap *artLayer) +// protected functions +void BitmapColoring::traceScansToTransparent() +{ + if (ui->cb1Threshold->isChecked()) + { + mEditor->copy(); + mEditor->layers()->currentLayer()->removeKeyFrame(mEditor->currentFrame()); + mEditor->layers()->currentLayer()->addNewKeyFrameAt(mEditor->currentFrame()); + mEditor->paste(); + } + mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); + mBitmapImage = mBitmapImage->scanToTransparent(mBitmapImage, + true, + ui->cb2TraceRed->isChecked(), + ui->cb2TraceGreen->isChecked(), + ui->cb2TraceBlue->isChecked()); +} + +void BitmapColoring::prepareLines() +{ + if (mLayerBitmap == nullptr) { return; } + if (!mLayerBitmap->keyExists(mEditor->currentFrame())) { return; } + + LayerBitmap* colorLayer = nullptr; + if (ui->cbMethodSelector->currentIndex() == 0) + { // if coloring is on same layer... + colorLayer = mLayerBitmap; + } + else + { // if coloring is on separate layer... + if (!mLayerBitmap->getHasColorLayer()) + { + colorLayer = mEditor->layers()->createBitmapLayer(mLayerBitmap->name() + "_C"); + mLayerBitmap->setHasColorLayer(true); + colorLayer->setIsColorLayer(true); + } + else { + colorLayer = static_cast(mEditor->layers()->findLayerByName(mLayerBitmap->name() + "_C")); + } + } + + if (ui->cbMethodSelector->currentIndex() == 1) + { + colorLayer->setVisible(false); + mLayerBitmap->copyFrame(mLayerBitmap, colorLayer, mEditor->currentFrame()); + } + colorLayer->getBitmapImageAtFrame(mEditor->currentFrame())->traceLine(colorLayer->getBitmapImageAtFrame(mEditor->currentFrame()), + ui->cb2TraceBlack->isChecked(), + ui->cb2TraceRed->isChecked(), + ui->cb2TraceGreen->isChecked(), + ui->cb2TraceBlue->isChecked()); +} + +void BitmapColoring::trace() +{ + if (ui->cb1Threshold->isChecked()) + traceScansToTransparent(); + prepareLines(); +} + +void BitmapColoring::thin() +{ + mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); + if (ui->cbSpotAreas->isChecked()) + { + mBitmapImage->fillSpotAreas(mBitmapImage); + } + mBitmapImage->toThinLine(mBitmapImage, + ui->cb2ThinBlack->isChecked(), + ui->cb2ThinRed->isChecked(), + ui->cb2ThinGreen->isChecked(), + ui->cb2ThinBlue->isChecked()); + mEditor->backup(tr("Thin lines")); + updateUI(); +} + +void BitmapColoring::blend(LayerBitmap *artLayer) { mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame())->blendLines(mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()), - ui->cb2FinishBlack->isChecked(), - ui->cb2FinishRed->isChecked(), - ui->cb2FinishGreen->isChecked(), - ui->cb2FinishBlue->isChecked()); + ui->cb2BlendBlack->isChecked(), + ui->cb2BlendRed->isChecked(), + ui->cb2BlendGreen->isChecked(), + ui->cb2BlendBlue->isChecked()); mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Blend lines")); if (ui->cbMethodSelector->currentIndex() == 1 && artLayer != nullptr) { artLayer->getBitmapImageAtFrame(mEditor->currentFrame())->blendLines(artLayer->getBitmapImageAtFrame(mEditor->currentFrame()), - ui->cb2FinishBlack->isChecked(), - ui->cb2FinishRed->isChecked(), - ui->cb2FinishGreen->isChecked(), - ui->cb2FinishBlue->isChecked()); + ui->cb2BlendBlack->isChecked(), + ui->cb2BlendRed->isChecked(), + ui->cb2BlendGreen->isChecked(), + ui->cb2BlendBlue->isChecked()); mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Blend lines")); } updateUI(); } - diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 13b92824ea..3c11b3ecac 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -35,9 +35,9 @@ public slots: void checkRedBoxes(); void checkGreenBoxes(); void checkBlueBoxes(); - void checkAllKeyframes(); - void tabClicked(int index); - // 1: Prepare + void checkAllKeyframesBoxes(); + void tabWidgetClicked(int index); + // 1: Trace void updateTraceBoxes(); void updateBtnSelect(); void activateSelectTool(); @@ -47,15 +47,16 @@ public slots: void updateThinBoxes(); void setSpotArea(int size); void thinLines(); - // 3: Finish - void updateFinishBoxes(); + // 3: Blend + void updateBlendBoxes(); void blendLines(); protected: void traceScansToTransparent(); void prepareLines(); - void thinLayers(); - void blendLayers(LayerBitmap* artLayer); + void trace(); + void thin(); + void blend(LayerBitmap* artLayer); private: Ui::BitmapColoringWidget* ui = nullptr; diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index a5b4ec80d2..d66d4a5806 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -64,7 +64,7 @@ - Tracing + Trace @@ -83,7 +83,7 @@ 4 - + Scanned Drawings? @@ -180,7 +180,7 @@ - + Filters @@ -343,7 +343,7 @@ - + Repeat Process @@ -414,7 +414,7 @@ - Thinning + Thin @@ -650,7 +650,7 @@ - + Repeat Process @@ -721,7 +721,7 @@ - Blending + Blend @@ -740,7 +740,7 @@ 4 - + Filters @@ -763,7 +763,7 @@ - + false @@ -786,7 +786,7 @@ - + @@ -800,7 +800,7 @@ - + Apply to Red @@ -820,7 +820,7 @@ - + @@ -834,7 +834,7 @@ - + Apply to Green @@ -854,7 +854,7 @@ - + @@ -868,7 +868,7 @@ - + Apply to Blue @@ -888,7 +888,7 @@ - + @@ -903,7 +903,7 @@ - + Repeat Process @@ -924,7 +924,7 @@ 4 - + All keyframes From 98276fe25eadfbac1dcf22280be6ad44416288ff Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 9 Mar 2019 17:33:38 +0100 Subject: [PATCH 056/100] Bug in blend() function corrected --- app/src/bitmapcoloring.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 260e1ffb9b..80cc1cd530 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -521,11 +521,11 @@ void BitmapColoring::blend(LayerBitmap *artLayer) mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Blend lines")); if (ui->cbMethodSelector->currentIndex() == 1 && artLayer != nullptr) { - artLayer->getBitmapImageAtFrame(mEditor->currentFrame())->blendLines(artLayer->getBitmapImageAtFrame(mEditor->currentFrame()), - ui->cb2BlendBlack->isChecked(), - ui->cb2BlendRed->isChecked(), - ui->cb2BlendGreen->isChecked(), - ui->cb2BlendBlue->isChecked()); + artLayer->getBitmapImageAtFrame(mEditor->currentFrame())->traceLine(artLayer->getBitmapImageAtFrame(mEditor->currentFrame()), + false, + false, + false, + false); mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Blend lines")); } updateUI(); From 8de4461b4c1cdde5eda89874219228394a2f2f69 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 10 Mar 2019 10:11:20 +0100 Subject: [PATCH 057/100] Removed filter restrain. Some optimizing of code --- app/src/bitmapcoloring.cpp | 72 ++++---------------- app/src/bitmapcoloring.h | 1 - core_lib/src/graphics/bitmap/bitmapimage.cpp | 12 ++-- 3 files changed, 19 insertions(+), 66 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 80cc1cd530..32f313b472 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -142,64 +142,36 @@ void BitmapColoring::checkBlackBoxes() { if (ui->cb2TraceBlack->isChecked()) { - ui->cb2ThinBlack->show(); - ui->cb2BlendBlack->show(); ui->cb2ThinBlack->setChecked(ui->cb2TraceBlack->isChecked()); ui->cb2BlendBlack->setChecked(ui->cb2TraceBlack->isChecked()); } - else - { - ui->cb2ThinBlack->hide(); - ui->cb2BlendBlack->hide(); - } } void BitmapColoring::checkRedBoxes() { if (ui->cb2TraceRed->isChecked()) { - ui->cb2ThinRed->show(); - ui->cb2BlendRed->show(); ui->cb2ThinRed->setChecked(ui->cb2TraceRed->isChecked()); ui->cb2BlendRed->setChecked(ui->cb2TraceRed->isChecked()); } - else - { - ui->cb2ThinRed->hide(); - ui->cb2BlendRed->hide(); - } } void BitmapColoring::checkGreenBoxes() { if (ui->cb2TraceGreen->isChecked()) { - ui->cb2ThinGreen->show(); - ui->cb2BlendGreen->show(); ui->cb2ThinGreen->setChecked(ui->cb2TraceGreen->isChecked()); ui->cb2BlendGreen->setChecked(ui->cb2TraceGreen->isChecked()); } - else - { - ui->cb2ThinGreen->hide(); - ui->cb2BlendGreen->hide(); - } } void BitmapColoring::checkBlueBoxes() { if (ui->cb2TraceBlue->isChecked()) { - ui->cb2ThinBlue->show(); - ui->cb2BlendBlue->show(); ui->cb2ThinBlue->setChecked(ui->cb2TraceBlue->isChecked()); ui->cb2BlendBlue->setChecked(ui->cb2TraceBlue->isChecked()); } - else - { - ui->cb2ThinBlue->hide(); - ui->cb2BlendBlue->hide(); - } } void BitmapColoring::checkAllKeyframesBoxes() @@ -346,12 +318,9 @@ void BitmapColoring::thinLines() { if (mLayerBitmap == nullptr) { return; } - if (!ui->cb3ThinAllKeyframes->isChecked()) + if (!ui->cb3ThinAllKeyframes->isChecked() && mLayerBitmap->keyExists(mEditor->currentFrame())) { - if (mLayerBitmap->keyExists(mEditor->currentFrame())) - { - thin(); - } + thin(); } else { @@ -366,10 +335,10 @@ void BitmapColoring::thinLines() { if (mLayerBitmap->keyExists(i)) { - mEditor->scrubTo(i); - thin(); mProgress->setValue(keysThinned++); QApplication::processEvents(); + mEditor->scrubTo(i); + thin(); } if (mProgress->wasCanceled()) { @@ -404,7 +373,7 @@ void BitmapColoring::blendLines() orgName.chop(2); LayerBitmap* artLayer = static_cast(mEditor->layers()->findLayerByName(orgName)); - if (!ui->cb3BlendAllKeyframes->isChecked()) + if (!ui->cb3BlendAllKeyframes->isChecked() && mLayerBitmap->keyExists(mEditor->currentFrame())) { blend(artLayer); } @@ -436,28 +405,8 @@ void BitmapColoring::blendLines() } // protected functions -void BitmapColoring::traceScansToTransparent() -{ - if (ui->cb1Threshold->isChecked()) - { - mEditor->copy(); - mEditor->layers()->currentLayer()->removeKeyFrame(mEditor->currentFrame()); - mEditor->layers()->currentLayer()->addNewKeyFrameAt(mEditor->currentFrame()); - mEditor->paste(); - } - mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); - mBitmapImage = mBitmapImage->scanToTransparent(mBitmapImage, - true, - ui->cb2TraceRed->isChecked(), - ui->cb2TraceGreen->isChecked(), - ui->cb2TraceBlue->isChecked()); -} - void BitmapColoring::prepareLines() { - if (mLayerBitmap == nullptr) { return; } - if (!mLayerBitmap->keyExists(mEditor->currentFrame())) { return; } - LayerBitmap* colorLayer = nullptr; if (ui->cbMethodSelector->currentIndex() == 0) { // if coloring is on same layer... @@ -471,7 +420,8 @@ void BitmapColoring::prepareLines() mLayerBitmap->setHasColorLayer(true); colorLayer->setIsColorLayer(true); } - else { + else + { colorLayer = static_cast(mEditor->layers()->findLayerByName(mLayerBitmap->name() + "_C")); } } @@ -490,8 +440,12 @@ void BitmapColoring::prepareLines() void BitmapColoring::trace() { - if (ui->cb1Threshold->isChecked()) - traceScansToTransparent(); + mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); + mBitmapImage = mBitmapImage->scanToTransparent(mBitmapImage, + true, + ui->cb2TraceRed->isChecked(), + ui->cb2TraceGreen->isChecked(), + ui->cb2TraceBlue->isChecked()); prepareLines(); } diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 3c11b3ecac..91a50d330f 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -52,7 +52,6 @@ public slots: void blendLines(); protected: - void traceScansToTransparent(); void prepareLines(); void trace(); void thin(); diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 0233a9f8d3..ecc50ec73e 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -660,8 +660,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool black Q_ASSERT(bitmapimage != nullptr); BitmapImage* img = bitmapimage; - img->enableAutoCrop(true); - img->autoCrop(); + img->enableAutoCrop(false); QRgb rgba; for (int x = img->left(); x <= img->right(); x++) @@ -673,7 +672,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool black { img->setPixel(x, y, transp); } // IF Red line - else if(qRed(rgba) - 50 > qGreen(rgba)) + else if(qRed(rgba) -40 > qGreen(rgba) && qRed(rgba) > qBlue(rgba)) { if (red) { @@ -684,7 +683,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool black img->setPixel(x, y, transp); } } // IF Blue line - else if(qBlue(rgba) - 50 > qRed(rgba) && qBlue(rgba) > qGreen(rgba)) + else if(qBlue(rgba) -40 > qRed(rgba) && qBlue(rgba) > qGreen(rgba)) { if (blue) { @@ -695,7 +694,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool black img->setPixel(x, y, transp); } } // IF Green line - else if(qGreen(rgba) - 50 > qRed(rgba) && qGreen(rgba) > qBlue(rgba)) + else if(qGreen(rgba) -40 > qRed(rgba) && qGreen(rgba) > qBlue(rgba)) { if (green) { @@ -765,7 +764,8 @@ void BitmapImage::traceLine(BitmapImage* bitmapimage, bool black, bool red, bool void BitmapImage::fillSpotAreas(BitmapImage *bitmapimage) { - if (bitmapimage == nullptr) { return; } + Q_ASSERT(bitmapimage != nullptr); + BitmapImage* img = bitmapimage; // fill areas size 'area' or less with appropriate color From 8c5bfcee184b604cf083c0a96d346e47140664ba Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 10 Mar 2019 20:55:47 +0100 Subject: [PATCH 058/100] Bug in Blend corrected --- app/src/bitmapcoloring.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 32f313b472..c684d8a1dd 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -372,6 +372,7 @@ void BitmapColoring::blendLines() QString orgName = mLayerBitmap->name(); orgName.chop(2); LayerBitmap* artLayer = static_cast(mEditor->layers()->findLayerByName(orgName)); + if (artLayer == nullptr) { return; } if (!ui->cb3BlendAllKeyframes->isChecked() && mLayerBitmap->keyExists(mEditor->currentFrame())) { @@ -442,7 +443,7 @@ void BitmapColoring::trace() { mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); mBitmapImage = mBitmapImage->scanToTransparent(mBitmapImage, - true, + ui->cb2TraceBlack->isChecked(), // true; ui->cb2TraceRed->isChecked(), ui->cb2TraceGreen->isChecked(), ui->cb2TraceBlue->isChecked()); @@ -475,12 +476,14 @@ void BitmapColoring::blend(LayerBitmap *artLayer) mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Blend lines")); if (ui->cbMethodSelector->currentIndex() == 1 && artLayer != nullptr) { + mLayerBitmap = artLayer; artLayer->getBitmapImageAtFrame(mEditor->currentFrame())->traceLine(artLayer->getBitmapImageAtFrame(mEditor->currentFrame()), false, false, false, false); mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Blend lines")); + mLayerBitmap = static_cast(mEditor->layers()->currentLayer()); } updateUI(); } From 589eb1fdd4f305cf7e4ad203efefdda2f38238ba Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 10 Mar 2019 23:44:49 +0100 Subject: [PATCH 059/100] Reset button on Trace-tab. --- app/src/bitmapcoloring.cpp | 15 ++++++++++++--- app/src/bitmapcoloring.h | 1 + app/ui/bitmapcoloringwidget.ui | 7 +++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index c684d8a1dd..0e68b79432 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -50,6 +50,7 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : connect(ui->cb2TraceGreen, &QCheckBox::stateChanged, this, &BitmapColoring::checkGreenBoxes); connect(ui->cb2TraceBlue, &QCheckBox::stateChanged, this, &BitmapColoring::checkBlueBoxes); connect(ui->cb3TraceAllKeyframes, &QCheckBox::stateChanged, this, &BitmapColoring::checkAllKeyframesBoxes); + connect(ui->btnResetTrace, &QPushButton::clicked, this, &BitmapColoring::resetColoringDock); // Prepare connect(ui->tabWidget, &QTabWidget::tabBarClicked, this, &BitmapColoring::tabWidgetClicked); @@ -198,6 +199,16 @@ void BitmapColoring::tabWidgetClicked(int index) } } +void BitmapColoring::resetColoringDock() +{ + ui->cbMethodSelector->setCurrentIndex(0); + ui->cb1Threshold->setChecked(false); + ui->cb2TraceRed->setChecked(false); + ui->cb2TraceGreen->setChecked(false); + ui->cb2TraceBlue->setChecked(false); + ui->cb3TraceAllKeyframes->setChecked(false); +} + // public Trace funtions void BitmapColoring::updateTraceBoxes() { @@ -443,7 +454,7 @@ void BitmapColoring::trace() { mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); mBitmapImage = mBitmapImage->scanToTransparent(mBitmapImage, - ui->cb2TraceBlack->isChecked(), // true; + ui->cb2TraceBlack->isChecked(), ui->cb2TraceRed->isChecked(), ui->cb2TraceGreen->isChecked(), ui->cb2TraceBlue->isChecked()); @@ -476,14 +487,12 @@ void BitmapColoring::blend(LayerBitmap *artLayer) mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Blend lines")); if (ui->cbMethodSelector->currentIndex() == 1 && artLayer != nullptr) { - mLayerBitmap = artLayer; artLayer->getBitmapImageAtFrame(mEditor->currentFrame())->traceLine(artLayer->getBitmapImageAtFrame(mEditor->currentFrame()), false, false, false, false); mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Blend lines")); - mLayerBitmap = static_cast(mEditor->layers()->currentLayer()); } updateUI(); } diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 91a50d330f..014ff5088b 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -37,6 +37,7 @@ public slots: void checkBlueBoxes(); void checkAllKeyframesBoxes(); void tabWidgetClicked(int index); + void resetColoringDock(); // 1: Trace void updateTraceBoxes(); void updateBtnSelect(); diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index d66d4a5806..dca6961dbf 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -388,6 +388,13 @@ + + + + Reset + + + From 0767c9d0da640383083f6549e6160cc94d4a5a2e Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Mon, 11 Mar 2019 15:59:53 +0100 Subject: [PATCH 060/100] Bug when using select tool corrected --- app/src/bitmapcoloring.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 0e68b79432..2f7c6c41e2 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -452,6 +452,13 @@ void BitmapColoring::prepareLines() void BitmapColoring::trace() { + if (mSelectAreas) + { + mEditor->copy(); + mLayerBitmap->removeKeyFrame(mEditor->currentFrame()); + mLayerBitmap->addNewKeyFrameAt(mEditor->currentFrame()); + mEditor->paste(); + } mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); mBitmapImage = mBitmapImage->scanToTransparent(mBitmapImage, ui->cb2TraceBlack->isChecked(), From fa9cf8b9147bb73af9c27b9e94fc0b6451bd3d89 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Mon, 11 Mar 2019 20:50:11 +0100 Subject: [PATCH 061/100] Removed Black from filters --- app/src/bitmapcoloring.cpp | 64 ++++++------------- app/src/bitmapcoloring.h | 2 - app/ui/bitmapcoloringwidget.ui | 111 --------------------------------- 3 files changed, 19 insertions(+), 158 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 2f7c6c41e2..f02e1b124a 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -39,13 +39,10 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : mLayerBitmap = static_cast(mEditor->layers()->currentLayer()); mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); ui->btnSelectAreas->setIcon(QIcon(":/icons/select.png")); - checkBlackBoxes(); checkRedBoxes(); checkGreenBoxes(); checkBlueBoxes(); - connect(ui->cbMethodSelector, QOverload::of(&QComboBox::currentIndexChanged), this, &BitmapColoring::colorMethodChanged); - connect(ui->cb2TraceBlack, &QCheckBox::stateChanged, this, &BitmapColoring::checkBlackBoxes); connect(ui->cb2TraceRed, &QCheckBox::stateChanged, this, &BitmapColoring::checkRedBoxes); connect(ui->cb2TraceGreen, &QCheckBox::stateChanged, this, &BitmapColoring::checkGreenBoxes); connect(ui->cb2TraceBlue, &QCheckBox::stateChanged, this, &BitmapColoring::checkBlueBoxes); @@ -119,35 +116,6 @@ void BitmapColoring::visibilityChanged(bool visibility) updateUI(); } -void BitmapColoring::colorMethodChanged() -{ - if (ui->cbMethodSelector->currentIndex() == 0) - { - ui->cb2TraceBlack->setChecked(false); - ui->cb2TraceBlack->setEnabled(false); - ui->cb2ThinBlack->setChecked(false); - ui->cb2ThinBlack->setEnabled(false); - ui->cb2BlendBlack->setChecked(false); - ui->cb2BlendBlack->setEnabled(false); - } - else - { - ui->cb2TraceBlack->setEnabled(true); - ui->cb2ThinBlack->setEnabled(true); - ui->cb2BlendBlack->setEnabled(true); - ui->cb2TraceBlack->setChecked(true); - } -} - -void BitmapColoring::checkBlackBoxes() -{ - if (ui->cb2TraceBlack->isChecked()) - { - ui->cb2ThinBlack->setChecked(ui->cb2TraceBlack->isChecked()); - ui->cb2BlendBlack->setChecked(ui->cb2TraceBlack->isChecked()); - } -} - void BitmapColoring::checkRedBoxes() { if (ui->cb2TraceRed->isChecked()) @@ -203,6 +171,9 @@ void BitmapColoring::resetColoringDock() { ui->cbMethodSelector->setCurrentIndex(0); ui->cb1Threshold->setChecked(false); + ui->sb1Threshold->setValue(220); + ui->cbSpotAreas->setChecked(false); + ui->sbSpotAreas->setValue(6); ui->cb2TraceRed->setChecked(false); ui->cb2TraceGreen->setChecked(false); ui->cb2TraceBlue->setChecked(false); @@ -220,8 +191,6 @@ void BitmapColoring::updateTraceBoxes() { ui->tab1->setEnabled(true); ui->gb2Trace->setEnabled(true); - if (ui->cbMethodSelector->currentIndex() == 0) - ui->cb2TraceBlack->setEnabled(false); } } @@ -315,8 +284,6 @@ void BitmapColoring::updateThinBoxes() { ui->tab2->setEnabled(true); ui->gb2Thin->setEnabled(true); - if (ui->cbMethodSelector->currentIndex() == 0) - ui->cb2ThinBlack->setEnabled(false); } } @@ -371,8 +338,6 @@ void BitmapColoring::updateBlendBoxes() else { ui->tab3->setEnabled(true); - if (ui->cbMethodSelector->currentIndex() == 0) - ui->cb2BlendBlack->setEnabled(false); } } @@ -420,6 +385,8 @@ void BitmapColoring::blendLines() void BitmapColoring::prepareLines() { LayerBitmap* colorLayer = nullptr; + bool black; + ui->cbMethodSelector->currentIndex() == 0 ? black = false: black = true; if (ui->cbMethodSelector->currentIndex() == 0) { // if coloring is on same layer... colorLayer = mLayerBitmap; @@ -444,7 +411,7 @@ void BitmapColoring::prepareLines() mLayerBitmap->copyFrame(mLayerBitmap, colorLayer, mEditor->currentFrame()); } colorLayer->getBitmapImageAtFrame(mEditor->currentFrame())->traceLine(colorLayer->getBitmapImageAtFrame(mEditor->currentFrame()), - ui->cb2TraceBlack->isChecked(), + black, ui->cb2TraceRed->isChecked(), ui->cb2TraceGreen->isChecked(), ui->cb2TraceBlue->isChecked()); @@ -459,39 +426,46 @@ void BitmapColoring::trace() mLayerBitmap->addNewKeyFrameAt(mEditor->currentFrame()); mEditor->paste(); } + bool black; + ui->cbMethodSelector->currentIndex() == 0 ? black = false: black = true; mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); mBitmapImage = mBitmapImage->scanToTransparent(mBitmapImage, - ui->cb2TraceBlack->isChecked(), + black, ui->cb2TraceRed->isChecked(), ui->cb2TraceGreen->isChecked(), ui->cb2TraceBlue->isChecked()); prepareLines(); + mEditor->backup("Trace lines"); } void BitmapColoring::thin() { + bool black; + ui->cbMethodSelector->currentIndex() == 0 ? black = false: black = true; mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); if (ui->cbSpotAreas->isChecked()) { mBitmapImage->fillSpotAreas(mBitmapImage); } mBitmapImage->toThinLine(mBitmapImage, - ui->cb2ThinBlack->isChecked(), + black, ui->cb2ThinRed->isChecked(), ui->cb2ThinGreen->isChecked(), ui->cb2ThinBlue->isChecked()); - mEditor->backup(tr("Thin lines")); + mEditor->backup("Thin lines"); updateUI(); } void BitmapColoring::blend(LayerBitmap *artLayer) { + bool black; + ui->cbMethodSelector->currentIndex() == 0 ? black = false: black = true; mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame())->blendLines(mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()), - ui->cb2BlendBlack->isChecked(), + black, ui->cb2BlendRed->isChecked(), ui->cb2BlendGreen->isChecked(), ui->cb2BlendBlue->isChecked()); - mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Blend lines")); + mEditor->backup("Blend lines"); if (ui->cbMethodSelector->currentIndex() == 1 && artLayer != nullptr) { artLayer->getBitmapImageAtFrame(mEditor->currentFrame())->traceLine(artLayer->getBitmapImageAtFrame(mEditor->currentFrame()), @@ -499,7 +473,7 @@ void BitmapColoring::blend(LayerBitmap *artLayer) false, false, false); - mEditor->backup(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame(), tr("Blend lines")); + mEditor->backup("Blend lines"); } updateUI(); } diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 014ff5088b..0e273512d1 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -30,8 +30,6 @@ class BitmapColoring : public BaseDockWidget signals: public slots: - void colorMethodChanged(); - void checkBlackBoxes(); void checkRedBoxes(); void checkGreenBoxes(); void checkBlueBoxes(); diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index dca6961dbf..645161606d 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -200,43 +200,6 @@ 4 - - - - - - false - - - Trace Black - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - :/icons/black.png - - - - - @@ -514,43 +477,6 @@ 4 - - - - - - false - - - Thin Black - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - :/icons/black.png - - - - - @@ -767,43 +693,6 @@ 4 - - - - - - false - - - Apply to Black - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - :/icons/black.png - - - - - From 912abb5e7248ea227f48d9bf4adc05cf60b1398a Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 24 Mar 2019 22:35:23 +0100 Subject: [PATCH 062/100] Bug when tracing pencil2d drawings fixed --- app/src/bitmapcoloring.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index f02e1b124a..f6f9888e85 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -426,11 +426,9 @@ void BitmapColoring::trace() mLayerBitmap->addNewKeyFrameAt(mEditor->currentFrame()); mEditor->paste(); } - bool black; - ui->cbMethodSelector->currentIndex() == 0 ? black = false: black = true; mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); mBitmapImage = mBitmapImage->scanToTransparent(mBitmapImage, - black, + mSelectAreas, ui->cb2TraceRed->isChecked(), ui->cb2TraceGreen->isChecked(), ui->cb2TraceBlue->isChecked()); From 5e6fe849e41e233753e1034205899d0eb3765ea8 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Tue, 2 Jul 2019 22:12:11 +0200 Subject: [PATCH 063/100] Applying changes from scribblearea refactoring --- app/src/bitmapcoloring.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index f6f9888e85..b4792d6e1f 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -20,6 +20,7 @@ GNU General Public License for more details. #include "ui_bitmapcoloringwidget.h" #include "layermanager.h" #include "toolmanager.h" +#include "selectionmanager.h" #include "app_util.h" @@ -232,7 +233,7 @@ void BitmapColoring::traceLines() { if (mLayerBitmap == nullptr) { return; } - if (mSelectAreas && !mScribblearea->isSomethingSelected()) + if (mSelectAreas && !mEditor->select()->somethingSelected()) { QMessageBox::information(this, tr("No selection!"), tr("Please select area with select tool...")); return; @@ -268,7 +269,7 @@ void BitmapColoring::traceLines() { trace(); } - mScribblearea->deselectAll(); + mEditor->deselectAll(); ui->cb1Threshold->setChecked(false); updateBtnSelect(); } From f2ac696d4b1ba46f837a813839835cbc3cefed16 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Tue, 1 Oct 2019 22:13:28 +0200 Subject: [PATCH 064/100] Force choose method. Make selecttool button more intuitive --- app/src/bitmapcoloring.cpp | 62 ++++++++------------ app/src/bitmapcoloring.h | 2 +- app/ui/bitmapcoloringwidget.ui | 31 ++++++++-- core_lib/src/graphics/bitmap/bitmapimage.cpp | 11 ++-- 4 files changed, 55 insertions(+), 51 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index b4792d6e1f..93b3184866 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -49,12 +49,12 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : connect(ui->cb2TraceBlue, &QCheckBox::stateChanged, this, &BitmapColoring::checkBlueBoxes); connect(ui->cb3TraceAllKeyframes, &QCheckBox::stateChanged, this, &BitmapColoring::checkAllKeyframesBoxes); connect(ui->btnResetTrace, &QPushButton::clicked, this, &BitmapColoring::resetColoringDock); + connect(ui->cbMethodSelector, QOverload::of(&QComboBox::currentIndexChanged), this, &BitmapColoring::enableTabs); // Prepare connect(ui->tabWidget, &QTabWidget::tabBarClicked, this, &BitmapColoring::tabWidgetClicked); - connect(ui->cb1Threshold, &QCheckBox::stateChanged, this, &BitmapColoring::updateBtnSelect); + connect(mEditor->select(), &SelectionManager::selectionChanged, this, &BitmapColoring::updateBtnSelect); connect(ui->sb1Threshold, QOverload::of(&QSpinBox::valueChanged), this, &BitmapColoring::setThreshold); - connect(ui->btnSelectAreas, &QPushButton::clicked, this, &BitmapColoring::activateSelectTool); connect(ui->btnApplyTrace, &QPushButton::clicked, this, &BitmapColoring::traceLines); // Thin connect(ui->sbSpotAreas, QOverload::of(&QSpinBox::valueChanged), this, &BitmapColoring::setSpotArea); @@ -81,7 +81,8 @@ void BitmapColoring::updateUI() mLayerBitmap = static_cast(mEditor->layers()->currentLayer()); if (mLayerBitmap == nullptr) { return; } - if (mEditor->layers()->currentLayer()->type() == Layer::BITMAP) + if (mEditor->layers()->currentLayer()->type() == Layer::BITMAP && + ui->cbMethodSelector->currentIndex() > 0) { if (mLayerBitmap->getHasColorLayer()) { @@ -103,7 +104,7 @@ void BitmapColoring::updateUI() } } else - { // If it is not a Bitmap Layer - disable + { // If it is not a Bitmap Layer OR method not chosen - disable ui->tab1->setEnabled(false); ui->tab2->setEnabled(false); ui->tab3->setEnabled(false); @@ -181,6 +182,12 @@ void BitmapColoring::resetColoringDock() ui->cb3TraceAllKeyframes->setChecked(false); } +void BitmapColoring::enableTabs(int index) +{ + Q_UNUSED(index) + updateUI(); +} + // public Trace funtions void BitmapColoring::updateTraceBoxes() { @@ -188,7 +195,7 @@ void BitmapColoring::updateTraceBoxes() { ui->tab1->setEnabled(false); } - else + else if (ui->cbMethodSelector->currentIndex() > 0) { ui->tab1->setEnabled(true); ui->gb2Trace->setEnabled(true); @@ -197,28 +204,13 @@ void BitmapColoring::updateTraceBoxes() void BitmapColoring::updateBtnSelect() { - if (ui->cb1Threshold->isChecked()) - { - ui->btnSelectAreas->setEnabled(true); - } - else - { - mSelectAreas = false; - ui->btnSelectAreas->setIcon(QIcon(":/icons/select.png")); - ui->btnSelectAreas->setEnabled(false); - } -} - -void BitmapColoring::activateSelectTool() -{ - if (!mSelectAreas) + if (mEditor->select()->somethingSelected()) { mSelectAreas = true; ui->btnSelectAreas->setIcon(QIcon(":/icons/select_ok.png")); - ToolManager* tool = mEditor->tools(); - tool->setCurrentTool(SELECT); } - else { + else + { mSelectAreas = false; ui->btnSelectAreas->setIcon(QIcon(":/icons/select.png")); } @@ -233,12 +225,6 @@ void BitmapColoring::traceLines() { if (mLayerBitmap == nullptr) { return; } - if (mSelectAreas && !mEditor->select()->somethingSelected()) - { - QMessageBox::information(this, tr("No selection!"), tr("Please select area with select tool...")); - return; - } - if (ui->cb3TraceAllKeyframes->isChecked()) { QProgressDialog* mProgress = new QProgressDialog(tr("Tracing lines in bitmaps..."), tr("Abort"), 0, 100, this); @@ -281,7 +267,7 @@ void BitmapColoring::updateThinBoxes() { ui->tab2->setEnabled(false); } - else + else if (ui->cbMethodSelector->currentIndex() > 0) { ui->tab2->setEnabled(true); ui->gb2Thin->setEnabled(true); @@ -336,7 +322,7 @@ void BitmapColoring::updateBlendBoxes() { ui->tab3->setEnabled(false); } - else + else if (ui->cbMethodSelector->currentIndex() > 0) { ui->tab3->setEnabled(true); } @@ -387,12 +373,12 @@ void BitmapColoring::prepareLines() { LayerBitmap* colorLayer = nullptr; bool black; - ui->cbMethodSelector->currentIndex() == 0 ? black = false: black = true; - if (ui->cbMethodSelector->currentIndex() == 0) + ui->cbMethodSelector->currentIndex() == 1 ? black = false: black = true; + if (ui->cbMethodSelector->currentIndex() == 1) { // if coloring is on same layer... colorLayer = mLayerBitmap; } - else + else if (ui->cbMethodSelector->currentIndex() == 2) { // if coloring is on separate layer... if (!mLayerBitmap->getHasColorLayer()) { @@ -406,7 +392,7 @@ void BitmapColoring::prepareLines() } } - if (ui->cbMethodSelector->currentIndex() == 1) + if (ui->cbMethodSelector->currentIndex() == 2) { colorLayer->setVisible(false); mLayerBitmap->copyFrame(mLayerBitmap, colorLayer, mEditor->currentFrame()); @@ -440,7 +426,7 @@ void BitmapColoring::trace() void BitmapColoring::thin() { bool black; - ui->cbMethodSelector->currentIndex() == 0 ? black = false: black = true; + ui->cbMethodSelector->currentIndex() == 1 ? black = false: black = true; mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); if (ui->cbSpotAreas->isChecked()) { @@ -458,14 +444,14 @@ void BitmapColoring::thin() void BitmapColoring::blend(LayerBitmap *artLayer) { bool black; - ui->cbMethodSelector->currentIndex() == 0 ? black = false: black = true; + ui->cbMethodSelector->currentIndex() == 1 ? black = false: black = true; mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame())->blendLines(mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()), black, ui->cb2BlendRed->isChecked(), ui->cb2BlendGreen->isChecked(), ui->cb2BlendBlue->isChecked()); mEditor->backup("Blend lines"); - if (ui->cbMethodSelector->currentIndex() == 1 && artLayer != nullptr) + if (ui->cbMethodSelector->currentIndex() == 2 && artLayer != nullptr) { artLayer->getBitmapImageAtFrame(mEditor->currentFrame())->traceLine(artLayer->getBitmapImageAtFrame(mEditor->currentFrame()), false, diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 0e273512d1..e43052466d 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -36,10 +36,10 @@ public slots: void checkAllKeyframesBoxes(); void tabWidgetClicked(int index); void resetColoringDock(); + void enableTabs(int index); // 1: Trace void updateTraceBoxes(); void updateBtnSelect(); - void activateSelectTool(); void setThreshold(int threshold); void traceLines(); // 2: Thin diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index 76a7cb6db0..d6b198ee64 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -6,7 +6,7 @@ 0 0 - 234 + 229 374 @@ -43,6 +43,11 @@ Colorize on Same or Separate layer? + + + Choose method... + + On the Same Layer @@ -85,7 +90,7 @@ - Scanned Drawings? + Prepare Drawings? @@ -138,8 +143,19 @@ + + + + - + + + Using Selecttool? + + + + + Qt::Horizontal @@ -154,16 +170,16 @@ - false + true - 24 + 20 16777215 - Activate Select tool + Something is selected @@ -172,6 +188,9 @@ :/icons/select.png:/icons/select.png + + true + diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 292d0282e5..a8c87a9484 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -1043,10 +1043,10 @@ void BitmapImage::blendLines(BitmapImage *bitmapimage, bool black, bool red, boo if (!rgblist.contains(img->pixel(x+1, y+1))) points.append(QPoint(x+1, y+1)); for (int i = 0; i < points.size(); i++) { - r += qPow(qRed(img->pixel(points.at(i))), 2); - g += qPow(qGreen(img->pixel(points.at(i))), 2); - b += qPow(qBlue(img->pixel(points.at(i))), 2); - a += qPow(qAlpha(img->pixel(points.at(i))), 2); + r += static_cast(qPow(qRed(img->pixel(points.at(i))), 2)); + g += static_cast(qPow(qGreen(img->pixel(points.at(i))), 2)); + b += static_cast(qPow(qBlue(img->pixel(points.at(i))), 2)); + a += static_cast(qPow(qAlpha(img->pixel(points.at(i))), 2)); } r = static_cast(sqrt(r/points.size())); g = static_cast(sqrt(g/points.size())); @@ -1074,7 +1074,7 @@ int BitmapImage::fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, Bitma QRect rect = img->bounds(); while (!fillList.isEmpty()) { - QPoint tmp = fillList.at(0); + QPoint tmp = fillList.takeFirst(); if (rect.contains(QPoint(tmp.x() + 1, tmp.y())) && img->pixel(QPoint(tmp.x() + 1, tmp.y())) == orgColor) { img->setPixel(QPoint(tmp.x() + 1, tmp.y()), newColor); @@ -1099,7 +1099,6 @@ int BitmapImage::fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, Bitma fillList.append(QPoint(tmp.x(), tmp.y() - 1)); pixels++; } - fillList.removeFirst(); } img->modification(); return pixels; From ac4f2e02e0ab3442043615c2d5e7204fdcfb088d Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Tue, 18 Feb 2020 20:21:43 +0100 Subject: [PATCH 065/100] Fixed error in fillWithColor function bitmapimage.cpp --- app/src/bitmapcoloring.cpp | 1 - core_lib/src/graphics/bitmap/bitmapimage.cpp | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 93b3184866..152123ec0b 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -295,7 +295,6 @@ void BitmapColoring::thinLines() mProgress->setMaximum(mLayerBitmap->keyFrameCount()); mProgress->setValue(0); int keysThinned = 0; - for (int i = mLayerBitmap->firstKeyFramePosition(); i <= mLayerBitmap->getMaxKeyFramePosition(); i++) { if (mLayerBitmap->keyExists(i)) diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index d6a0070f1a..9128ba45dd 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -781,9 +781,9 @@ void BitmapImage::fillSpotAreas(BitmapImage *bitmapimage) QVector points; points.clear(); QRgb active, previous = blackline; - for (int x = img->left(); x < img->right(); x++) + for (int x = img->left() + 1; x < img->right(); x++) { - for (int y = img->top(); y < img->bottom(); y++) + for (int y = img->top() + 1; y < img->bottom(); y++) { active = img->constScanLine(x, y); if (qAlpha(active) == 0) From e251a89a2f454bd6cb3f1a0966bbfbcfd319f7fa Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Thu, 20 Feb 2020 13:40:17 +0100 Subject: [PATCH 066/100] Prevent autosave while Tracing, Thinning and Blending --- app/src/bitmapcoloring.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 152123ec0b..686abb9cd2 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -234,13 +234,13 @@ void BitmapColoring::traceLines() mProgress->setMaximum(keysToTrace); mProgress->setValue(0); int keysTraced = 0; + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); for (int i = mLayerBitmap->firstKeyFramePosition(); i <= mLayerBitmap->getMaxKeyFramePosition(); i++) { if (mLayerBitmap->keyExists(i)) { mProgress->setValue(keysTraced++); - QApplication::processEvents(); mEditor->scrubTo(i); trace(); if (mProgress->wasCanceled()) @@ -295,12 +295,12 @@ void BitmapColoring::thinLines() mProgress->setMaximum(mLayerBitmap->keyFrameCount()); mProgress->setValue(0); int keysThinned = 0; + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); for (int i = mLayerBitmap->firstKeyFramePosition(); i <= mLayerBitmap->getMaxKeyFramePosition(); i++) { if (mLayerBitmap->keyExists(i)) { mProgress->setValue(keysThinned++); - QApplication::processEvents(); mEditor->scrubTo(i); thin(); } @@ -349,6 +349,7 @@ void BitmapColoring::blendLines() int keysToBlend = mLayerBitmap->keyFrameCount(); progress.setMaximum(keysToBlend); int keysBlended = 0; + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); for (int i = mLayerBitmap->firstKeyFramePosition(); i <= mLayerBitmap->getMaxKeyFramePosition(); i++) { @@ -357,7 +358,6 @@ void BitmapColoring::blendLines() mEditor->scrubTo(i); blend(artLayer); progress.setValue(keysBlended++); - QApplication::processEvents(); if (progress.wasCanceled()) { break; From e409ef422dd203681d879cdb2d96732cf40de766 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 23 Feb 2020 17:27:25 +0100 Subject: [PATCH 067/100] Disabled autosave while doing batchwork in coloring --- app/src/bitmapcoloring.cpp | 15 +++++++++++++++ core_lib/src/interface/editor.cpp | 2 +- core_lib/src/interface/editor.h | 6 ++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 686abb9cd2..643db30c21 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -227,6 +227,8 @@ void BitmapColoring::traceLines() if (ui->cb3TraceAllKeyframes->isChecked()) { + mEditor->setIsDoingRepeatColoring(true); + int count = mEditor->getAutoSaveCounter(); QProgressDialog* mProgress = new QProgressDialog(tr("Tracing lines in bitmaps..."), tr("Abort"), 0, 100, this); mProgress->setWindowModality(Qt::WindowModal); mProgress->show(); @@ -243,6 +245,7 @@ void BitmapColoring::traceLines() mProgress->setValue(keysTraced++); mEditor->scrubTo(i); trace(); + count++; if (mProgress->wasCanceled()) { break; @@ -250,6 +253,8 @@ void BitmapColoring::traceLines() } } mProgress->close(); + mEditor->setIsDoingRepeatColoring(false); + mEditor->setAutoSaveCounter(count); } else if (mLayerBitmap->keyExists(mEditor->currentFrame())) { @@ -289,6 +294,8 @@ void BitmapColoring::thinLines() } else { + mEditor->setIsDoingRepeatColoring(true); + int count = mEditor->getAutoSaveCounter(); QProgressDialog* mProgress = new QProgressDialog(tr("Thinning lines in bitmaps..."), tr("Abort"), 0, 100, this); mProgress->setWindowModality(Qt::WindowModal); mProgress->show(); @@ -303,6 +310,7 @@ void BitmapColoring::thinLines() mProgress->setValue(keysThinned++); mEditor->scrubTo(i); thin(); + count++; } if (mProgress->wasCanceled()) { @@ -310,6 +318,8 @@ void BitmapColoring::thinLines() } } mProgress->close(); + mEditor->setIsDoingRepeatColoring(false); + mEditor->setAutoSaveCounter(count); } ui->cbSpotAreas->setChecked(false); } @@ -342,6 +352,8 @@ void BitmapColoring::blendLines() } else { + mEditor->setIsDoingRepeatColoring(true); + int count = mEditor->getAutoSaveCounter(); QProgressDialog progress(tr("Blending lines in bitmaps..."), tr("Abort"), 0, 100, this); hideQuestionMark(progress); progress.setWindowModality(Qt::WindowModal); @@ -357,6 +369,7 @@ void BitmapColoring::blendLines() { mEditor->scrubTo(i); blend(artLayer); + count++; progress.setValue(keysBlended++); if (progress.wasCanceled()) { @@ -364,6 +377,8 @@ void BitmapColoring::blendLines() } } } + mEditor->setIsDoingRepeatColoring(false); + mEditor->setAutoSaveCounter(count); } } diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 8c4d19b5c3..2bb76fe290 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -496,7 +496,7 @@ void Editor::clearUndoStack() void Editor::updateAutoSaveCounter() { - if (mIsAutosave == false) + if (mIsAutosave == false || mIsDoingRepeatInColoring) return; mAutosaveCounter++; diff --git a/core_lib/src/interface/editor.h b/core_lib/src/interface/editor.h index bfb22d978c..0a71fe122b 100644 --- a/core_lib/src/interface/editor.h +++ b/core_lib/src/interface/editor.h @@ -170,6 +170,11 @@ class Editor : public QObject void dontAskAutoSave(bool b) { mAutosaveNeverAskAgain = b; } bool autoSaveNeverAskAgain() { return mAutosaveNeverAskAgain; } void resetAutoSaveCounter(); + int getAutoSaveCounter() { return mAutosaveCounter; } + void setAutoSaveCounter(int count) { mAutosaveCounter = count; } + bool getIsDoingRepeatColoring() { return mIsDoingRepeatInColoring; } + void setIsDoingRepeatColoring(bool b) { mIsDoingRepeatInColoring = b; } + void createNewBitmapLayer(const QString& name); void createNewVectorLayer(const QString& name); @@ -210,6 +215,7 @@ class Editor : public QObject int mAutosaveNumber = 12; int mAutosaveCounter = 0; bool mAutosaveNeverAskAgain = false; + bool mIsDoingRepeatInColoring = false; void makeConnections(); KeyFrame* addKeyFrame(int layerNumber, int frameNumber); From 3a30a8cb1c8f888f891ddd1e444c20ba1112a6a0 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 26 Apr 2020 13:46:10 +0200 Subject: [PATCH 068/100] Make coloring Layer visible, and move beneath Anim layer --- app/src/bitmapcoloring.cpp | 13 ++++++++++++- app/src/bitmapcoloring.h | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 643db30c21..7c1d70017f 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -253,6 +253,15 @@ void BitmapColoring::traceLines() } } mProgress->close(); + + // move colorLayer beneath Animation layer + while (mColLayer > mAnimLayer) + { + mEditor->object()->swapLayers(mColLayer, mColLayer - 1); + mColLayer--; + } + mAnimLayer++; + mEditor->setIsDoingRepeatColoring(false); mEditor->setAutoSaveCounter(count); } @@ -396,7 +405,10 @@ void BitmapColoring::prepareLines() { // if coloring is on separate layer... if (!mLayerBitmap->getHasColorLayer()) { + int currLayer = mAnimLayer = mEditor->currentLayerIndex(); colorLayer = mEditor->layers()->createBitmapLayer(mLayerBitmap->name() + "_C"); + mColLayer = mEditor->object()->getLayerCount() - 1; + mEditor->layers()->setCurrentLayer(currLayer); mLayerBitmap->setHasColorLayer(true); colorLayer->setIsColorLayer(true); } @@ -408,7 +420,6 @@ void BitmapColoring::prepareLines() if (ui->cbMethodSelector->currentIndex() == 2) { - colorLayer->setVisible(false); mLayerBitmap->copyFrame(mLayerBitmap, colorLayer, mEditor->currentFrame()); } colorLayer->getBitmapImageAtFrame(mEditor->currentFrame())->traceLine(colorLayer->getBitmapImageAtFrame(mEditor->currentFrame()), diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index e43052466d..5504db9564 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -63,6 +63,8 @@ public slots: LayerBitmap* mLayerBitmap = nullptr; BitmapImage* mBitmapImage = nullptr; bool mSelectAreas = false; + int mAnimLayer = 0; // Animation layer index + int mColLayer = 0; // Coloring layer index }; From d59f54863e81380fed4f6be2adbd59e3be097228 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 26 Apr 2020 14:25:49 +0200 Subject: [PATCH 069/100] Removed unnecessary variable --- app/src/bitmapcoloring.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 7c1d70017f..a5ccea5789 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -405,10 +405,10 @@ void BitmapColoring::prepareLines() { // if coloring is on separate layer... if (!mLayerBitmap->getHasColorLayer()) { - int currLayer = mAnimLayer = mEditor->currentLayerIndex(); + mAnimLayer = mEditor->currentLayerIndex(); // necessary since new layer becomes currentlayer colorLayer = mEditor->layers()->createBitmapLayer(mLayerBitmap->name() + "_C"); mColLayer = mEditor->object()->getLayerCount() - 1; - mEditor->layers()->setCurrentLayer(currLayer); + mEditor->layers()->setCurrentLayer(mAnimLayer); mLayerBitmap->setHasColorLayer(true); colorLayer->setIsColorLayer(true); } From ce08b0197e84ae46529dbf79a6b66139a382af5f Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 5 Jul 2020 09:22:42 +0200 Subject: [PATCH 070/100] Fixing black lines in trace --- app/src/bitmapcoloring.cpp | 11 ++++++----- core_lib/src/graphics/bitmap/bitmapimage.cpp | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index a5ccea5789..0c7999900b 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -439,11 +439,12 @@ void BitmapColoring::trace() mEditor->paste(); } mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); - mBitmapImage = mBitmapImage->scanToTransparent(mBitmapImage, - mSelectAreas, - ui->cb2TraceRed->isChecked(), - ui->cb2TraceGreen->isChecked(), - ui->cb2TraceBlue->isChecked()); + if (ui->cb1Threshold->isChecked()) + mBitmapImage = mBitmapImage->scanToTransparent(mBitmapImage, + mSelectAreas, + ui->cb2TraceRed->isChecked(), + ui->cb2TraceGreen->isChecked(), + ui->cb2TraceBlue->isChecked()); prepareLines(); mEditor->backup("Trace lines"); } diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 7273897489..be7b003450 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -741,28 +741,28 @@ void BitmapImage::traceLine(BitmapImage* bitmapimage, bool black, bool red, bool rgba = img->constScanLine(x, y); if (qAlpha(img->constScanLine(x, y)) > 0) { - if(qRed(rgba) - 50 > qGreen(rgba)) + if(qRed(rgba) > qGreen(rgba) && qRed(rgba) > qBlue(rgba)) { if(red) img->scanLine(x, y, redline); else img->scanLine(x, y, transp); } - else if(qBlue(rgba) - 50 > qRed(rgba) && qBlue(rgba) > qGreen(rgba)) + else if(qBlue(rgba) > qRed(rgba) && qBlue(rgba) > qGreen(rgba)) { if(blue) img->scanLine(x, y, blueline); else img->scanLine(x, y, transp); } - else if(qGreen(rgba) - 50 > qRed(rgba) && qGreen(rgba) > qBlue(rgba)) + else if(qGreen(rgba) > qRed(rgba) && qGreen(rgba) > qBlue(rgba)) { if(green) img->scanLine(x, y, greenline); else img->scanLine(x, y, transp); } - else if(black) + else if(black && qRed(rgba) == qGreen(rgba) && qRed(rgba) == qBlue(rgba)) { img->scanLine(x, y, blackline); } From ec48140ca140526deef0462361006b298a486a49 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 5 Jul 2020 15:18:33 +0200 Subject: [PATCH 071/100] Testing debug messages --- core_lib/src/graphics/bitmap/bitmapimage.cpp | 2 ++ core_lib/src/interface/timeline.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index be7b003450..458b342dea 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -730,6 +730,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool black void BitmapImage::traceLine(BitmapImage* bitmapimage, bool black, bool red, bool green, bool blue) { + qDebug() << "in traceline..."; Q_ASSERT(bitmapimage != nullptr); BitmapImage* img = bitmapimage; @@ -764,6 +765,7 @@ void BitmapImage::traceLine(BitmapImage* bitmapimage, bool black, bool red, bool } else if(black && qRed(rgba) == qGreen(rgba) && qRed(rgba) == qBlue(rgba)) { + qDebug() << "gray red green: " << qGray(rgba) << " " << qRed(rgba) << " " << qGreen(rgba); img->scanLine(x, y, blackline); } } diff --git a/core_lib/src/interface/timeline.cpp b/core_lib/src/interface/timeline.cpp index fb01dcff18..bfc8d7fd0b 100644 --- a/core_lib/src/interface/timeline.cpp +++ b/core_lib/src/interface/timeline.cpp @@ -151,7 +151,6 @@ void TimeLine::initUI() timelineButtons->addWidget(zoomLabel); timelineButtons->addWidget(zoomSlider); timelineButtons->addSeparator(); - timelineButtons->addSeparator(); timelineButtons->setFixedHeight(30); // --------- Time controls --------- @@ -171,6 +170,7 @@ void TimeLine::initUI() QGridLayout* rightLayout = new QGridLayout(); rightLayout->addWidget(rightToolBar, 0, 0); + rightLayout->setAlignment(Qt::AlignLeft); rightLayout->addWidget(mTracks, 1, 0); rightLayout->setMargin(0); rightLayout->setSpacing(0); From 26c5f6fe780e53bd79a43ecef98fe0066075d8e7 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 5 Jul 2020 17:59:02 +0200 Subject: [PATCH 072/100] Disabling checkboxes in thin and blend, to avoid mistakes --- app/ui/bitmapcoloringwidget.ui | 20 +++++++++++++++++++- core_lib/src/graphics/bitmap/bitmapimage.cpp | 4 +--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index d6b198ee64..cbb80ca145 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -6,7 +6,7 @@ 0 0 - 229 + 239 374 @@ -500,6 +500,9 @@ + + false + Thin Red @@ -534,6 +537,9 @@ + + false + Thin Green @@ -568,6 +574,9 @@ + + false + Thin Blue @@ -716,6 +725,9 @@ + + false + Blend Red @@ -750,6 +762,9 @@ + + false + Blend Green @@ -784,6 +799,9 @@ + + false + Blend Blue diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 458b342dea..5a86eb82cf 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -730,7 +730,6 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool black void BitmapImage::traceLine(BitmapImage* bitmapimage, bool black, bool red, bool green, bool blue) { - qDebug() << "in traceline..."; Q_ASSERT(bitmapimage != nullptr); BitmapImage* img = bitmapimage; @@ -763,9 +762,8 @@ void BitmapImage::traceLine(BitmapImage* bitmapimage, bool black, bool red, bool else img->scanLine(x, y, transp); } - else if(black && qRed(rgba) == qGreen(rgba) && qRed(rgba) == qBlue(rgba)) + else if(black && qRed(rgba) == qGray(rgba)) { - qDebug() << "gray red green: " << qGray(rgba) << " " << qRed(rgba) << " " << qGreen(rgba); img->scanLine(x, y, blackline); } } From c24ff6dacaae764bcd90d94c82839b4f08eca07c Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Mon, 6 Jul 2020 14:34:11 +0200 Subject: [PATCH 073/100] Refactoring coloring feature --- app/app.pro | 3 + app/src/addtransparencytopaperdialog.cpp | 92 +++++++ app/src/addtransparencytopaperdialog.h | 37 +++ app/src/bitmapcoloring.cpp | 78 +++--- app/src/bitmapcoloring.h | 3 +- app/src/mainwindow2.cpp | 26 +- app/src/mainwindow2.h | 4 + app/src/preferencesdialog.cpp | 2 +- app/ui/addtransparencytopaperdialog.ui | 247 +++++++++++++++++++ app/ui/bitmapcoloringwidget.ui | 165 +++---------- app/ui/mainwindow2.ui | 21 +- core_lib/src/graphics/bitmap/bitmapimage.cpp | 39 +-- core_lib/src/graphics/bitmap/bitmapimage.h | 2 +- 13 files changed, 529 insertions(+), 190 deletions(-) create mode 100644 app/src/addtransparencytopaperdialog.cpp create mode 100644 app/src/addtransparencytopaperdialog.h create mode 100644 app/ui/addtransparencytopaperdialog.ui diff --git a/app/app.pro b/app/app.pro index 03701c5ab8..58e012379b 100644 --- a/app/app.pro +++ b/app/app.pro @@ -40,6 +40,7 @@ INCLUDEPATH += \ PRECOMPILED_HEADER = src/app-pch.h HEADERS += \ + src/addtransparencytopaperdialog.h \ src/app-pch.h \ src/importlayersdialog.h \ src/importpositiondialog.h \ @@ -77,6 +78,7 @@ HEADERS += \ src/presetdialog.h SOURCES += \ + src/addtransparencytopaperdialog.cpp \ src/importlayersdialog.cpp \ src/importpositiondialog.cpp \ src/main.cpp \ @@ -113,6 +115,7 @@ SOURCES += \ src/presetdialog.cpp FORMS += \ + ui/addtransparencytopaperdialog.ui \ ui/importimageseqpreview.ui \ ui/importlayersdialog.ui \ ui/importpositiondialog.ui \ diff --git a/app/src/addtransparencytopaperdialog.cpp b/app/src/addtransparencytopaperdialog.cpp new file mode 100644 index 0000000000..8fa1f40c20 --- /dev/null +++ b/app/src/addtransparencytopaperdialog.cpp @@ -0,0 +1,92 @@ +#include "addtransparencytopaperdialog.h" +#include "ui_addtransparencytopaperdialog.h" + +#include "editor.h" +#include "layermanager.h" +#include "selectionmanager.h" +#include "layerbitmap.h" +#include "bitmapimage.h" + +AddTransparencyToPaperDialog::AddTransparencyToPaperDialog(QWidget *parent) : + QWidget(parent), + ui(new Ui::AddTransparencyToPaperDialog) +{ + ui->setupUi(this); + + connect(ui->btnCancel, &QPushButton::clicked, this, &AddTransparencyToPaperDialog::closeClicked); + connect(ui->btnTrace, &QPushButton::clicked, this, &AddTransparencyToPaperDialog::traceScannedDrawings); +} + +AddTransparencyToPaperDialog::~AddTransparencyToPaperDialog() +{ + delete ui; +} + +void AddTransparencyToPaperDialog::setCore(Editor *editor) +{ + mEditor = editor; + connect(mEditor->layers(), &LayerManager::currentLayerChanged, this, &AddTransparencyToPaperDialog::updateTraceButton); +} + +void AddTransparencyToPaperDialog::updateTraceButton() +{ + if (mEditor->layers()->currentLayer()->type() == Layer::BITMAP) + ui->btnTrace->setEnabled(true); + else + ui->btnTrace->setEnabled(false); +} + +void AddTransparencyToPaperDialog::traceScannedDrawings() +{ + if (mEditor->layers()->currentLayer()->type() != Layer::BITMAP) { return; } + + LayerBitmap* layer = static_cast(mEditor->layers()->currentLayer()); + BitmapImage* img = new BitmapImage(); + bool somethingSelected = mEditor->select()->somethingSelected(); + + if (ui->rbCurrentKeyframe->isChecked() && layer->keyExists(mEditor->currentFrame())) + { + if (somethingSelected) + { + mEditor->copy(); + layer->removeKeyFrame(mEditor->currentFrame()); + layer->addNewKeyFrameAt(mEditor->currentFrame()); + mEditor->paste(); + } + img = layer->getBitmapImageAtFrame(mEditor->currentFrame()); + img->setThreshold(ui->sb_treshold->value()); + img = img->scanToTransparent(img, + ui->cb_Red->isChecked(), + ui->cb_Green->isChecked(), + ui->cb_Blue->isChecked()); + } + else + { + for (int i = layer->firstKeyFramePosition(); i <= layer->getMaxKeyFramePosition(); i++) + { + mEditor->scrubTo(i); + if (layer->keyExists(i)) + { + if (somethingSelected) + { + mEditor->copy(); + layer->removeKeyFrame(i); + layer->addNewKeyFrameAt(i); + mEditor->paste(); + } + img = layer->getBitmapImageAtFrame(i); + img->setThreshold(ui->sb_treshold->value()); + img = img->scanToTransparent(img, + ui->cb_Red->isChecked(), + ui->cb_Green->isChecked(), + ui->cb_Blue->isChecked()); + } + } + } +} + +void AddTransparencyToPaperDialog::closeClicked() +{ + emit closeDialog(); + close(); +} diff --git a/app/src/addtransparencytopaperdialog.h b/app/src/addtransparencytopaperdialog.h new file mode 100644 index 0000000000..a50c7fbd85 --- /dev/null +++ b/app/src/addtransparencytopaperdialog.h @@ -0,0 +1,37 @@ +#ifndef ADDTRANSPARENCYTOPAPERDIALOG_H +#define ADDTRANSPARENCYTOPAPERDIALOG_H + +#include + +class Editor; + +namespace Ui { +class AddTransparencyToPaperDialog; +} + +class AddTransparencyToPaperDialog : public QWidget +{ + Q_OBJECT + +public: + explicit AddTransparencyToPaperDialog(QWidget *parent = nullptr); + ~AddTransparencyToPaperDialog(); + + void setCore(Editor* editor); + +public slots: + void updateTraceButton(); + +signals: + void closeDialog(); + +private: + Ui::AddTransparencyToPaperDialog *ui; + + void traceScannedDrawings(); + void closeClicked(); + + Editor* mEditor = nullptr; +}; + +#endif // ADDTRANSPARENCYTOPAPERDIALOG_H diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 0c7999900b..1aa72b7c8c 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -28,7 +28,7 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : BaseDockWidget(parent) { QWidget* innerWidget = new QWidget; - setWindowTitle(tr("Bitmap Coloring")); + setWindowTitle(tr("Advanced Bitmap Coloring")); ui = new Ui::BitmapColoringWidget; ui->setupUi(innerWidget); @@ -39,7 +39,6 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : if (mEditor->layers()->currentLayer()->type() == Layer::BITMAP) mLayerBitmap = static_cast(mEditor->layers()->currentLayer()); mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); - ui->btnSelectAreas->setIcon(QIcon(":/icons/select.png")); checkRedBoxes(); checkGreenBoxes(); checkBlueBoxes(); @@ -53,11 +52,11 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : // Prepare connect(ui->tabWidget, &QTabWidget::tabBarClicked, this, &BitmapColoring::tabWidgetClicked); - connect(mEditor->select(), &SelectionManager::selectionChanged, this, &BitmapColoring::updateBtnSelect); - connect(ui->sb1Threshold, QOverload::of(&QSpinBox::valueChanged), this, &BitmapColoring::setThreshold); connect(ui->btnApplyTrace, &QPushButton::clicked, this, &BitmapColoring::traceLines); // Thin connect(ui->sbSpotAreas, QOverload::of(&QSpinBox::valueChanged), this, &BitmapColoring::setSpotArea); + connect(ui->cbSpotAreas, &QCheckBox::stateChanged, this, &BitmapColoring::updateFillSpotsButton); + connect(ui->btnFillAreas, &QPushButton::clicked, this, &BitmapColoring::fillSpotAreas); connect(ui->btnApplyThin, &QPushButton::clicked, this, &BitmapColoring::thinLines); // Finish connect(ui->btnApplyBlend, &QPushButton::clicked, this, &BitmapColoring::blendLines); @@ -147,7 +146,7 @@ void BitmapColoring::checkBlueBoxes() void BitmapColoring::checkAllKeyframesBoxes() { - ui->cb3ThinAllKeyframes->setChecked(ui->cb3TraceAllKeyframes->isChecked()); + ui->cbThinAllKeyframes->setChecked(ui->cb3TraceAllKeyframes->isChecked()); ui->cb3BlendAllKeyframes->setChecked(ui->cb3TraceAllKeyframes->isChecked()); } @@ -172,8 +171,6 @@ void BitmapColoring::tabWidgetClicked(int index) void BitmapColoring::resetColoringDock() { ui->cbMethodSelector->setCurrentIndex(0); - ui->cb1Threshold->setChecked(false); - ui->sb1Threshold->setValue(220); ui->cbSpotAreas->setChecked(false); ui->sbSpotAreas->setValue(6); ui->cb2TraceRed->setChecked(false); @@ -202,20 +199,6 @@ void BitmapColoring::updateTraceBoxes() } } -void BitmapColoring::updateBtnSelect() -{ - if (mEditor->select()->somethingSelected()) - { - mSelectAreas = true; - ui->btnSelectAreas->setIcon(QIcon(":/icons/select_ok.png")); - } - else - { - mSelectAreas = false; - ui->btnSelectAreas->setIcon(QIcon(":/icons/select.png")); - } -} - void BitmapColoring::setThreshold(int threshold) { mBitmapImage->setThreshold(threshold); @@ -270,8 +253,41 @@ void BitmapColoring::traceLines() trace(); } mEditor->deselectAll(); - ui->cb1Threshold->setChecked(false); - updateBtnSelect(); +} + +void BitmapColoring::updateFillSpotsButton() +{ + if (ui->cbSpotAreas->isChecked()) + ui->btnFillAreas->setEnabled(true); + else + ui->btnFillAreas->setEnabled(false); +} + +void BitmapColoring::fillSpotAreas() +{ + if (!ui->cbThinAllKeyframes->isChecked() && mLayerBitmap->keyExists(mEditor->currentFrame())) + { + mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); + mBitmapImage->setSpotArea(ui->sbSpotAreas->value()); + mBitmapImage->fillSpotAreas(mBitmapImage); + mBitmapImage->modification(); + mEditor->scrubTo(mEditor->currentFrame()); + } + else + { + for (int i = mLayerBitmap->firstKeyFramePosition(); i <= mLayerBitmap->getMaxKeyFramePosition(); i++) + { + if (mLayerBitmap->keyExists(i)) + { + mEditor->scrubTo(i); + mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); + mBitmapImage->setSpotArea(ui->sbSpotAreas->value()); + mBitmapImage->fillSpotAreas(mBitmapImage); + mBitmapImage->modification(); + } + } + } + updateUI(); } // public Thin functions @@ -297,7 +313,7 @@ void BitmapColoring::thinLines() { if (mLayerBitmap == nullptr) { return; } - if (!ui->cb3ThinAllKeyframes->isChecked() && mLayerBitmap->keyExists(mEditor->currentFrame())) + if (!ui->cbThinAllKeyframes->isChecked() && mLayerBitmap->keyExists(mEditor->currentFrame())) { thin(); } @@ -351,7 +367,9 @@ void BitmapColoring::blendLines() if (mLayerBitmap == nullptr) { return; } QString orgName = mLayerBitmap->name(); - orgName.chop(2); + if (ui->cbMethodSelector->currentIndex() == 2) + orgName.chop(2); + qDebug() << "artlayer: " << orgName; LayerBitmap* artLayer = static_cast(mEditor->layers()->findLayerByName(orgName)); if (artLayer == nullptr) { return; } @@ -439,12 +457,6 @@ void BitmapColoring::trace() mEditor->paste(); } mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); - if (ui->cb1Threshold->isChecked()) - mBitmapImage = mBitmapImage->scanToTransparent(mBitmapImage, - mSelectAreas, - ui->cb2TraceRed->isChecked(), - ui->cb2TraceGreen->isChecked(), - ui->cb2TraceBlue->isChecked()); prepareLines(); mEditor->backup("Trace lines"); } @@ -454,10 +466,6 @@ void BitmapColoring::thin() bool black; ui->cbMethodSelector->currentIndex() == 1 ? black = false: black = true; mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); - if (ui->cbSpotAreas->isChecked()) - { - mBitmapImage->fillSpotAreas(mBitmapImage); - } mBitmapImage->toThinLine(mBitmapImage, black, ui->cb2ThinRed->isChecked(), diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 5504db9564..655870919f 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -39,10 +39,11 @@ public slots: void enableTabs(int index); // 1: Trace void updateTraceBoxes(); - void updateBtnSelect(); void setThreshold(int threshold); void traceLines(); // 2: Thin + void updateFillSpotsButton(); + void fillSpotAreas(); void updateThinBoxes(); void setSpotArea(int size); void thinLines(); diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index d265f8ae99..93b335579a 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -283,7 +283,8 @@ void MainWindow2::createMenus() connect(mEditor->select(), &SelectionManager::selectionChanged, this, &MainWindow2::selectionChanged); connect(ui->actionFlip_X, &QAction::triggered, mCommands, &ActionCommands::flipSelectionX); connect(ui->actionFlip_Y, &QAction::triggered, mCommands, &ActionCommands::flipSelectionY); - connect(ui->actionPegbarAlignment, &QAction::triggered, this, &MainWindow2::openPegAlignDialog); + connect(ui->actionPeg_bar_Alignment, &QAction::triggered, this, &MainWindow2::openPegAlignDialog); + connect(ui->actionAdd_Transparency_to_paper, &QAction::triggered, this, &MainWindow2::openAddTranspToPaperDialog); connect(ui->actionSelect_All, &QAction::triggered, mCommands, &ActionCommands::selectAll); connect(ui->actionDeselect_All, &QAction::triggered, mCommands, &ActionCommands::deselectAll); connect(ui->actionPreference, &QAction::triggered, [=] { preferences(); }); @@ -478,6 +479,29 @@ void MainWindow2::closePegAlignDialog() mPegAlign = nullptr; } +void MainWindow2::openAddTranspToPaperDialog() +{ + if (mAddTranspToPaper != nullptr) + { + QMessageBox::information(this, nullptr, + tr("Dialog is already open!"), + QMessageBox::Ok); + return; + } + + mAddTranspToPaper = new AddTransparencyToPaperDialog(); + connect(mAddTranspToPaper, &AddTransparencyToPaperDialog::closeDialog, this , &MainWindow2::closeAddTranspToPaperDialog); + mAddTranspToPaper->setCore(mEditor); + mAddTranspToPaper->setWindowFlag(Qt::WindowStaysOnTopHint); + mAddTranspToPaper->show(); +} + +void MainWindow2::closeAddTranspToPaperDialog() +{ + disconnect(mAddTranspToPaper, &AddTransparencyToPaperDialog::closeDialog, this , &MainWindow2::closeAddTranspToPaperDialog); + mAddTranspToPaper = nullptr; +} + void MainWindow2::currentLayerChanged() { if (mEditor->layers()->currentLayer()->type() == Layer::BITMAP) diff --git a/app/src/mainwindow2.h b/app/src/mainwindow2.h index 9e3ca91ecd..c89bc5ebbe 100644 --- a/app/src/mainwindow2.h +++ b/app/src/mainwindow2.h @@ -21,6 +21,7 @@ GNU General Public License for more details. #include #include "preferencemanager.h" #include "pegbaralignmentdialog.h" +#include "addtransparencytopaperdialog.h" template class QList; @@ -70,6 +71,8 @@ public slots: void clearRecentFilesList(); void openPegAlignDialog(); void closePegAlignDialog(); + void openAddTranspToPaperDialog(); + void closeAddTranspToPaperDialog(); void currentLayerChanged(); void selectionChanged(); @@ -170,6 +173,7 @@ private slots: BackupElement* mBackupAtSave = nullptr; PegBarAlignmentDialog* mPegAlign = nullptr; + AddTransparencyToPaperDialog* mAddTranspToPaper = nullptr; private: ActionCommands* mCommands = nullptr; diff --git a/app/src/preferencesdialog.cpp b/app/src/preferencesdialog.cpp index 631fac6f49..be60f04be6 100644 --- a/app/src/preferencesdialog.cpp +++ b/app/src/preferencesdialog.cpp @@ -804,7 +804,7 @@ void ToolsPage::rotationIncrementChange(int value) while (360 % angle != 0) { angle++; } - ui->rotationIncrementDisplay->setText(tr("1% degrees").arg(angle)); // don't use tr()'s plural settings, it breaks Transifex. + ui->rotationIncrementDisplay->setText(tr("%1 degrees").arg(angle)); // don't use tr()'s plural settings, it breaks Transifex. mManager->set(SETTING::ROTATION_INCREMENT, angle); } diff --git a/app/ui/addtransparencytopaperdialog.ui b/app/ui/addtransparencytopaperdialog.ui new file mode 100644 index 0000000000..f9a849b4b2 --- /dev/null +++ b/app/ui/addtransparencytopaperdialog.ui @@ -0,0 +1,247 @@ + + + AddTransparencyToPaperDialog + + + + 0 + 0 + 271 + 283 + + + + Add transparency to Paper + + + + + + + + Threshold + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Color pick values above treshold, will become transparent + + + 150 + + + 245 + + + 220 + + + + + + + + + Qt::Horizontal + + + + + + + + + Trace Red + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + :/icons/red.png + + + + + + + + + + + Trace Green + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + :/icons/green.png + + + + + + + + + + + Trace Blue + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + :/icons/blue.png + + + + + + + + + Qt::Horizontal + + + + + + + Current Keyframe + + + + + + + All Keyframes on layer + + + true + + + + + + + Qt::Horizontal + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Cancel + + + + + + + Trace + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index cbb80ca145..aba7e42860 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -6,7 +6,7 @@ 0 0 - 239 + 240 374 @@ -65,7 +65,7 @@ - 0 + 1 @@ -87,117 +87,6 @@ 4 - - - - Prepare Drawings? - - - - 2 - - - 4 - - - 4 - - - 4 - - - 4 - - - - - - - Threshold - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - 160 - - - 245 - - - 220 - - - - - - - - - - - Using Selecttool? - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - true - - - - 20 - 16777215 - - - - Something is selected - - - - - - - :/icons/select.png:/icons/select.png - - - true - - - - - - - - @@ -426,25 +315,10 @@ Fill spot areas? - - - 2 - - - 4 - - - 4 - - - 4 - - - 4 - + - - + + Fill small, unwanted areas in lines @@ -454,7 +328,7 @@ - + Size of area to fill (1-15) @@ -470,6 +344,29 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + Fill areas + + + @@ -632,7 +529,7 @@ 4 - + All keyframes @@ -884,7 +781,7 @@ - Apply + Apply and Finish diff --git a/app/ui/mainwindow2.ui b/app/ui/mainwindow2.ui index 74c9bb0dda..6a0d72885b 100644 --- a/app/ui/mainwindow2.ui +++ b/app/ui/mainwindow2.ui @@ -49,7 +49,7 @@ 0 0 831 - 24 + 20 @@ -108,6 +108,13 @@ + + + Prepare scanned drawings + + + + @@ -121,7 +128,7 @@ - + @@ -1080,6 +1087,16 @@ Open Temporary Directory + + + Peg bar Alignment + + + + + Add Transparency to paper + + diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 5a86eb82cf..d707591914 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -665,11 +665,11 @@ void BitmapImage::setBounds(QRect rect) updateBounds(rect); } -BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool black, bool red, bool green, bool blue) +BitmapImage* BitmapImage::scanToTransparent(BitmapImage *img, bool red, bool green, bool blue) { - Q_ASSERT(bitmapimage != nullptr); + Q_ASSERT(img != nullptr); - BitmapImage* img = bitmapimage; +// BitmapImage* img = bitmapimage; img->enableAutoCrop(false); QRgb rgba; @@ -682,7 +682,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool black { img->scanLine(x, y, transp); } // IF Red line - else if(qRed(rgba) -40 > qGreen(rgba) && qRed(rgba) > qBlue(rgba)) + else if(qRed(rgba) - 20 > qGreen(rgba) && qRed(rgba) - 20 > qBlue(rgba)) { if (red) { @@ -693,7 +693,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool black img->scanLine(x, y, transp); } } // IF Blue line - else if(qBlue(rgba) -40 > qRed(rgba) && qBlue(rgba) > qGreen(rgba)) + else if(qBlue(rgba) -20 > qRed(rgba) && qBlue(rgba) - 20 > qGreen(rgba)) { if (blue) { @@ -704,7 +704,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool black img->scanLine(x, y, transp); } } // IF Green line - else if(qGreen(rgba) -40 > qRed(rgba) && qGreen(rgba) > qBlue(rgba)) + else if(qGreen(rgba) - 20 > qRed(rgba) && qGreen(rgba) - 20 > qBlue(rgba)) { if (green) { @@ -714,13 +714,22 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool black { img->scanLine(x, y, transp); } - } // IF in grayscale graduation area - else if(qGray(rgba) >= mLowThreshold && qGray(rgba) < mThreshold && black) + } // okay, so it is in grayscale graduation area + else { - qreal factor = qreal(mThreshold - qGray(rgba)) / qreal(mThreshold - mLowThreshold); - int alpha = static_cast(255 * factor); - QRgb tmp = qRgba(0, 0, 0, alpha); - img->scanLine(x , y, tmp); + if(qGray(rgba) >= mLowThreshold && qGray(rgba) < mThreshold) + { + qreal factor = qreal(mThreshold - qGray(rgba)) / qreal(mThreshold - mLowThreshold); + int alpha = static_cast(255 * factor); + QRgb tmp = qRgba(0, 0, 0, alpha); + img->scanLine(x , y, tmp); + } + else + { + int c = (qRed(rgba) + qGreen(rgba) + qBlue(rgba)) / 3; + QRgb tmp = qRgba(c, c, c, qAlpha(rgba)); + img->scanLine(x, y, tmp); + } } } } @@ -728,11 +737,11 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool black return img; } -void BitmapImage::traceLine(BitmapImage* bitmapimage, bool black, bool red, bool green, bool blue) +void BitmapImage::traceLine(BitmapImage* img, bool black, bool red, bool green, bool blue) { - Q_ASSERT(bitmapimage != nullptr); + Q_ASSERT(img != nullptr); - BitmapImage* img = bitmapimage; +// BitmapImage* img = bitmapimage; QRgb rgba; for (int x = img->left(); x <= img->right(); x++) { diff --git a/core_lib/src/graphics/bitmap/bitmapimage.h b/core_lib/src/graphics/bitmap/bitmapimage.h index 5a87f46a23..fc082ff980 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.h +++ b/core_lib/src/graphics/bitmap/bitmapimage.h @@ -114,7 +114,7 @@ class BitmapImage : public KeyFrame // coloring methods int getThreshold() { return mThreshold; } int getSpotArea() { return mSpotArea; } - BitmapImage* scanToTransparent(BitmapImage* bitmapimage, bool black, bool red, bool green, bool blue); + BitmapImage* scanToTransparent(BitmapImage* bitmapimage, bool red, bool green, bool blue); void traceLine(BitmapImage* bitmapimage, bool black, bool red, bool green, bool blue); void fillSpotAreas(BitmapImage* bitmapimage); void toThinLine(BitmapImage* colorImage, bool black, bool red, bool green, bool blue); From 80f8105a7713558befa42842667c506d9af76b9a Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Wed, 8 Jul 2020 11:44:55 +0200 Subject: [PATCH 074/100] Adding progress bars. Optimizing trace code --- app/src/addtransparencytopaperdialog.cpp | 23 ++++++++++- app/src/bitmapcoloring.cpp | 20 ++++++++- app/ui/addtransparencytopaperdialog.ui | 36 +++++++++++++--- app/ui/bitmapcoloringwidget.ui | 12 +++--- core_lib/src/graphics/bitmap/bitmapimage.cpp | 43 +++++++++----------- core_lib/src/graphics/bitmap/bitmapimage.h | 5 ++- 6 files changed, 99 insertions(+), 40 deletions(-) diff --git a/app/src/addtransparencytopaperdialog.cpp b/app/src/addtransparencytopaperdialog.cpp index 8fa1f40c20..12d7a50235 100644 --- a/app/src/addtransparencytopaperdialog.cpp +++ b/app/src/addtransparencytopaperdialog.cpp @@ -1,12 +1,15 @@ #include "addtransparencytopaperdialog.h" #include "ui_addtransparencytopaperdialog.h" +#include + #include "editor.h" #include "layermanager.h" #include "selectionmanager.h" #include "layerbitmap.h" #include "bitmapimage.h" + AddTransparencyToPaperDialog::AddTransparencyToPaperDialog(QWidget *parent) : QWidget(parent), ui(new Ui::AddTransparencyToPaperDialog) @@ -62,11 +65,26 @@ void AddTransparencyToPaperDialog::traceScannedDrawings() } else { + mEditor->setIsDoingRepeatColoring(true); + int count = mEditor->getAutoSaveCounter(); + QProgressDialog* mProgress = new QProgressDialog(tr("Thinning lines in bitmaps..."), tr("Abort"), 0, 100, this); + mProgress->setWindowModality(Qt::WindowModal); + mProgress->show(); + mProgress->setMaximum(layer->keyFrameCount()); + mProgress->setValue(0); + int keysThinned = 0; + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); for (int i = layer->firstKeyFramePosition(); i <= layer->getMaxKeyFramePosition(); i++) { - mEditor->scrubTo(i); if (layer->keyExists(i)) { + mProgress->setValue(keysThinned++); + mEditor->scrubTo(i); + count++; + if (mProgress->wasCanceled()) + { + break; + } if (somethingSelected) { mEditor->copy(); @@ -82,6 +100,9 @@ void AddTransparencyToPaperDialog::traceScannedDrawings() ui->cb_Blue->isChecked()); } } + mProgress->close(); + mEditor->setIsDoingRepeatColoring(false); + mEditor->setAutoSaveCounter(count); } } diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 1aa72b7c8c..84e18748ed 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -275,17 +275,35 @@ void BitmapColoring::fillSpotAreas() } else { + mEditor->setIsDoingRepeatColoring(true); + int count = mEditor->getAutoSaveCounter(); + QProgressDialog* mProgress = new QProgressDialog(tr("Thinning lines in bitmaps..."), tr("Abort"), 0, 100, this); + mProgress->setWindowModality(Qt::WindowModal); + mProgress->show(); + mProgress->setMaximum(mLayerBitmap->keyFrameCount()); + mProgress->setValue(0); + int keysThinned = 0; + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); for (int i = mLayerBitmap->firstKeyFramePosition(); i <= mLayerBitmap->getMaxKeyFramePosition(); i++) { if (mLayerBitmap->keyExists(i)) { + mProgress->setValue(keysThinned++); mEditor->scrubTo(i); mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); mBitmapImage->setSpotArea(ui->sbSpotAreas->value()); mBitmapImage->fillSpotAreas(mBitmapImage); mBitmapImage->modification(); + count++; + } + if (mProgress->wasCanceled()) + { + break; } } + mProgress->close(); + mEditor->setIsDoingRepeatColoring(false); + mEditor->setAutoSaveCounter(count); } updateUI(); } @@ -395,13 +413,13 @@ void BitmapColoring::blendLines() if (mLayerBitmap->keyExists(i)) { mEditor->scrubTo(i); - blend(artLayer); count++; progress.setValue(keysBlended++); if (progress.wasCanceled()) { break; } + blend(artLayer); } } mEditor->setIsDoingRepeatColoring(false); diff --git a/app/ui/addtransparencytopaperdialog.ui b/app/ui/addtransparencytopaperdialog.ui index f9a849b4b2..06985e3849 100644 --- a/app/ui/addtransparencytopaperdialog.ui +++ b/app/ui/addtransparencytopaperdialog.ui @@ -7,7 +7,7 @@ 0 0 271 - 283 + 318 @@ -195,7 +195,14 @@ - + + + + + Trace + + + @@ -210,16 +217,33 @@ - + - Cancel + + + + + - + + + Qt::Horizontal + + + + 40 + 20 + + + + + + - Trace + Close diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index aba7e42860..8aa12f839d 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -65,7 +65,7 @@ - 1 + 0 @@ -269,7 +269,7 @@ - Apply + Trace... @@ -313,7 +313,7 @@ - Fill spot areas? + Fill small areas? @@ -324,7 +324,7 @@ Fill small, unwanted areas in lines - Fill spots areas + Fill small areas @@ -556,7 +556,7 @@ - Apply + Thin... @@ -781,7 +781,7 @@ - Apply and Finish + Blend and Finish... diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index d707591914..67a9239211 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -669,21 +669,20 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *img, bool red, bool gre { Q_ASSERT(img != nullptr); -// BitmapImage* img = bitmapimage; img->enableAutoCrop(false); QRgb rgba; for (int x = img->left(); x <= img->right(); x++) { for (int y = img->top(); y <= img->bottom(); y++) - { // IF Threshold or above + { rgba = img->constScanLine(x, y); if (qGray(rgba) >= mThreshold) - { + { // IF Threshold or above img->scanLine(x, y, transp); - } // IF Red line - else if(qRed(rgba) - 20 > qGreen(rgba) && qRed(rgba) - 20 > qBlue(rgba)) - { + } + else if(qRed(rgba) > qGreen(rgba) + COLORDIFF && qRed(rgba) > qBlue(rgba) + COLORDIFF) + { // IF Red line if (red) { img->scanLine(x, y, redline); @@ -692,43 +691,39 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *img, bool red, bool gre { img->scanLine(x, y, transp); } - } // IF Blue line - else if(qBlue(rgba) -20 > qRed(rgba) && qBlue(rgba) - 20 > qGreen(rgba)) - { - if (blue) + } + else if(qGreen(rgba) > qRed(rgba) + COLORDIFF && qGreen(rgba) > qBlue(rgba) + COLORDIFF) + { // IF Green line + if (green) { - img->scanLine(x, y, blueline); + img->scanLine(x, y, greenline); } else { img->scanLine(x, y, transp); } - } // IF Green line - else if(qGreen(rgba) - 20 > qRed(rgba) && qGreen(rgba) - 20 > qBlue(rgba)) - { - if (green) + } + else if(qBlue(rgba) > qRed(rgba) + COLORDIFF && qBlue(rgba) > qGreen(rgba) + COLORDIFF) + { // IF Blue line + if (blue) { - img->scanLine(x, y, greenline); + img->scanLine(x, y, blueline); } else { img->scanLine(x, y, transp); } - } // okay, so it is in grayscale graduation area + } else - { + { // okay, so it is in grayscale graduation area if(qGray(rgba) >= mLowThreshold && qGray(rgba) < mThreshold) { qreal factor = qreal(mThreshold - qGray(rgba)) / qreal(mThreshold - mLowThreshold); - int alpha = static_cast(255 * factor); - QRgb tmp = qRgba(0, 0, 0, alpha); - img->scanLine(x , y, tmp); + img->scanLine(x , y, qRgba(0, 0, 0, static_cast(mThreshold * factor))); } else { - int c = (qRed(rgba) + qGreen(rgba) + qBlue(rgba)) / 3; - QRgb tmp = qRgba(c, c, c, qAlpha(rgba)); - img->scanLine(x, y, tmp); + img->scanLine(x , y, blackline); } } } diff --git a/core_lib/src/graphics/bitmap/bitmapimage.h b/core_lib/src/graphics/bitmap/bitmapimage.h index fc082ff980..25907d55ac 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.h +++ b/core_lib/src/graphics/bitmap/bitmapimage.h @@ -30,7 +30,7 @@ class BitmapImage : public KeyFrame public: const QRgb transp = qRgba(0, 0, 0, 0); const QRgb rosa = qRgba(255,230,230,255); - const QRgb blackline = qRgba(1, 0, 0, 255); + const QRgb blackline = qRgba(1, 1, 1, 255); const QRgb redline = qRgba(254,0,0,255); const QRgb greenline = qRgba(0,254,0,255); const QRgb blueline = qRgba(0,0,254,255); @@ -157,8 +157,9 @@ public slots: bool mEnableAutoCrop = false; int mThreshold = 200; - const int mLowThreshold = 30; // threshold for images to be given transparency + const int mLowThreshold = 30; // threshold for images to be given transparency int mSpotArea = 6; + const int COLORDIFF = 20; // difference in color values to decide color }; From d2f0a9c6b67867de7c3bf44277e1b15d1c0987ab Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Wed, 8 Jul 2020 12:32:38 +0200 Subject: [PATCH 075/100] Optimizing UI. Refactoring progress bars --- app/src/bitmapcoloring.cpp | 51 +++++++-------- app/ui/bitmapcoloringwidget.ui | 65 +++++++++++--------- core_lib/src/graphics/bitmap/bitmapimage.cpp | 1 - 3 files changed, 61 insertions(+), 56 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 84e18748ed..4c1bdaa2c7 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -212,12 +212,12 @@ void BitmapColoring::traceLines() { mEditor->setIsDoingRepeatColoring(true); int count = mEditor->getAutoSaveCounter(); - QProgressDialog* mProgress = new QProgressDialog(tr("Tracing lines in bitmaps..."), tr("Abort"), 0, 100, this); - mProgress->setWindowModality(Qt::WindowModal); - mProgress->show(); + QProgressDialog mProgress(tr("Tracing lines in bitmaps..."), tr("Abort"), 0, 100, this); + mProgress.setWindowModality(Qt::WindowModal); + mProgress.show(); int keysToTrace = mLayerBitmap->keyFrameCount(); - mProgress->setMaximum(keysToTrace); - mProgress->setValue(0); + mProgress.setMaximum(keysToTrace); + mProgress.setValue(0); int keysTraced = 0; QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); @@ -225,17 +225,17 @@ void BitmapColoring::traceLines() { if (mLayerBitmap->keyExists(i)) { - mProgress->setValue(keysTraced++); + mProgress.setValue(keysTraced++); mEditor->scrubTo(i); trace(); count++; - if (mProgress->wasCanceled()) + if (mProgress.wasCanceled()) { break; } } } - mProgress->close(); + mProgress.close(); // move colorLayer beneath Animation layer while (mColLayer > mAnimLayer) @@ -277,18 +277,18 @@ void BitmapColoring::fillSpotAreas() { mEditor->setIsDoingRepeatColoring(true); int count = mEditor->getAutoSaveCounter(); - QProgressDialog* mProgress = new QProgressDialog(tr("Thinning lines in bitmaps..."), tr("Abort"), 0, 100, this); - mProgress->setWindowModality(Qt::WindowModal); - mProgress->show(); - mProgress->setMaximum(mLayerBitmap->keyFrameCount()); - mProgress->setValue(0); + QProgressDialog mProgress(tr("Fill small areas in bitmaps..."), tr("Abort"), 0, 100, this); + mProgress.setWindowModality(Qt::WindowModal); + mProgress.show(); + mProgress.setMaximum(mLayerBitmap->keyFrameCount()); + mProgress.setValue(0); int keysThinned = 0; QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); for (int i = mLayerBitmap->firstKeyFramePosition(); i <= mLayerBitmap->getMaxKeyFramePosition(); i++) { if (mLayerBitmap->keyExists(i)) { - mProgress->setValue(keysThinned++); + mProgress.setValue(keysThinned++); mEditor->scrubTo(i); mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); mBitmapImage->setSpotArea(ui->sbSpotAreas->value()); @@ -296,12 +296,12 @@ void BitmapColoring::fillSpotAreas() mBitmapImage->modification(); count++; } - if (mProgress->wasCanceled()) + if (mProgress.wasCanceled()) { break; } } - mProgress->close(); + mProgress.close(); mEditor->setIsDoingRepeatColoring(false); mEditor->setAutoSaveCounter(count); } @@ -339,28 +339,28 @@ void BitmapColoring::thinLines() { mEditor->setIsDoingRepeatColoring(true); int count = mEditor->getAutoSaveCounter(); - QProgressDialog* mProgress = new QProgressDialog(tr("Thinning lines in bitmaps..."), tr("Abort"), 0, 100, this); - mProgress->setWindowModality(Qt::WindowModal); - mProgress->show(); - mProgress->setMaximum(mLayerBitmap->keyFrameCount()); - mProgress->setValue(0); + QProgressDialog mProgress(tr("Thinning lines in bitmaps..."), tr("Abort"), 0, 100, this); + mProgress.setWindowModality(Qt::WindowModal); + mProgress.show(); + mProgress.setMaximum(mLayerBitmap->keyFrameCount()); + mProgress.setValue(0); int keysThinned = 0; QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); for (int i = mLayerBitmap->firstKeyFramePosition(); i <= mLayerBitmap->getMaxKeyFramePosition(); i++) { if (mLayerBitmap->keyExists(i)) { - mProgress->setValue(keysThinned++); + mProgress.setValue(keysThinned++); mEditor->scrubTo(i); thin(); count++; } - if (mProgress->wasCanceled()) + if (mProgress.wasCanceled()) { break; } } - mProgress->close(); + mProgress.close(); mEditor->setIsDoingRepeatColoring(false); mEditor->setAutoSaveCounter(count); } @@ -415,13 +415,14 @@ void BitmapColoring::blendLines() mEditor->scrubTo(i); count++; progress.setValue(keysBlended++); + blend(artLayer); if (progress.wasCanceled()) { break; } - blend(artLayer); } } + mEditor->setIsDoingRepeatColoring(false); mEditor->setAutoSaveCounter(count); } diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index 8aa12f839d..6fc277c7ac 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -6,8 +6,8 @@ 0 0 - 240 - 374 + 254 + 325 @@ -246,6 +246,13 @@ + + + + Reset + + + @@ -259,13 +266,6 @@ - - - - Reset - - - @@ -316,23 +316,31 @@ Fill small areas? + + 2 + + + 4 + + + 4 + + + 4 + + + 4 + - - - - Fill small, unwanted areas in lines - - - Fill small areas - - - Size of area to fill (1-15) + + px + 1 @@ -344,20 +352,17 @@ - - - - Qt::Horizontal + + + + Fill small, unwanted areas in lines - - - 40 - 20 - + + Fill - + - + false diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 67a9239211..f7240e61d2 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -736,7 +736,6 @@ void BitmapImage::traceLine(BitmapImage* img, bool black, bool red, bool green, { Q_ASSERT(img != nullptr); -// BitmapImage* img = bitmapimage; QRgb rgba; for (int x = img->left(); x <= img->right(); x++) { From 5d8ff54f93f48bf00db75219dcbdfd90c20c7401 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Wed, 8 Jul 2020 14:39:56 +0200 Subject: [PATCH 076/100] Adding guides. Optimized and automated workflow --- app/src/bitmapcoloring.cpp | 30 ++++++++++++- app/ui/bitmapcoloringwidget.ui | 82 ++++++++++++++++------------------ 2 files changed, 67 insertions(+), 45 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 4c1bdaa2c7..84dccbe523 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -253,14 +253,29 @@ void BitmapColoring::traceLines() trace(); } mEditor->deselectAll(); + if (ui->cb3TraceAllKeyframes->isChecked()) + { + ui->tabWidget->setCurrentIndex(1); + QMessageBox msgBox; + msgBox.setText(tr("Ready for thinning lines!")); + msgBox.exec(); + } } void BitmapColoring::updateFillSpotsButton() { if (ui->cbSpotAreas->isChecked()) + { ui->btnFillAreas->setEnabled(true); + ui->btnApplyThin->setEnabled(false); + ui->labReminder->setText(tr("Fill areas blocks Thin button!")); + } else + { ui->btnFillAreas->setEnabled(false); + ui->btnApplyThin->setEnabled(true); + ui->labReminder->setText(""); + } } void BitmapColoring::fillSpotAreas() @@ -304,6 +319,7 @@ void BitmapColoring::fillSpotAreas() mProgress.close(); mEditor->setIsDoingRepeatColoring(false); mEditor->setAutoSaveCounter(count); + ui->cbSpotAreas->setChecked(false); } updateUI(); } @@ -365,6 +381,13 @@ void BitmapColoring::thinLines() mEditor->setAutoSaveCounter(count); } ui->cbSpotAreas->setChecked(false); + if (ui->cbThinAllKeyframes->isChecked()) + { + ui->tabWidget->setCurrentIndex(2); + QMessageBox msgBox; + msgBox.setText(tr("Ready for coloring!")); + msgBox.exec(); + } } // public Blend functions @@ -422,9 +445,14 @@ void BitmapColoring::blendLines() } } } - + progress.close(); mEditor->setIsDoingRepeatColoring(false); mEditor->setAutoSaveCounter(count); + ui->tabWidget->setCurrentIndex(0); + resetColoringDock(); + QMessageBox msgBox; + msgBox.setText(tr("Coloring finished!\nDialog reset...")); + msgBox.exec(); } } diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index 6fc277c7ac..14842d67bb 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -6,29 +6,14 @@ 0 0 - 254 - 325 + 271 + 399 Form - - - 2 - - - 4 - - - 4 - - - 4 - - - 4 - + @@ -294,22 +279,7 @@ Thin - - - 2 - - - 4 - - - 4 - - - 4 - - - 4 - + @@ -352,16 +322,6 @@ - - - - Fill small, unwanted areas in lines - - - Fill - - - @@ -372,6 +332,16 @@ + + + + Fill small, unwanted areas in lines + + + Fill + + + @@ -567,6 +537,30 @@ + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + From 5fe8399ef7c48ca16c4f32ff4822f9b5d910bfbc Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Fri, 10 Jul 2020 12:54:01 +0200 Subject: [PATCH 077/100] Redesign dialog. Show preview --- app/src/addtransparencytopaperdialog.cpp | 36 +- app/src/addtransparencytopaperdialog.h | 13 +- app/ui/addtransparencytopaperdialog.ui | 509 ++++++++++++----------- 3 files changed, 309 insertions(+), 249 deletions(-) diff --git a/app/src/addtransparencytopaperdialog.cpp b/app/src/addtransparencytopaperdialog.cpp index 12d7a50235..7f25e78660 100644 --- a/app/src/addtransparencytopaperdialog.cpp +++ b/app/src/addtransparencytopaperdialog.cpp @@ -2,6 +2,10 @@ #include "ui_addtransparencytopaperdialog.h" #include +#include +#include +#include +#include #include "editor.h" #include "layermanager.h" @@ -10,14 +14,17 @@ #include "bitmapimage.h" -AddTransparencyToPaperDialog::AddTransparencyToPaperDialog(QWidget *parent) : - QWidget(parent), +AddTransparencyToPaperDialog::AddTransparencyToPaperDialog(QDialog *parent) : + QDialog(parent), ui(new Ui::AddTransparencyToPaperDialog) { ui->setupUi(this); + ui->mainLayout->setStretchFactor(ui->optionsLayout, 1); + ui->mainLayout->setStretchFactor(ui->previewLayout, 10); connect(ui->btnCancel, &QPushButton::clicked, this, &AddTransparencyToPaperDialog::closeClicked); connect(ui->btnTrace, &QPushButton::clicked, this, &AddTransparencyToPaperDialog::traceScannedDrawings); + connect(this, &QDialog::finished, this, &AddTransparencyToPaperDialog::closeClicked); } AddTransparencyToPaperDialog::~AddTransparencyToPaperDialog() @@ -28,6 +35,7 @@ AddTransparencyToPaperDialog::~AddTransparencyToPaperDialog() void AddTransparencyToPaperDialog::setCore(Editor *editor) { mEditor = editor; + loadDrawing(mEditor->currentFrame()); connect(mEditor->layers(), &LayerManager::currentLayerChanged, this, &AddTransparencyToPaperDialog::updateTraceButton); } @@ -39,6 +47,30 @@ void AddTransparencyToPaperDialog::updateTraceButton() ui->btnTrace->setEnabled(false); } +void AddTransparencyToPaperDialog::loadDrawing(int frame) +{ + if (mEditor->layers()->currentLayer()->type() != Layer::BITMAP) { return; } + + LayerBitmap* layer = static_cast(mEditor->layers()->currentLayer()); + BitmapImage* img = nullptr; + if (layer->keyExists(frame)) + img = layer->getBitmapImageAtFrame(mEditor->currentFrame()); + else + img = layer->getBitmapImageAtFrame(layer->getPreviousKeyFramePosition(frame)); + if (img == nullptr) + { + QMessageBox msgBox; + msgBox.setText( tr("No image at or before frame %1").arg(QString::number(frame))); + msgBox.exec(); + return; + } + mLoadedImage = *img->image(); + mPixmapFromImage = QPixmap::fromImage(mLoadedImage); + scene.addPixmap(mPixmapFromImage); + ui->preview->setScene(&scene); + ui->preview->update(); +} + void AddTransparencyToPaperDialog::traceScannedDrawings() { if (mEditor->layers()->currentLayer()->type() != Layer::BITMAP) { return; } diff --git a/app/src/addtransparencytopaperdialog.h b/app/src/addtransparencytopaperdialog.h index a50c7fbd85..25ac3a0939 100644 --- a/app/src/addtransparencytopaperdialog.h +++ b/app/src/addtransparencytopaperdialog.h @@ -1,7 +1,9 @@ #ifndef ADDTRANSPARENCYTOPAPERDIALOG_H #define ADDTRANSPARENCYTOPAPERDIALOG_H -#include +#include +#include +#include class Editor; @@ -9,18 +11,19 @@ namespace Ui { class AddTransparencyToPaperDialog; } -class AddTransparencyToPaperDialog : public QWidget +class AddTransparencyToPaperDialog : public QDialog { Q_OBJECT public: - explicit AddTransparencyToPaperDialog(QWidget *parent = nullptr); + explicit AddTransparencyToPaperDialog(QDialog *parent = nullptr); ~AddTransparencyToPaperDialog(); void setCore(Editor* editor); public slots: void updateTraceButton(); + void loadDrawing(int frame); signals: void closeDialog(); @@ -31,6 +34,10 @@ public slots: void traceScannedDrawings(); void closeClicked(); + QGraphicsScene scene; + + QImage mLoadedImage; + QPixmap mPixmapFromImage; Editor* mEditor = nullptr; }; diff --git a/app/ui/addtransparencytopaperdialog.ui b/app/ui/addtransparencytopaperdialog.ui index 06985e3849..018fb86478 100644 --- a/app/ui/addtransparencytopaperdialog.ui +++ b/app/ui/addtransparencytopaperdialog.ui @@ -6,262 +6,283 @@ 0 0 - 271 - 318 + 609 + 343 Add transparency to Paper - + - + - - - Threshold - - + + + + + + + Threshold + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Color pick values above treshold, will become transparent + + + 150 + + + 245 + + + 220 + + + + + + + + + Qt::Horizontal + + + + + + + + + Trace Red + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + :/icons/red.png + + + + + + + + + + + Trace Green + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + :/icons/green.png + + + + + + + + + + + Trace Blue + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + :/icons/blue.png + + + + + + + + + Qt::Horizontal + + + + + + + Current Keyframe + + + + + + + All Keyframes on layer + + + true + + + + + + + Qt::Horizontal + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Trace + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Close + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Color pick values above treshold, will become transparent - - - 150 - - - 245 - - - 220 - - + + + + + + 0 + 0 + + + + + 400 + 300 + + + + + - - - - Qt::Horizontal - - - - - - - - - Trace Red - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - :/icons/red.png - - - - - - - - - - - Trace Green - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - :/icons/green.png - - - - - - - - - - - Trace Blue - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - :/icons/blue.png - - - - - - - - - Qt::Horizontal - - - - - - - Current Keyframe - - - - - - - All Keyframes on layer - - - true - - - - - - - Qt::Horizontal - - - - - - - - - Trace - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Close - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - From 4affc161de2a2173cbe381387839e15b0e6ed3be Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 11 Jul 2020 12:32:34 +0200 Subject: [PATCH 078/100] Enhancement to preview --- app/src/addtransparencytopaperdialog.cpp | 108 +++++++++++++---- app/src/addtransparencytopaperdialog.h | 8 +- app/ui/addtransparencytopaperdialog.ui | 121 +++++++++++++------ core_lib/src/graphics/bitmap/bitmapimage.cpp | 7 +- core_lib/src/interface/editor.cpp | 1 + core_lib/src/interface/editor.h | 1 + 6 files changed, 181 insertions(+), 65 deletions(-) diff --git a/app/src/addtransparencytopaperdialog.cpp b/app/src/addtransparencytopaperdialog.cpp index 7f25e78660..f715e45cb4 100644 --- a/app/src/addtransparencytopaperdialog.cpp +++ b/app/src/addtransparencytopaperdialog.cpp @@ -20,11 +20,16 @@ AddTransparencyToPaperDialog::AddTransparencyToPaperDialog(QDialog *parent) : { ui->setupUi(this); ui->mainLayout->setStretchFactor(ui->optionsLayout, 1); - ui->mainLayout->setStretchFactor(ui->previewLayout, 10); + ui->mainLayout->setStretchFactor(ui->previewLayout, 20); + connect(this, &QDialog::finished, this, &AddTransparencyToPaperDialog::closeClicked); + connect(ui->sb_treshold, QOverload::of(&QSpinBox::valueChanged), this, &AddTransparencyToPaperDialog::SpinboxChanged); + connect(ui->sliderThreshold, &QSlider::valueChanged, this, &AddTransparencyToPaperDialog::SliderChanged); + connect(ui->cb_Red, &QCheckBox::stateChanged, this, &AddTransparencyToPaperDialog::updateDrawing); + connect(ui->cb_Green, &QCheckBox::stateChanged, this, &AddTransparencyToPaperDialog::updateDrawing); + connect(ui->cb_Blue, &QCheckBox::stateChanged, this, &AddTransparencyToPaperDialog::updateDrawing); connect(ui->btnCancel, &QPushButton::clicked, this, &AddTransparencyToPaperDialog::closeClicked); connect(ui->btnTrace, &QPushButton::clicked, this, &AddTransparencyToPaperDialog::traceScannedDrawings); - connect(this, &QDialog::finished, this, &AddTransparencyToPaperDialog::closeClicked); } AddTransparencyToPaperDialog::~AddTransparencyToPaperDialog() @@ -35,16 +40,25 @@ AddTransparencyToPaperDialog::~AddTransparencyToPaperDialog() void AddTransparencyToPaperDialog::setCore(Editor *editor) { mEditor = editor; + if (mEditor->layers()->currentLayer()->type() != Layer::BITMAP) + this->setEnabled(false); loadDrawing(mEditor->currentFrame()); - connect(mEditor->layers(), &LayerManager::currentLayerChanged, this, &AddTransparencyToPaperDialog::updateTraceButton); + connect(mEditor->layers(), &LayerManager::currentLayerChanged, this, &AddTransparencyToPaperDialog::layerChanged); + connect(mEditor, &Editor::scrubbedTo, this, &AddTransparencyToPaperDialog::updateDrawing); } -void AddTransparencyToPaperDialog::updateTraceButton() +void AddTransparencyToPaperDialog::SpinboxChanged(int value) { - if (mEditor->layers()->currentLayer()->type() == Layer::BITMAP) - ui->btnTrace->setEnabled(true); - else - ui->btnTrace->setEnabled(false); + mThreshold = value; + ui->sliderThreshold->setValue(value); + updateDrawing(); +} + +void AddTransparencyToPaperDialog::SliderChanged(int value) +{ + mThreshold = value; + ui->sb_treshold->setValue(value); + updateDrawing(); } void AddTransparencyToPaperDialog::loadDrawing(int frame) @@ -52,23 +66,51 @@ void AddTransparencyToPaperDialog::loadDrawing(int frame) if (mEditor->layers()->currentLayer()->type() != Layer::BITMAP) { return; } LayerBitmap* layer = static_cast(mEditor->layers()->currentLayer()); - BitmapImage* img = nullptr; - if (layer->keyExists(frame)) - img = layer->getBitmapImageAtFrame(mEditor->currentFrame()); - else - img = layer->getBitmapImageAtFrame(layer->getPreviousKeyFramePosition(frame)); - if (img == nullptr) + + if (!layer->keyExists(frame)) { - QMessageBox msgBox; - msgBox.setText( tr("No image at or before frame %1").arg(QString::number(frame))); - msgBox.exec(); - return; + if (!layer->keyExistsWhichCovers(frame)) + frame = layer->getPreviousKeyFramePosition(frame); + else + frame = layer->getNextKeyFramePosition(frame); } - mLoadedImage = *img->image(); + + ui->labShowingFrame->setText(tr("Previewing frame %1").arg(QString::number(frame))); + + mBitmap = nullptr; + mBitmap = layer->getBitmapImageAtFrame(frame)->clone(); + mBitmap->setThreshold(mThreshold); + + mBitmap = mBitmap->scanToTransparent(mBitmap, + ui->cb_Red->isChecked(), + ui->cb_Green->isChecked(), + ui->cb_Blue->isChecked()); + + mLoadedImage = *mBitmap->image(); mPixmapFromImage = QPixmap::fromImage(mLoadedImage); + scene.clear(); scene.addPixmap(mPixmapFromImage); + ui->preview->items().clear(); ui->preview->setScene(&scene); - ui->preview->update(); + ui->preview->show(); +} + +void AddTransparencyToPaperDialog::updateDrawing() +{ + loadDrawing(mEditor->currentFrame()); +} + +void AddTransparencyToPaperDialog::layerChanged(int index) +{ + if (mEditor->layers()->getLayer(index)->type() == Layer::BITMAP) + { + this->setEnabled(true); + updateDrawing(); + } + else + { + this->setEnabled(false); + } } void AddTransparencyToPaperDialog::traceScannedDrawings() @@ -79,21 +121,32 @@ void AddTransparencyToPaperDialog::traceScannedDrawings() BitmapImage* img = new BitmapImage(); bool somethingSelected = mEditor->select()->somethingSelected(); - if (ui->rbCurrentKeyframe->isChecked() && layer->keyExists(mEditor->currentFrame())) + if (ui->rbCurrentKeyframe->isChecked()) { + int frame = mEditor->currentFrame(); + if (!layer->keyExists(frame)) + { + if (!layer->keyExistsWhichCovers(frame)) + frame = layer->getPreviousKeyFramePosition(frame); + else + frame = layer->getNextKeyFramePosition(frame); + } + mEditor->scrubTo(frame); + if (somethingSelected) { mEditor->copy(); - layer->removeKeyFrame(mEditor->currentFrame()); - layer->addNewKeyFrameAt(mEditor->currentFrame()); + layer->removeKeyFrame(frame); + layer->addNewKeyFrameAt(frame); mEditor->paste(); } - img = layer->getBitmapImageAtFrame(mEditor->currentFrame()); - img->setThreshold(ui->sb_treshold->value()); + img = layer->getBitmapImageAtFrame(frame); + img->setThreshold(mThreshold); img = img->scanToTransparent(img, ui->cb_Red->isChecked(), ui->cb_Green->isChecked(), ui->cb_Blue->isChecked()); + img->modification(); } else { @@ -125,17 +178,20 @@ void AddTransparencyToPaperDialog::traceScannedDrawings() mEditor->paste(); } img = layer->getBitmapImageAtFrame(i); - img->setThreshold(ui->sb_treshold->value()); + img->setThreshold(mThreshold); img = img->scanToTransparent(img, ui->cb_Red->isChecked(), ui->cb_Green->isChecked(), ui->cb_Blue->isChecked()); + img->modification(); } } mProgress->close(); mEditor->setIsDoingRepeatColoring(false); mEditor->setAutoSaveCounter(count); } + if (ui->rbAllKeyframes->isChecked()) + closeClicked(); } void AddTransparencyToPaperDialog::closeClicked() diff --git a/app/src/addtransparencytopaperdialog.h b/app/src/addtransparencytopaperdialog.h index 25ac3a0939..5ffca67ec7 100644 --- a/app/src/addtransparencytopaperdialog.h +++ b/app/src/addtransparencytopaperdialog.h @@ -6,6 +6,7 @@ #include class Editor; +class BitmapImage; namespace Ui { class AddTransparencyToPaperDialog; @@ -22,8 +23,11 @@ class AddTransparencyToPaperDialog : public QDialog void setCore(Editor* editor); public slots: - void updateTraceButton(); + void SpinboxChanged(int value); + void SliderChanged(int value); void loadDrawing(int frame); + void updateDrawing(); + void layerChanged(int index); signals: void closeDialog(); @@ -36,6 +40,8 @@ public slots: QGraphicsScene scene; + int mThreshold = 220; + BitmapImage* mBitmap = nullptr; QImage mLoadedImage; QPixmap mPixmapFromImage; Editor* mEditor = nullptr; diff --git a/app/ui/addtransparencytopaperdialog.ui b/app/ui/addtransparencytopaperdialog.ui index 018fb86478..eeaee8aa88 100644 --- a/app/ui/addtransparencytopaperdialog.ui +++ b/app/ui/addtransparencytopaperdialog.ui @@ -6,8 +6,8 @@ 0 0 - 609 - 343 + 671 + 375 @@ -19,42 +19,79 @@ - + - - - Threshold - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - + + + + + Threshold + + + + + + + Qt::Horizontal + + + + 13 + 19 + + + + + - - - Color pick values above treshold, will become transparent - - - 150 - - - 245 - - - 220 - - + + + + + 150 + + + 245 + + + 220 + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Color pick values above treshold, will become transparent + + + 150 + + + 245 + + + 220 + + + + @@ -262,11 +299,18 @@ - + + + + + (Previewing frame: ) + + + - + 0 0 @@ -277,6 +321,9 @@ 300 + + QAbstractScrollArea::AdjustToContents + diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index f7240e61d2..687ad730a5 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -671,12 +671,17 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *img, bool red, bool gre img->enableAutoCrop(false); - QRgb rgba; + QRgb rgba = img->constScanLine(img->left(), img->top()); + if (qAlpha(rgba) == 0) + return img; + for (int x = img->left(); x <= img->right(); x++) { for (int y = img->top(); y <= img->bottom(); y++) { rgba = img->constScanLine(x, y); + if (qAlpha(rgba) == 0) + break; if (qGray(rgba) >= mThreshold) { // IF Threshold or above img->scanLine(x, y, transp); diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 1fc7f0a329..8848d69e56 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -1043,6 +1043,7 @@ void Editor::scrubTo(int frame) emit updateTimeLine(); // needs to update the timeline to update onion skin positions } mObject->updateActiveFrames(frame); + Q_EMIT scrubbedTo(frame); } void Editor::scrubForward() diff --git a/core_lib/src/interface/editor.h b/core_lib/src/interface/editor.h index f5196b1746..ddd099a167 100644 --- a/core_lib/src/interface/editor.h +++ b/core_lib/src/interface/editor.h @@ -126,6 +126,7 @@ class Editor : public QObject void changeThinLinesButton(bool); void currentFrameChanged(int n); + void scrubbedTo(int frame); void needSave(); void needDisplayInfo(const QString& title, const QString& body); From 9d969bde393b75e9c1fc0705a7c4ce50fb5c454b Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 12 Jul 2020 08:55:50 +0200 Subject: [PATCH 079/100] Renaming to Manga Coloring --- app/src/bitmapcoloring.cpp | 2 +- app/ui/bitmapcoloringwidget.ui | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 84dccbe523..99bf379a80 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -28,7 +28,7 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : BaseDockWidget(parent) { QWidget* innerWidget = new QWidget; - setWindowTitle(tr("Advanced Bitmap Coloring")); + setWindowTitle(tr("Manga Coloring")); ui = new Ui::BitmapColoringWidget; ui->setupUi(innerWidget); diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index 14842d67bb..a28058ddef 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -6,12 +6,12 @@ 0 0 - 271 - 399 + 282 + 436 - Form + Manga Coloring From d34ffd4b3245a969a81da186e40058b07edfbeb1 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Mon, 24 Aug 2020 20:11:40 +0200 Subject: [PATCH 080/100] Function for erase colored lines. Improving scan tracing --- app/src/bitmapcoloring.cpp | 52 +++++++++++++++++--- app/src/bitmapcoloring.h | 1 + app/ui/bitmapcoloringwidget.ui | 52 ++++++++++---------- core_lib/src/graphics/bitmap/bitmapimage.cpp | 26 +++++++++- core_lib/src/graphics/bitmap/bitmapimage.h | 2 + 5 files changed, 97 insertions(+), 36 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 99bf379a80..eff84a6f41 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -28,7 +28,7 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : BaseDockWidget(parent) { QWidget* innerWidget = new QWidget; - setWindowTitle(tr("Manga Coloring")); + setWindowTitle(tr("Anime Coloring")); ui = new Ui::BitmapColoringWidget; ui->setupUi(innerWidget); @@ -487,7 +487,14 @@ void BitmapColoring::prepareLines() { mLayerBitmap->copyFrame(mLayerBitmap, colorLayer, mEditor->currentFrame()); } - colorLayer->getBitmapImageAtFrame(mEditor->currentFrame())->traceLine(colorLayer->getBitmapImageAtFrame(mEditor->currentFrame()), + mBitmapImage = colorLayer->getBitmapImageAtFrame(mEditor->currentFrame()); + if (mBitmapImage == nullptr) + { + nonValidBitmap(mEditor->currentFrame()); + return; + } + + mBitmapImage->traceLine(colorLayer->getBitmapImageAtFrame(mEditor->currentFrame()), black, ui->cb2TraceRed->isChecked(), ui->cb2TraceGreen->isChecked(), @@ -504,6 +511,12 @@ void BitmapColoring::trace() mEditor->paste(); } mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); + if (mBitmapImage == nullptr) + { + nonValidBitmap(mEditor->currentFrame()); + return; + } + prepareLines(); mEditor->backup("Trace lines"); } @@ -513,6 +526,12 @@ void BitmapColoring::thin() bool black; ui->cbMethodSelector->currentIndex() == 1 ? black = false: black = true; mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); + if (mBitmapImage == nullptr) + { + nonValidBitmap(mEditor->currentFrame()); + return; + } + mBitmapImage->toThinLine(mBitmapImage, black, ui->cb2ThinRed->isChecked(), @@ -526,7 +545,14 @@ void BitmapColoring::blend(LayerBitmap *artLayer) { bool black; ui->cbMethodSelector->currentIndex() == 1 ? black = false: black = true; - mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame())->blendLines(mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()), + mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); + if (mBitmapImage == nullptr) + { + nonValidBitmap(mEditor->currentFrame()); + return; + } + + mBitmapImage->blendLines(mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()), black, ui->cb2BlendRed->isChecked(), ui->cb2BlendGreen->isChecked(), @@ -534,12 +560,22 @@ void BitmapColoring::blend(LayerBitmap *artLayer) mEditor->backup("Blend lines"); if (ui->cbMethodSelector->currentIndex() == 2 && artLayer != nullptr) { - artLayer->getBitmapImageAtFrame(mEditor->currentFrame())->traceLine(artLayer->getBitmapImageAtFrame(mEditor->currentFrame()), - false, - false, - false, - false); + mBitmapImage = artLayer->getBitmapImageAtFrame(mEditor->currentFrame()); + if (mBitmapImage == nullptr) + { + nonValidBitmap(mEditor->currentFrame()); + return; + } + + mBitmapImage->eraseRedGreenBlueLines(mBitmapImage); mEditor->backup("Blend lines"); } updateUI(); } + +void BitmapColoring::nonValidBitmap(int frame) +{ + QMessageBox msgBox; + msgBox.setText(tr("Frame %1 is not valid!\nAborting frame...").arg(frame)); + msgBox.exec(); +} diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 655870919f..e5c5785acb 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -56,6 +56,7 @@ public slots: void trace(); void thin(); void blend(LayerBitmap* artLayer); + void nonValidBitmap(int frame); private: Ui::BitmapColoringWidget* ui = nullptr; diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index a28058ddef..aa9815536f 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -7,11 +7,11 @@ 0 0 282 - 436 + 403 - Manga Coloring + Anime Coloring @@ -347,6 +347,30 @@ + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -537,30 +561,6 @@ - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 687ad730a5..604f458953 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -770,9 +770,12 @@ void BitmapImage::traceLine(BitmapImage* img, bool black, bool red, bool green, else img->scanLine(x, y, transp); } - else if(black && qRed(rgba) == qGray(rgba)) + else { - img->scanLine(x, y, blackline); + if (black && qAlpha(rgba) > TRANSP_THRESHOLD) + img->scanLine(x, y, blackline); + else + img->scanLine(x, y, transp); } } } @@ -780,6 +783,25 @@ void BitmapImage::traceLine(BitmapImage* img, bool black, bool red, bool green, img->modification(); } +void BitmapImage::eraseRedGreenBlueLines(BitmapImage *img) +{ + Q_ASSERT(img != nullptr); + + QRgb rgba; + for (int x = img->left(); x <= img->right(); x++) + { + for (int y = img->top(); y <= img->bottom(); y++) + { + rgba = img->constScanLine(x, y); + if (rgba == redline || rgba == greenline || rgba == blueline) + { + img->scanLine(x, y, transp); + } + } + } + img->modification(); +} + void BitmapImage::fillSpotAreas(BitmapImage *bitmapimage) { Q_ASSERT(bitmapimage != nullptr); diff --git a/core_lib/src/graphics/bitmap/bitmapimage.h b/core_lib/src/graphics/bitmap/bitmapimage.h index 25907d55ac..f82885be5c 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.h +++ b/core_lib/src/graphics/bitmap/bitmapimage.h @@ -116,6 +116,7 @@ class BitmapImage : public KeyFrame int getSpotArea() { return mSpotArea; } BitmapImage* scanToTransparent(BitmapImage* bitmapimage, bool red, bool green, bool blue); void traceLine(BitmapImage* bitmapimage, bool black, bool red, bool green, bool blue); + void eraseRedGreenBlueLines(BitmapImage* img); void fillSpotAreas(BitmapImage* bitmapimage); void toThinLine(BitmapImage* colorImage, bool black, bool red, bool green, bool blue); void blendLines(BitmapImage* bitmapimage, bool black, bool red, bool green, bool blue); @@ -160,6 +161,7 @@ public slots: const int mLowThreshold = 30; // threshold for images to be given transparency int mSpotArea = 6; const int COLORDIFF = 20; // difference in color values to decide color + const int TRANSP_THRESHOLD = 60;// threshold when tracing black for two layer coloring }; From e5caaa5a08cbd9b29daa7b7ee5577fed2af40297 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Thu, 27 Aug 2020 21:44:28 +0200 Subject: [PATCH 081/100] Improved ux --- app/src/addtransparencytopaperdialog.cpp | 2 +- app/src/bitmapcoloring.cpp | 9 +++++-- app/ui/addtransparencytopaperdialog.ui | 4 +-- app/ui/bitmapcoloringwidget.ui | 12 ++++----- core_lib/src/graphics/bitmap/bitmapimage.cpp | 28 +++++++++----------- core_lib/src/graphics/bitmap/bitmapimage.h | 4 +-- 6 files changed, 30 insertions(+), 29 deletions(-) diff --git a/app/src/addtransparencytopaperdialog.cpp b/app/src/addtransparencytopaperdialog.cpp index f715e45cb4..16e0a73983 100644 --- a/app/src/addtransparencytopaperdialog.cpp +++ b/app/src/addtransparencytopaperdialog.cpp @@ -29,7 +29,7 @@ AddTransparencyToPaperDialog::AddTransparencyToPaperDialog(QDialog *parent) : connect(ui->cb_Green, &QCheckBox::stateChanged, this, &AddTransparencyToPaperDialog::updateDrawing); connect(ui->cb_Blue, &QCheckBox::stateChanged, this, &AddTransparencyToPaperDialog::updateDrawing); connect(ui->btnCancel, &QPushButton::clicked, this, &AddTransparencyToPaperDialog::closeClicked); - connect(ui->btnTrace, &QPushButton::clicked, this, &AddTransparencyToPaperDialog::traceScannedDrawings); + connect(ui->btnAddTransparency, &QPushButton::clicked, this, &AddTransparencyToPaperDialog::traceScannedDrawings); } AddTransparencyToPaperDialog::~AddTransparencyToPaperDialog() diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index eff84a6f41..f2c485c177 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -206,7 +206,7 @@ void BitmapColoring::setThreshold(int threshold) void BitmapColoring::traceLines() { - if (mLayerBitmap == nullptr) { return; } + if (mLayerBitmap == nullptr || mLayerBitmap->type() != Layer::BITMAP) { return; } if (ui->cb3TraceAllKeyframes->isChecked()) { @@ -280,6 +280,10 @@ void BitmapColoring::updateFillSpotsButton() void BitmapColoring::fillSpotAreas() { + if (mEditor->layers()->currentLayer()->type() != Layer::BITMAP) { return; } + + mLayerBitmap = static_cast(mEditor->layers()->currentLayer()); + if (!ui->cbThinAllKeyframes->isChecked() && mLayerBitmap->keyExists(mEditor->currentFrame())) { mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); @@ -303,10 +307,11 @@ void BitmapColoring::fillSpotAreas() { if (mLayerBitmap->keyExists(i)) { - mProgress.setValue(keysThinned++); mEditor->scrubTo(i); + mProgress.setValue(keysThinned++); mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); mBitmapImage->setSpotArea(ui->sbSpotAreas->value()); + qDebug() << "Frame: " << i << ", Spot area: " << ui->sbSpotAreas->value(); mBitmapImage->fillSpotAreas(mBitmapImage); mBitmapImage->modification(); count++; diff --git a/app/ui/addtransparencytopaperdialog.ui b/app/ui/addtransparencytopaperdialog.ui index eeaee8aa88..c4bb011741 100644 --- a/app/ui/addtransparencytopaperdialog.ui +++ b/app/ui/addtransparencytopaperdialog.ui @@ -251,9 +251,9 @@ - + - Trace + Add tranparency to paper diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index aa9815536f..e98a45978d 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -397,7 +397,7 @@ - false + true Thin Red @@ -434,7 +434,7 @@ - false + true Thin Green @@ -471,7 +471,7 @@ - false + true Thin Blue @@ -622,7 +622,7 @@ - false + true Blend Red @@ -659,7 +659,7 @@ - false + true Blend Green @@ -696,7 +696,7 @@ - false + true Blend Blue diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 604f458953..1914af1cc1 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -774,7 +774,7 @@ void BitmapImage::traceLine(BitmapImage* img, bool black, bool red, bool green, { if (black && qAlpha(rgba) > TRANSP_THRESHOLD) img->scanLine(x, y, blackline); - else + else if (black) img->scanLine(x, y, transp); } } @@ -802,16 +802,15 @@ void BitmapImage::eraseRedGreenBlueLines(BitmapImage *img) img->modification(); } -void BitmapImage::fillSpotAreas(BitmapImage *bitmapimage) +void BitmapImage::fillSpotAreas(BitmapImage *img) { - Q_ASSERT(bitmapimage != nullptr); - - BitmapImage* img = bitmapimage; + Q_ASSERT(img != nullptr); // fill areas size 'area' or less with appropriate color QVector points; points.clear(); - QRgb active, previous = blackline; + QRgb active = blackline; + QRgb previous = blackline; for (int x = img->left() + 1; x < img->right(); x++) { for (int y = img->top() + 1; y < img->bottom(); y++) @@ -823,6 +822,7 @@ void BitmapImage::fillSpotAreas(BitmapImage *bitmapimage) int areaSize = fillWithColor(QPoint(x, y), transp, rosa, img); if (areaSize <= mSpotArea) { // replace rosa with last color + qDebug() << "Fill spot area " << areaSize << " with: " << qRed(previous) << " " << qGreen(previous) << " " << qBlue(previous) << " " << qAlpha(previous); fillWithColor(points.last(), rosa, previous, img); points.removeLast(); } @@ -838,11 +838,10 @@ void BitmapImage::fillSpotAreas(BitmapImage *bitmapimage) img->modification(); } -void BitmapImage::toThinLine(BitmapImage * colorImage, bool black, bool red, bool green, bool blue) +void BitmapImage::toThinLine(BitmapImage * img, bool black, bool red, bool green, bool blue) { - Q_ASSERT(colorImage != nullptr); + Q_ASSERT(img != nullptr); - BitmapImage* img = colorImage; bool N = true, E = true, S = true, W = true, pixelRemoved, search; QList colors; @@ -1050,11 +1049,9 @@ void BitmapImage::toThinLine(BitmapImage * colorImage, bool black, bool red, boo img->modification(); } -void BitmapImage::blendLines(BitmapImage *bitmapimage, bool black, bool red, bool green, bool blue) +void BitmapImage::blendLines(BitmapImage *img, bool black, bool red, bool green, bool blue) { - Q_ASSERT(bitmapimage != nullptr); - - BitmapImage* img = bitmapimage; + Q_ASSERT(img != nullptr); int r, g, b, a; //red, green, blue, alpha QList points; // QPoints to add in calculation @@ -1097,11 +1094,10 @@ void BitmapImage::blendLines(BitmapImage *bitmapimage, bool black, bool red, boo img->modification(); } -int BitmapImage::fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, BitmapImage *bitmapimage) +int BitmapImage::fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, BitmapImage *img) { - Q_ASSERT(bitmapimage != nullptr); + Q_ASSERT(img != nullptr); - BitmapImage* img = bitmapimage; QList fillList; fillList.clear(); // fill first pixel diff --git a/core_lib/src/graphics/bitmap/bitmapimage.h b/core_lib/src/graphics/bitmap/bitmapimage.h index f82885be5c..1fde3a8588 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.h +++ b/core_lib/src/graphics/bitmap/bitmapimage.h @@ -117,10 +117,10 @@ class BitmapImage : public KeyFrame BitmapImage* scanToTransparent(BitmapImage* bitmapimage, bool red, bool green, bool blue); void traceLine(BitmapImage* bitmapimage, bool black, bool red, bool green, bool blue); void eraseRedGreenBlueLines(BitmapImage* img); - void fillSpotAreas(BitmapImage* bitmapimage); + void fillSpotAreas(BitmapImage* img); void toThinLine(BitmapImage* colorImage, bool black, bool red, bool green, bool blue); void blendLines(BitmapImage* bitmapimage, bool black, bool red, bool green, bool blue); - int fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, BitmapImage* bitmapimage); + int fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, BitmapImage* img); /** Determines if the BitmapImage is minimally bounded. * From 573d620105c8a521ceb2e8f310a930165493e33c Mon Sep 17 00:00:00 2001 From: CandyFace Date: Fri, 28 Aug 2020 17:35:13 +0200 Subject: [PATCH 082/100] Add white background to dialog scene widget --- app/src/addtransparencytopaperdialog.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/addtransparencytopaperdialog.cpp b/app/src/addtransparencytopaperdialog.cpp index f715e45cb4..42a0061bb8 100644 --- a/app/src/addtransparencytopaperdialog.cpp +++ b/app/src/addtransparencytopaperdialog.cpp @@ -89,6 +89,7 @@ void AddTransparencyToPaperDialog::loadDrawing(int frame) mLoadedImage = *mBitmap->image(); mPixmapFromImage = QPixmap::fromImage(mLoadedImage); scene.clear(); + scene.setBackgroundBrush(Qt::white); scene.addPixmap(mPixmapFromImage); ui->preview->items().clear(); ui->preview->setScene(&scene); From a470a5fdbe7d810f97d06a335a137efb69461e51 Mon Sep 17 00:00:00 2001 From: CandyFace Date: Fri, 28 Aug 2020 17:37:21 +0200 Subject: [PATCH 083/100] Make slight variation to tracing algorithm Changes includes a more strict color check and less strict grayscale check --- core_lib/src/graphics/bitmap/bitmapimage.cpp | 53 ++++++++++++-------- core_lib/src/graphics/bitmap/bitmapimage.h | 9 ++-- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 604f458953..88efcdb6bd 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -665,7 +665,7 @@ void BitmapImage::setBounds(QRect rect) updateBounds(rect); } -BitmapImage* BitmapImage::scanToTransparent(BitmapImage *img, bool red, bool green, bool blue) +BitmapImage* BitmapImage::scanToTransparent(BitmapImage *img, bool redEnabled, bool greenEnabled, bool blueEnabled) { Q_ASSERT(img != nullptr); @@ -680,15 +680,21 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *img, bool red, bool gre for (int y = img->top(); y <= img->bottom(); y++) { rgba = img->constScanLine(x, y); - if (qAlpha(rgba) == 0) + + int grayValue = qGray(rgba); + int redValue = qRed(rgba); + int greenValue = qGreen(rgba); + int blueValue = qBlue(rgba); + int alphaValue = qAlpha(rgba); + if (alphaValue == 0) break; - if (qGray(rgba) >= mThreshold) + if (grayValue >= mThreshold) { // IF Threshold or above img->scanLine(x, y, transp); } - else if(qRed(rgba) > qGreen(rgba) + COLORDIFF && qRed(rgba) > qBlue(rgba) + COLORDIFF) + else if(redValue > greenValue + COLORDIFF && redValue > blueValue + COLORDIFF && redValue > grayValue + GRAYSCALEDIFF) { // IF Red line - if (red) + if (redEnabled) { img->scanLine(x, y, redline); } @@ -697,9 +703,9 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *img, bool red, bool gre img->scanLine(x, y, transp); } } - else if(qGreen(rgba) > qRed(rgba) + COLORDIFF && qGreen(rgba) > qBlue(rgba) + COLORDIFF) + else if(greenValue > redValue + COLORDIFF && greenValue > blueValue + COLORDIFF && greenValue > grayValue + GRAYSCALEDIFF) { // IF Green line - if (green) + if (greenEnabled) { img->scanLine(x, y, greenline); } @@ -708,9 +714,9 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *img, bool red, bool gre img->scanLine(x, y, transp); } } - else if(qBlue(rgba) > qRed(rgba) + COLORDIFF && qBlue(rgba) > qGreen(rgba) + COLORDIFF) + else if(blueValue > redValue + COLORDIFF && blueValue > greenValue + COLORDIFF && blueValue > grayValue + GRAYSCALEDIFF) { // IF Blue line - if (blue) + if (blueEnabled) { img->scanLine(x, y, blueline); } @@ -721,9 +727,9 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *img, bool red, bool gre } else { // okay, so it is in grayscale graduation area - if(qGray(rgba) >= mLowThreshold && qGray(rgba) < mThreshold) + if(grayValue >= mLowThreshold && grayValue < mThreshold) { - qreal factor = qreal(mThreshold - qGray(rgba)) / qreal(mThreshold - mLowThreshold); + qreal factor = qreal(mThreshold - grayValue) / qreal(mThreshold - mLowThreshold); img->scanLine(x , y, qRgba(0, 0, 0, static_cast(mThreshold * factor))); } else @@ -737,7 +743,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *img, bool red, bool gre return img; } -void BitmapImage::traceLine(BitmapImage* img, bool black, bool red, bool green, bool blue) +void BitmapImage::traceLine(BitmapImage* img, bool blackEnabled, bool redEnabled, bool greenEnabled, bool blueEnabled) { Q_ASSERT(img != nullptr); @@ -747,32 +753,37 @@ void BitmapImage::traceLine(BitmapImage* img, bool black, bool red, bool green, for (int y = img->top(); y <= img->bottom(); y++) { rgba = img->constScanLine(x, y); - if (qAlpha(img->constScanLine(x, y)) > 0) + + int redValue = qRed(rgba); + int greenValue = qGreen(rgba); + int blueValue = qBlue(rgba); + int alphaValue = qAlpha(rgba); + if (alphaValue > 0) { - if(qRed(rgba) > qGreen(rgba) && qRed(rgba) > qBlue(rgba)) + if(redValue > greenValue && redValue > blueValue) { - if(red) + if(redEnabled) img->scanLine(x, y, redline); else img->scanLine(x, y, transp); } - else if(qBlue(rgba) > qRed(rgba) && qBlue(rgba) > qGreen(rgba)) + else if(blueValue > redValue && blueValue > greenValue) { - if(blue) + if(blueEnabled) img->scanLine(x, y, blueline); else img->scanLine(x, y, transp); } - else if(qGreen(rgba) > qRed(rgba) && qGreen(rgba) > qBlue(rgba)) + else if(greenValue > redValue && greenValue > blueValue) { - if(green) + if(greenEnabled) img->scanLine(x, y, greenline); else img->scanLine(x, y, transp); } else { - if (black && qAlpha(rgba) > TRANSP_THRESHOLD) + if (blackEnabled && alphaValue > TRANSP_THRESHOLD) img->scanLine(x, y, blackline); else img->scanLine(x, y, transp); @@ -795,7 +806,7 @@ void BitmapImage::eraseRedGreenBlueLines(BitmapImage *img) rgba = img->constScanLine(x, y); if (rgba == redline || rgba == greenline || rgba == blueline) { - img->scanLine(x, y, transp); + img->scanLine(x, y, transp); } } } diff --git a/core_lib/src/graphics/bitmap/bitmapimage.h b/core_lib/src/graphics/bitmap/bitmapimage.h index f82885be5c..421bbab375 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.h +++ b/core_lib/src/graphics/bitmap/bitmapimage.h @@ -114,8 +114,8 @@ class BitmapImage : public KeyFrame // coloring methods int getThreshold() { return mThreshold; } int getSpotArea() { return mSpotArea; } - BitmapImage* scanToTransparent(BitmapImage* bitmapimage, bool red, bool green, bool blue); - void traceLine(BitmapImage* bitmapimage, bool black, bool red, bool green, bool blue); + BitmapImage* scanToTransparent(BitmapImage* bitmapimage, bool redEnabled, bool greenEnabled, bool blueEnabled); + void traceLine(BitmapImage* bitmapimage, bool blackEnabled, bool redEnabled, bool greenEnabled, bool blueEnabled); void eraseRedGreenBlueLines(BitmapImage* img); void fillSpotAreas(BitmapImage* bitmapimage); void toThinLine(BitmapImage* colorImage, bool black, bool red, bool green, bool blue); @@ -157,10 +157,11 @@ public slots: bool mMinBound = true; bool mEnableAutoCrop = false; + int mSpotArea = 6; int mThreshold = 200; const int mLowThreshold = 30; // threshold for images to be given transparency - int mSpotArea = 6; - const int COLORDIFF = 20; // difference in color values to decide color + const int COLORDIFF = 5; // difference in color values to decide color + const int GRAYSCALEDIFF = 15; // difference in grasycale values to decide color const int TRANSP_THRESHOLD = 60;// threshold when tracing black for two layer coloring }; From f1b64cffc8fc574b36216529e144444f0a9d9322 Mon Sep 17 00:00:00 2001 From: CandyFace Date: Sat, 29 Aug 2020 11:42:31 +0200 Subject: [PATCH 084/100] Cleanup dialog properly when closing. Avoid adding logic to setCore as it's a setter and only supposed to set the variable. Also make background white, as it had no color. --- app/src/addtransparencytopaperdialog.cpp | 9 ++++++- app/src/addtransparencytopaperdialog.h | 7 +++--- app/src/mainwindow2.cpp | 30 +++++++++++------------- app/src/mainwindow2.h | 1 - 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/src/addtransparencytopaperdialog.cpp b/app/src/addtransparencytopaperdialog.cpp index 42a0061bb8..8c94ec0ab3 100644 --- a/app/src/addtransparencytopaperdialog.cpp +++ b/app/src/addtransparencytopaperdialog.cpp @@ -40,11 +40,19 @@ AddTransparencyToPaperDialog::~AddTransparencyToPaperDialog() void AddTransparencyToPaperDialog::setCore(Editor *editor) { mEditor = editor; +} + +void AddTransparencyToPaperDialog::initUI() +{ if (mEditor->layers()->currentLayer()->type() != Layer::BITMAP) this->setEnabled(false); loadDrawing(mEditor->currentFrame()); connect(mEditor->layers(), &LayerManager::currentLayerChanged, this, &AddTransparencyToPaperDialog::layerChanged); connect(mEditor, &Editor::scrubbedTo, this, &AddTransparencyToPaperDialog::updateDrawing); + + scene.setBackgroundBrush(Qt::white); + ui->preview->setScene(&scene); + ui->preview->show(); } void AddTransparencyToPaperDialog::SpinboxChanged(int value) @@ -198,5 +206,4 @@ void AddTransparencyToPaperDialog::traceScannedDrawings() void AddTransparencyToPaperDialog::closeClicked() { emit closeDialog(); - close(); } diff --git a/app/src/addtransparencytopaperdialog.h b/app/src/addtransparencytopaperdialog.h index 5ffca67ec7..2d940b1ae7 100644 --- a/app/src/addtransparencytopaperdialog.h +++ b/app/src/addtransparencytopaperdialog.h @@ -22,16 +22,17 @@ class AddTransparencyToPaperDialog : public QDialog void setCore(Editor* editor); + void initUI(); + public slots: +signals: + void closeDialog(); void SpinboxChanged(int value); void SliderChanged(int value); void loadDrawing(int frame); void updateDrawing(); void layerChanged(int index); -signals: - void closeDialog(); - private: Ui::AddTransparencyToPaperDialog *ui; diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index 93b335579a..fe31ccce61 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -481,25 +481,23 @@ void MainWindow2::closePegAlignDialog() void MainWindow2::openAddTranspToPaperDialog() { - if (mAddTranspToPaper != nullptr) + if (mAddTranspToPaper == nullptr) { - QMessageBox::information(this, nullptr, - tr("Dialog is already open!"), - QMessageBox::Ok); - return; - } + mAddTranspToPaper = new AddTransparencyToPaperDialog(); + mAddTranspToPaper->setCore(mEditor); + mAddTranspToPaper->initUI(); + mAddTranspToPaper->setWindowFlag(Qt::WindowStaysOnTopHint); + mAddTranspToPaper->show(); - mAddTranspToPaper = new AddTransparencyToPaperDialog(); - connect(mAddTranspToPaper, &AddTransparencyToPaperDialog::closeDialog, this , &MainWindow2::closeAddTranspToPaperDialog); - mAddTranspToPaper->setCore(mEditor); - mAddTranspToPaper->setWindowFlag(Qt::WindowStaysOnTopHint); - mAddTranspToPaper->show(); -} + connect(mAddTranspToPaper, &AddTransparencyToPaperDialog::closeDialog, [=] { + mAddTranspToPaper->deleteLater(); + mAddTranspToPaper = nullptr; + }); + + } else { + mAddTranspToPaper->raise(); + } -void MainWindow2::closeAddTranspToPaperDialog() -{ - disconnect(mAddTranspToPaper, &AddTransparencyToPaperDialog::closeDialog, this , &MainWindow2::closeAddTranspToPaperDialog); - mAddTranspToPaper = nullptr; } void MainWindow2::currentLayerChanged() diff --git a/app/src/mainwindow2.h b/app/src/mainwindow2.h index c89bc5ebbe..cb2c8e0af4 100644 --- a/app/src/mainwindow2.h +++ b/app/src/mainwindow2.h @@ -72,7 +72,6 @@ public slots: void openPegAlignDialog(); void closePegAlignDialog(); void openAddTranspToPaperDialog(); - void closeAddTranspToPaperDialog(); void currentLayerChanged(); void selectionChanged(); From 7c16262a16812bd7d763a5c69d87ae79344cd7c2 Mon Sep 17 00:00:00 2001 From: CandyFace Date: Sat, 29 Aug 2020 15:15:23 +0200 Subject: [PATCH 085/100] Implement various improvements + Transparency check + Zoom + fit widget + Disable trace button if there is no image + Fix memory leaks by changing mBitmap to be created on the stack instead of heap.. + Update preview when bitmap has been modified --- app/src/addtransparencytopaperdialog.cpp | 77 +++++++++++--- app/src/addtransparencytopaperdialog.h | 24 +++-- app/ui/addtransparencytopaperdialog.ui | 122 ++++++++++++++--------- core_lib/src/interface/editor.cpp | 5 + core_lib/src/interface/editor.h | 5 + core_lib/src/interface/scribblearea.cpp | 2 + 6 files changed, 164 insertions(+), 71 deletions(-) diff --git a/app/src/addtransparencytopaperdialog.cpp b/app/src/addtransparencytopaperdialog.cpp index 8c94ec0ab3..830ebd30a0 100644 --- a/app/src/addtransparencytopaperdialog.cpp +++ b/app/src/addtransparencytopaperdialog.cpp @@ -2,9 +2,6 @@ #include "ui_addtransparencytopaperdialog.h" #include -#include -#include -#include #include #include "editor.h" @@ -23,13 +20,15 @@ AddTransparencyToPaperDialog::AddTransparencyToPaperDialog(QDialog *parent) : ui->mainLayout->setStretchFactor(ui->previewLayout, 20); connect(this, &QDialog::finished, this, &AddTransparencyToPaperDialog::closeClicked); - connect(ui->sb_treshold, QOverload::of(&QSpinBox::valueChanged), this, &AddTransparencyToPaperDialog::SpinboxChanged); + connect(ui->sb_treshold, static_cast(&QSpinBox::valueChanged), this, &AddTransparencyToPaperDialog::SpinboxChanged); connect(ui->sliderThreshold, &QSlider::valueChanged, this, &AddTransparencyToPaperDialog::SliderChanged); connect(ui->cb_Red, &QCheckBox::stateChanged, this, &AddTransparencyToPaperDialog::updateDrawing); connect(ui->cb_Green, &QCheckBox::stateChanged, this, &AddTransparencyToPaperDialog::updateDrawing); connect(ui->cb_Blue, &QCheckBox::stateChanged, this, &AddTransparencyToPaperDialog::updateDrawing); connect(ui->btnCancel, &QPushButton::clicked, this, &AddTransparencyToPaperDialog::closeClicked); connect(ui->btnTrace, &QPushButton::clicked, this, &AddTransparencyToPaperDialog::traceScannedDrawings); + connect(ui->testTransparencyCheckbox, &QCheckBox::stateChanged, this, &AddTransparencyToPaperDialog::checkerStateChanged); + connect(ui->zoomSlider, &QSlider::valueChanged, this, &AddTransparencyToPaperDialog::zoomChanged); } AddTransparencyToPaperDialog::~AddTransparencyToPaperDialog() @@ -49,10 +48,15 @@ void AddTransparencyToPaperDialog::initUI() loadDrawing(mEditor->currentFrame()); connect(mEditor->layers(), &LayerManager::currentLayerChanged, this, &AddTransparencyToPaperDialog::layerChanged); connect(mEditor, &Editor::scrubbedTo, this, &AddTransparencyToPaperDialog::updateDrawing); + connect(mEditor, &Editor::currentFrameUpdated, this, &AddTransparencyToPaperDialog::updateDrawing); scene.setBackgroundBrush(Qt::white); ui->preview->setScene(&scene); ui->preview->show(); + + if (!mBitmap.bounds().isValid()) { + ui->btnTrace->setEnabled(false); + } } void AddTransparencyToPaperDialog::SpinboxChanged(int value) @@ -69,6 +73,43 @@ void AddTransparencyToPaperDialog::SliderChanged(int value) updateDrawing(); } +void AddTransparencyToPaperDialog::checkerStateChanged(bool state) +{ + if (state) { + scene.setBackgroundBrush(QBrush(QImage(":/background/checkerboard.png"))); + } else { + scene.setBackgroundBrush(Qt::white); + } +} + +void AddTransparencyToPaperDialog::zoomChanged(int zoomLevel) +{ + mZoomLevel = zoomLevel; + updatePreview(); +} + +void AddTransparencyToPaperDialog::resizeEvent(QResizeEvent*) +{ + updatePreview(); +} + +void AddTransparencyToPaperDialog::updatePreview() +{ + QImage loadedImage = *mBitmap.image(); + + QSize previewSize = ui->preview->size()*mZoomLevel; + QSize size = mBitmap.size().scaled(previewSize, Qt::KeepAspectRatioByExpanding); + mPixmapFromImage = QPixmap(size); + mPixmapFromImage.fill(Qt::transparent); + + QPainter painter(&mPixmapFromImage); + + painter.drawImage(QRect(QPoint(0,0),QSize(size)), loadedImage, loadedImage.rect()); + mPreviewImageItem->setPixmap(mPixmapFromImage); + + scene.setSceneRect(QRect(QPoint(), previewSize)); +} + void AddTransparencyToPaperDialog::loadDrawing(int frame) { if (mEditor->layers()->currentLayer()->type() != Layer::BITMAP) { return; } @@ -85,23 +126,27 @@ void AddTransparencyToPaperDialog::loadDrawing(int frame) ui->labShowingFrame->setText(tr("Previewing frame %1").arg(QString::number(frame))); - mBitmap = nullptr; - mBitmap = layer->getBitmapImageAtFrame(frame)->clone(); - mBitmap->setThreshold(mThreshold); + BitmapImage* currentImage = layer->getBitmapImageAtFrame(frame); + + if (!currentImage) { return; } + + mBitmap = currentImage->copy(); + mBitmap.setThreshold(mThreshold); - mBitmap = mBitmap->scanToTransparent(mBitmap, + mBitmap = *mBitmap.scanToTransparent(&mBitmap, ui->cb_Red->isChecked(), ui->cb_Green->isChecked(), ui->cb_Blue->isChecked()); - mLoadedImage = *mBitmap->image(); - mPixmapFromImage = QPixmap::fromImage(mLoadedImage); - scene.clear(); - scene.setBackgroundBrush(Qt::white); - scene.addPixmap(mPixmapFromImage); - ui->preview->items().clear(); - ui->preview->setScene(&scene); - ui->preview->show(); + if (mPreviewImageItem == nullptr) { + mPreviewImageItem = scene.addPixmap(mPixmapFromImage); + } else { + mPreviewImageItem->setPixmap(mPixmapFromImage); + } + + ui->btnTrace->setEnabled(true); + + updatePreview(); } void AddTransparencyToPaperDialog::updateDrawing() diff --git a/app/src/addtransparencytopaperdialog.h b/app/src/addtransparencytopaperdialog.h index 2d940b1ae7..8f3b7866f7 100644 --- a/app/src/addtransparencytopaperdialog.h +++ b/app/src/addtransparencytopaperdialog.h @@ -4,9 +4,11 @@ #include #include #include +#include + +#include "bitmapimage.h" class Editor; -class BitmapImage; namespace Ui { class AddTransparencyToPaperDialog; @@ -18,32 +20,42 @@ class AddTransparencyToPaperDialog : public QDialog public: explicit AddTransparencyToPaperDialog(QDialog *parent = nullptr); - ~AddTransparencyToPaperDialog(); + ~AddTransparencyToPaperDialog() override; void setCore(Editor* editor); void initUI(); -public slots: signals: void closeDialog(); + +protected: + void resizeEvent(QResizeEvent*) override; + +private slots: void SpinboxChanged(int value); void SliderChanged(int value); void loadDrawing(int frame); void updateDrawing(); void layerChanged(int index); + void checkerStateChanged(bool state); + void zoomChanged(int zoomLevel); private: - Ui::AddTransparencyToPaperDialog *ui; + void updatePreview(); void traceScannedDrawings(); void closeClicked(); + int mZoomLevel = 1; + + Ui::AddTransparencyToPaperDialog *ui; + QGraphicsScene scene; + QGraphicsPixmapItem* mPreviewImageItem = nullptr; int mThreshold = 220; - BitmapImage* mBitmap = nullptr; - QImage mLoadedImage; + BitmapImage mBitmap; QPixmap mPixmapFromImage; Editor* mEditor = nullptr; }; diff --git a/app/ui/addtransparencytopaperdialog.ui b/app/ui/addtransparencytopaperdialog.ui index eeaee8aa88..57ae49f3ac 100644 --- a/app/ui/addtransparencytopaperdialog.ui +++ b/app/ui/addtransparencytopaperdialog.ui @@ -62,19 +62,6 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - @@ -102,6 +89,40 @@ + + + + 0 + + + + + Zoom + + + + + + + 1 + + + 10 + + + Qt::Horizontal + + + + + + + + + Qt::Horizontal + + + @@ -236,33 +257,43 @@ - - - - - Qt::Horizontal - - - - 40 - 20 - - - - + + + Test transparency + + + + + + + Qt::Horizontal + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + - + - Trace + Close - - - - - + Qt::Horizontal @@ -275,27 +306,17 @@ - + - Close + Trace + + + true - - - - Qt::Vertical - - - - 20 - 40 - - - - @@ -324,6 +345,9 @@ QAbstractScrollArea::AdjustToContents + + QGraphicsView::NoAnchor + diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 8848d69e56..9d51c6eea0 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -983,6 +983,11 @@ void Editor::selectAll() select()->setSelection(rect, false); } +void Editor::notifyCurrentFrameUpdated() +{ + emit currentFrameUpdated(); +} + void Editor::deselectAll() { Layer* layer = layers()->currentLayer(); diff --git a/core_lib/src/interface/editor.h b/core_lib/src/interface/editor.h index ddd099a167..e3bdce2d11 100644 --- a/core_lib/src/interface/editor.h +++ b/core_lib/src/interface/editor.h @@ -132,7 +132,11 @@ class Editor : public QObject void needDisplayInfo(const QString& title, const QString& body); void needDisplayInfoNoTitle(const QString& body); + // Something was updated on the current frame, notify receivers + void currentFrameUpdated(); + public: //slots + void clearCurrentFrame(); void cut(); @@ -153,6 +157,7 @@ class Editor : public QObject KeyFrame* addNewKey(); void removeKey(); + void notifyCurrentFrameUpdated(); void notifyAnimationLengthChanged(); void switchVisibilityOfLayer(int layerNumber); void showLayerNotVisibleWarning(); diff --git a/core_lib/src/interface/scribblearea.cpp b/core_lib/src/interface/scribblearea.cpp index 1fbbbb390f..ebc0e621e1 100644 --- a/core_lib/src/interface/scribblearea.cpp +++ b/core_lib/src/interface/scribblearea.cpp @@ -753,6 +753,8 @@ void ScribbleArea::paintBitmapBuffer() } layer->setModified(frameNumber, true); + mEditor->notifyCurrentFrameUpdated(); + mBufferImg->clear(); } From 38b64aeba4ac2a03d606388ab7c0ddda1a63b566 Mon Sep 17 00:00:00 2001 From: CandyFace Date: Sat, 29 Aug 2020 15:35:27 +0200 Subject: [PATCH 086/100] Shorten button name --- app/src/addtransparencytopaperdialog.cpp | 6 +++--- app/ui/addtransparencytopaperdialog.ui | 2 +- core_lib/src/graphics/bitmap/bitmapimage.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/addtransparencytopaperdialog.cpp b/app/src/addtransparencytopaperdialog.cpp index e36093d8b6..f2a8732eb2 100644 --- a/app/src/addtransparencytopaperdialog.cpp +++ b/app/src/addtransparencytopaperdialog.cpp @@ -26,7 +26,7 @@ AddTransparencyToPaperDialog::AddTransparencyToPaperDialog(QDialog *parent) : connect(ui->cb_Green, &QCheckBox::stateChanged, this, &AddTransparencyToPaperDialog::updateDrawing); connect(ui->cb_Blue, &QCheckBox::stateChanged, this, &AddTransparencyToPaperDialog::updateDrawing); connect(ui->btnCancel, &QPushButton::clicked, this, &AddTransparencyToPaperDialog::closeClicked); - connect(ui->btnAddTransparency, &QPushButton::clicked, this, &AddTransparencyToPaperDialog::traceScannedDrawings); + connect(ui->btnApply, &QPushButton::clicked, this, &AddTransparencyToPaperDialog::traceScannedDrawings); connect(ui->testTransparencyCheckbox, &QCheckBox::stateChanged, this, &AddTransparencyToPaperDialog::checkerStateChanged); connect(ui->zoomSlider, &QSlider::valueChanged, this, &AddTransparencyToPaperDialog::zoomChanged); } @@ -55,7 +55,7 @@ void AddTransparencyToPaperDialog::initUI() ui->preview->show(); if (!mBitmap.bounds().isValid()) { - ui->btnTrace->setEnabled(false); + ui->btnApply->setEnabled(false); } } @@ -144,7 +144,7 @@ void AddTransparencyToPaperDialog::loadDrawing(int frame) mPreviewImageItem->setPixmap(mPixmapFromImage); } - ui->btnTrace->setEnabled(true); + ui->btnApply->setEnabled(true); updatePreview(); } diff --git a/app/ui/addtransparencytopaperdialog.ui b/app/ui/addtransparencytopaperdialog.ui index ea83b23325..4ac06df893 100644 --- a/app/ui/addtransparencytopaperdialog.ui +++ b/app/ui/addtransparencytopaperdialog.ui @@ -306,7 +306,7 @@ - + Apply diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 4f1a1ac413..5f8e43041f 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -785,7 +785,7 @@ void BitmapImage::traceLine(BitmapImage* img, bool blackEnabled, bool redEnabled { if (blackEnabled && alphaValue > TRANSP_THRESHOLD) img->scanLine(x, y, blackline); - else if (black) + else if (blackEnabled) img->scanLine(x, y, transp); } } From d2abe860fa592fe989122614e67f79410f6e752e Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Fri, 12 Mar 2021 16:41:20 +0100 Subject: [PATCH 087/100] Some extra check for nullptr --- app/src/bitmapcoloring.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index a5ccea5789..1e13b7da79 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -1,7 +1,7 @@ /* Pencil - Traditional Animation Software -Copyright (C) 2012-2018 Matthew Chiawen Chang +Copyright (C) 2012-2021 Matthew Chiawen Chang This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -394,15 +394,22 @@ void BitmapColoring::blendLines() // protected functions void BitmapColoring::prepareLines() { + // Method selector can be 0, 1 or 2. 0 = No method selected + if (ui->cbMethodSelector->currentIndex() < 1) + { + return; + } LayerBitmap* colorLayer = nullptr; bool black; ui->cbMethodSelector->currentIndex() == 1 ? black = false: black = true; + // Method selector 1 = Coloring on same layer if (ui->cbMethodSelector->currentIndex() == 1) - { // if coloring is on same layer... + { colorLayer = mLayerBitmap; } - else if (ui->cbMethodSelector->currentIndex() == 2) - { // if coloring is on separate layer... + // Method selector 2 = Coloring on separate layer + else + { if (!mLayerBitmap->getHasColorLayer()) { mAnimLayer = mEditor->currentLayerIndex(); // necessary since new layer becomes currentlayer @@ -417,6 +424,7 @@ void BitmapColoring::prepareLines() colorLayer = static_cast(mEditor->layers()->findLayerByName(mLayerBitmap->name() + "_C")); } } + Q_ASSERT(colorLayer); if (ui->cbMethodSelector->currentIndex() == 2) { From 5fc2a619255984bcf85ffff2477024bb9a3f001a Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 13 Mar 2021 07:21:48 +0100 Subject: [PATCH 088/100] Removed some dead code, and replaced magic number with var --- core_lib/src/graphics/bitmap/bitmapimage.cpp | 60 ++------------------ core_lib/src/graphics/bitmap/bitmapimage.h | 1 + 2 files changed, 7 insertions(+), 54 deletions(-) diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index c8683b0ec5..2a22095db3 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -699,7 +699,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool black { img->scanLine(x, y, transp); } // IF Red line - else if(qRed(rgba) -40 > qGreen(rgba) && qRed(rgba) > qBlue(rgba)) + else if(qRed(rgba) - RED_FACTOR > qGreen(rgba) && qRed(rgba) > qBlue(rgba)) { if (red) { @@ -710,7 +710,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool black img->scanLine(x, y, transp); } } // IF Blue line - else if(qBlue(rgba) -40 > qRed(rgba) && qBlue(rgba) > qGreen(rgba)) + else if(qBlue(rgba) - RED_FACTOR > qRed(rgba) && qBlue(rgba) > qGreen(rgba)) { if (blue) { @@ -721,7 +721,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *bitmapimage, bool black img->scanLine(x, y, transp); } } // IF Green line - else if(qGreen(rgba) -40 > qRed(rgba) && qGreen(rgba) > qBlue(rgba)) + else if(qGreen(rgba) - RED_FACTOR > qRed(rgba) && qGreen(rgba) > qBlue(rgba)) { if (green) { @@ -758,21 +758,21 @@ void BitmapImage::traceLine(BitmapImage* bitmapimage, bool black, bool red, bool rgba = img->constScanLine(x, y); if (qAlpha(img->constScanLine(x, y)) > 0) { - if(qRed(rgba) - 50 > qGreen(rgba)) + if(qRed(rgba) - RED_FACTOR > qGreen(rgba)) { if(red) img->scanLine(x, y, redline); else img->scanLine(x, y, transp); } - else if(qBlue(rgba) - 50 > qRed(rgba) && qBlue(rgba) > qGreen(rgba)) + else if(qBlue(rgba) - RED_FACTOR > qRed(rgba) && qBlue(rgba) > qGreen(rgba)) { if(blue) img->scanLine(x, y, blueline); else img->scanLine(x, y, transp); } - else if(qGreen(rgba) - 50 > qRed(rgba) && qGreen(rgba) > qBlue(rgba)) + else if(qGreen(rgba) - RED_FACTOR > qRed(rgba) && qGreen(rgba) > qBlue(rgba)) { if(green) img->scanLine(x, y, greenline); @@ -1128,55 +1128,7 @@ int BitmapImage::fillWithColor(QPoint point, QRgb orgColor, QRgb newColor, Bitma img->modification(); return pixels; } -/* -Status::StatusInt BitmapImage::findLeft(QRectF rect, int grayValue) -{ - Status::StatusInt retValues; - retValues.value = -1; - retValues.errorcode = Status::FAIL; - int left = static_cast(rect.left()); - int right = static_cast(rect.right()); - int top = static_cast(rect.top()); - int bottom = static_cast(rect.bottom()); - for (int x = left; x <= right; x++) - { - for (int y = top; y <= bottom; y++) - { - if (qAlpha(constScanLine(x,y)) == 255 && qGray(constScanLine(x,y)) < grayValue) - { - retValues.value = x; - retValues.errorcode = Status::OK; - return retValues; - } - } - } - return retValues; -} -Status::StatusInt BitmapImage::findTop(QRectF rect, int grayValue) -{ - Status::StatusInt retValues; - retValues.value = -1; - retValues.errorcode = Status::FAIL; - int left = static_cast(rect.left()); - int right = static_cast(rect.right()); - int top = static_cast(rect.top()); - int bottom = static_cast(rect.bottom()); - for (int y = top; y <= bottom; y++) - { - for (int x = left; x <= right; x++) - { - if (qAlpha(constScanLine(x,y)) == 255 && qGray(constScanLine(x,y)) < grayValue) - { - retValues.value = y; - retValues.errorcode = Status::OK; - return retValues; - } - } - } - return retValues; -} -*/ Status BitmapImage::writeFile(const QString& filename) { if (mImage && !mImage->isNull()) diff --git a/core_lib/src/graphics/bitmap/bitmapimage.h b/core_lib/src/graphics/bitmap/bitmapimage.h index ee87cb0ab8..403632dead 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.h +++ b/core_lib/src/graphics/bitmap/bitmapimage.h @@ -159,6 +159,7 @@ public slots: const int mLowThreshold = 30; // threshold for images to be given transparency int mSpotArea = 6; + const int RED_FACTOR = 20; qreal mOpacity = 1.0; }; From 994d94f6ea4c29949eee9fec5746fda83c71c760 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 13 Mar 2021 08:25:32 +0100 Subject: [PATCH 089/100] Removed debug messages and enhanced ui --- app/src/bitmapcoloring.cpp | 2 -- app/src/mainwindow2.h | 1 - app/ui/addtransparencytopaperdialog.ui | 7 +++++++ app/ui/bitmapcoloringwidget.ui | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 5b5991ea6c..6d3eb66e5a 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -311,7 +311,6 @@ void BitmapColoring::fillSpotAreas() mProgress.setValue(keysThinned++); mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); mBitmapImage->setSpotArea(ui->sbSpotAreas->value()); - qDebug() << "Frame: " << i << ", Spot area: " << ui->sbSpotAreas->value(); mBitmapImage->fillSpotAreas(mBitmapImage); mBitmapImage->modification(); count++; @@ -415,7 +414,6 @@ void BitmapColoring::blendLines() QString orgName = mLayerBitmap->name(); if (ui->cbMethodSelector->currentIndex() == 2) orgName.chop(2); - qDebug() << "artlayer: " << orgName; LayerBitmap* artLayer = static_cast(mEditor->layers()->findLayerByName(orgName)); if (artLayer == nullptr) { return; } diff --git a/app/src/mainwindow2.h b/app/src/mainwindow2.h index f2b6483cdc..1f1d8832f4 100644 --- a/app/src/mainwindow2.h +++ b/app/src/mainwindow2.h @@ -73,7 +73,6 @@ public slots: void clearRecentFilesList(); void openPegAlignDialog(); void openLayerOpacityDialog(); -// void closePegAlignDialog(); void openAddTranspToPaperDialog(); void currentLayerChanged(); void selectionChanged(); diff --git a/app/ui/addtransparencytopaperdialog.ui b/app/ui/addtransparencytopaperdialog.ui index 4ac06df893..a8420ab845 100644 --- a/app/ui/addtransparencytopaperdialog.ui +++ b/app/ui/addtransparencytopaperdialog.ui @@ -232,6 +232,13 @@ + + + + Apply to: + + + diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index e98a45978d..c8379007d1 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -11,7 +11,7 @@ - Anime Coloring + Advanced Coloring From 094ded520598b6be1e1b780d1927e11236ddca4b Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 14 Mar 2021 10:04:07 +0100 Subject: [PATCH 090/100] Correcting titles for two dialogs --- app/src/addtransparencytopaperdialog.cpp | 2 +- app/src/bitmapcoloring.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/addtransparencytopaperdialog.cpp b/app/src/addtransparencytopaperdialog.cpp index f2a8732eb2..cfaaf22b56 100644 --- a/app/src/addtransparencytopaperdialog.cpp +++ b/app/src/addtransparencytopaperdialog.cpp @@ -206,7 +206,7 @@ void AddTransparencyToPaperDialog::traceScannedDrawings() { mEditor->setIsDoingRepeatColoring(true); int count = mEditor->getAutoSaveCounter(); - QProgressDialog* mProgress = new QProgressDialog(tr("Thinning lines in bitmaps..."), tr("Abort"), 0, 100, this); + QProgressDialog* mProgress = new QProgressDialog(tr("Tracing scanned drawings..."), tr("Abort"), 0, 100, this); mProgress->setWindowModality(Qt::WindowModal); mProgress->show(); mProgress->setMaximum(layer->keyFrameCount()); diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 6d3eb66e5a..01270f0ec4 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -28,7 +28,7 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : BaseDockWidget(parent) { QWidget* innerWidget = new QWidget; - setWindowTitle(tr("Anime Coloring")); + setWindowTitle(tr("Advanced Coloring")); ui = new Ui::BitmapColoringWidget; ui->setupUi(innerWidget); From 220b259be7b9b7a0dd8986c70830d57340dfe3c6 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Mon, 5 Apr 2021 09:30:23 +0200 Subject: [PATCH 091/100] Fixed tracing on originals --- app/src/bitmapcoloring.cpp | 166 +++++++++++++++++-- app/src/bitmapcoloring.h | 5 + app/ui/bitmapcoloringwidget.ui | 49 ++++-- core_lib/src/graphics/bitmap/bitmapimage.cpp | 62 ++++++- core_lib/src/graphics/bitmap/bitmapimage.h | 1 + 5 files changed, 247 insertions(+), 36 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 01270f0ec4..855e2e00c0 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -52,6 +52,7 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : // Prepare connect(ui->tabWidget, &QTabWidget::tabBarClicked, this, &BitmapColoring::tabWidgetClicked); + connect(ui->btnPrepareLines, &QPushButton::clicked, this, &BitmapColoring::prepareAndTraceLines); connect(ui->btnApplyTrace, &QPushButton::clicked, this, &BitmapColoring::traceLines); // Thin connect(ui->sbSpotAreas, QOverload::of(&QSpinBox::valueChanged), this, &BitmapColoring::setSpotArea); @@ -60,8 +61,8 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : connect(ui->btnApplyThin, &QPushButton::clicked, this, &BitmapColoring::thinLines); // Finish connect(ui->btnApplyBlend, &QPushButton::clicked, this, &BitmapColoring::blendLines); + updateTraceButtons(); - updateUI(); } BitmapColoring::~BitmapColoring() @@ -123,7 +124,13 @@ void BitmapColoring::checkRedBoxes() { ui->cb2ThinRed->setChecked(ui->cb2TraceRed->isChecked()); ui->cb2BlendRed->setChecked(ui->cb2TraceRed->isChecked()); + mRedChecked = true; } + else + { + mRedChecked = false; + } + updateTraceButtons(); } void BitmapColoring::checkGreenBoxes() @@ -132,7 +139,13 @@ void BitmapColoring::checkGreenBoxes() { ui->cb2ThinGreen->setChecked(ui->cb2TraceGreen->isChecked()); ui->cb2BlendGreen->setChecked(ui->cb2TraceGreen->isChecked()); + mGreenChecked = true; } + else + { + mGreenChecked = false; + } + updateTraceButtons(); } void BitmapColoring::checkBlueBoxes() @@ -141,7 +154,13 @@ void BitmapColoring::checkBlueBoxes() { ui->cb2ThinBlue->setChecked(ui->cb2TraceBlue->isChecked()); ui->cb2BlendBlue->setChecked(ui->cb2TraceBlue->isChecked()); + mBlueChecked = true; } + else + { + mBlueChecked = false; + } + updateTraceButtons(); } void BitmapColoring::checkAllKeyframesBoxes() @@ -251,6 +270,7 @@ void BitmapColoring::traceLines() else if (mLayerBitmap->keyExists(mEditor->currentFrame())) { trace(); + qDebug() << "TRACE one " << mEditor->currentFrame(); } mEditor->deselectAll(); if (ui->cb3TraceAllKeyframes->isChecked()) @@ -383,15 +403,14 @@ void BitmapColoring::thinLines() mProgress.close(); mEditor->setIsDoingRepeatColoring(false); mEditor->setAutoSaveCounter(count); - } - ui->cbSpotAreas->setChecked(false); - if (ui->cbThinAllKeyframes->isChecked()) - { + ui->tabWidget->setCurrentIndex(2); QMessageBox msgBox; msgBox.setText(tr("Ready for coloring!")); msgBox.exec(); } + + mEditor->scrubTo(mEditor->currentFrame()); } // public Blend functions @@ -412,11 +431,19 @@ void BitmapColoring::blendLines() if (mLayerBitmap == nullptr) { return; } QString orgName = mLayerBitmap->name(); - if (ui->cbMethodSelector->currentIndex() == 2) - orgName.chop(2); - LayerBitmap* artLayer = static_cast(mEditor->layers()->findLayerByName(orgName)); + LayerBitmap* artLayer = nullptr; + orgName.chop(2); + QString artLayerName = orgName + "_L"; + artLayer = static_cast(mEditor->layers()->findLayerByName(artLayerName)); + if (!artLayer) + { + artLayerName.chop(2); + artLayer = static_cast(mEditor->layers()->findLayerByName(artLayerName)); + } if (artLayer == nullptr) { return; } + artLayer->setVisible(false); + if (!ui->cb3BlendAllKeyframes->isChecked() && mLayerBitmap->keyExists(mEditor->currentFrame())) { blend(artLayer); @@ -451,12 +478,102 @@ void BitmapColoring::blendLines() progress.close(); mEditor->setIsDoingRepeatColoring(false); mEditor->setAutoSaveCounter(count); + ui->tabWidget->setCurrentIndex(0); resetColoringDock(); QMessageBox msgBox; msgBox.setText(tr("Coloring finished!\nDialog reset...")); msgBox.exec(); } + mEditor->scrubTo(mEditor->currentFrame()); +} + +/* + * If drawings are made in Pencil2D, we need to: + * - Preserve the originals by... + * - ...making a copy of the originals, and... + * - ...making a color layer + * (unless copy and color layer already exists) +*/ +void BitmapColoring::prepareAndTraceLines() +{ + bool black; + ui->cbMethodSelector->currentIndex() == 1 ? black = false: black = true; + + LayerManager* lMgr = mEditor->layers(); + LayerBitmap* sourceLayer = mLayerBitmap; + QString orgName = mLayerBitmap->name(); + LayerBitmap* artLayer = nullptr; + LayerBitmap* colorLayer = nullptr; + + if (!lMgr->findLayerByName(orgName + "_L")) + { + artLayer = lMgr->createBitmapLayer(orgName + "_L"); + colorLayer = lMgr->createBitmapLayer(orgName + "_C"); + } + else + { + artLayer = static_cast(lMgr->findLayerByName(orgName + "_L")); + colorLayer = static_cast(lMgr->findLayerByName(orgName + "_C")); + } + Q_ASSERT(artLayer && colorLayer); + + artLayer->setHasColorLayer(true); + colorLayer->setIsColorLayer(true); + + if (ui->cb3TraceAllKeyframes->isChecked()) + { + for (int i = sourceLayer->firstKeyFramePosition(); i <= sourceLayer->getMaxKeyFramePosition(); i++ ) + { + if (sourceLayer->keyExists(i)) + { + mEditor->scrubTo(i); + lMgr->setCurrentLayer(sourceLayer); + sourceLayer->copyFrame(sourceLayer, artLayer, i); + BitmapImage* image = artLayer->getBitmapImageAtFrame(i); + image->prepDrawing(image, + mRedChecked, + mGreenChecked, + mBlueChecked); + artLayer->copyFrame(artLayer, colorLayer, i); + BitmapImage* colorImage = colorLayer->getBitmapImageAtFrame(i); + colorImage->traceLine(colorImage, + black, + mRedChecked, + mGreenChecked, + mBlueChecked); + } + } + ui->tabWidget->setCurrentIndex(1); + QMessageBox msgBox; + msgBox.setText(tr("Ready for thinning lines!")); + msgBox.exec(); + } + else + { + int i = mEditor->currentFrame(); + + if (sourceLayer->keyExists(i)) + { + lMgr->setCurrentLayer(sourceLayer); + sourceLayer->copyFrame(sourceLayer, artLayer, i); + BitmapImage* image = artLayer->getBitmapImageAtFrame(i); + image->prepDrawing(image, + mRedChecked, + mGreenChecked, + mBlueChecked); + artLayer->copyFrame(artLayer, colorLayer, i); + BitmapImage* colorImage = colorLayer->getBitmapImageAtFrame(i); + colorImage->traceLine(colorImage, + black, + mRedChecked, + mGreenChecked, + mBlueChecked); + } + } + lMgr->setCurrentLayer(colorLayer); + + mEditor->scrubTo(mEditor->currentFrame()); } // protected functions @@ -467,6 +584,7 @@ void BitmapColoring::prepareLines() { return; } + LayerManager* lMgr = mEditor->layers(); LayerBitmap* colorLayer = nullptr; bool black; ui->cbMethodSelector->currentIndex() == 1 ? black = false: black = true; @@ -478,18 +596,22 @@ void BitmapColoring::prepareLines() // Method selector 2 = Coloring on separate layer else { + QString orgName = mLayerBitmap->name(); + // is it a copy or is it a prepared scanned drawing? + if (orgName.endsWith("_L")) + orgName.chop(2); if (!mLayerBitmap->getHasColorLayer()) { mAnimLayer = mEditor->currentLayerIndex(); // necessary since new layer becomes currentlayer - colorLayer = mEditor->layers()->createBitmapLayer(mLayerBitmap->name() + "_C"); + colorLayer = lMgr->createBitmapLayer(orgName + "_C"); mColLayer = mEditor->object()->getLayerCount() - 1; - mEditor->layers()->setCurrentLayer(mAnimLayer); + lMgr->setCurrentLayer(mAnimLayer); mLayerBitmap->setHasColorLayer(true); colorLayer->setIsColorLayer(true); } else { - colorLayer = static_cast(mEditor->layers()->findLayerByName(mLayerBitmap->name() + "_C")); + colorLayer = static_cast(lMgr->findLayerByName(orgName + "_C")); } } Q_ASSERT(colorLayer); @@ -506,10 +628,10 @@ void BitmapColoring::prepareLines() } mBitmapImage->traceLine(colorLayer->getBitmapImageAtFrame(mEditor->currentFrame()), - black, - ui->cb2TraceRed->isChecked(), - ui->cb2TraceGreen->isChecked(), - ui->cb2TraceBlue->isChecked()); + black, + mRedChecked, + mGreenChecked, + mBlueChecked); } void BitmapColoring::trace() @@ -590,3 +712,17 @@ void BitmapColoring::nonValidBitmap(int frame) msgBox.setText(tr("Frame %1 is not valid!\nAborting frame...").arg(frame)); msgBox.exec(); } + +void BitmapColoring::updateTraceButtons() +{ + if (ui->cb2TraceRed->isChecked() || ui->cb2TraceGreen->isChecked() || ui->cb2TraceBlue->isChecked()) + { + ui->btnPrepareLines->setEnabled(true); + ui->btnApplyTrace->setEnabled(false); + } + else + { + ui->btnPrepareLines->setEnabled(false); + ui->btnApplyTrace->setEnabled(true); + } +} diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index e5c5785acb..4323d496be 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -52,11 +52,13 @@ public slots: void blendLines(); protected: + void prepareAndTraceLines(); void prepareLines(); void trace(); void thin(); void blend(LayerBitmap* artLayer); void nonValidBitmap(int frame); + void updateTraceButtons(); private: Ui::BitmapColoringWidget* ui = nullptr; @@ -67,6 +69,9 @@ public slots: bool mSelectAreas = false; int mAnimLayer = 0; // Animation layer index int mColLayer = 0; // Coloring layer index + bool mRedChecked = false; + bool mGreenChecked = false; + bool mBlueChecked = false; }; diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index c8379007d1..e2600797d6 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -49,6 +49,9 @@ + + + 0 @@ -56,22 +59,7 @@ Trace - - - 2 - - - 4 - - - 4 - - - 4 - - - 4 - + @@ -230,7 +218,34 @@ - + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + <html><head/><body><p>Color separation lines must be prepared for coloring.<br/>Color separation, made in Pencil2d, are not prepared.<br/></p></body></html> + + + Prepare lines + Trace... + + + + + + + diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index fd0389b712..5f984da0d6 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -686,8 +686,6 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *img, bool redEnabled, b { Q_ASSERT(img != nullptr); - img->enableAutoCrop(false); - QRgb rgba = img->constScanLine(img->left(), img->top()); if (qAlpha(rgba) == 0) return img; @@ -744,7 +742,7 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *img, bool redEnabled, b } else { // okay, so it is in grayscale graduation area - if(grayValue >= mLowThreshold && grayValue < mThreshold) + if( grayValue >= mLowThreshold && grayValue < mThreshold) { qreal factor = qreal(mThreshold - grayValue) / qreal(mThreshold - mLowThreshold); img->scanLine(x , y, qRgba(0, 0, 0, static_cast(mThreshold * factor))); @@ -760,6 +758,63 @@ BitmapImage* BitmapImage::scanToTransparent(BitmapImage *img, bool redEnabled, b return img; } +BitmapImage* BitmapImage::prepDrawing(BitmapImage* img, bool redEnabled, bool greenEnabled, bool blueEnabled) +{ + Q_ASSERT(img != nullptr); + + for (int x = img->left(); x <= img->right(); x++) + { + for (int y = img->top(); y <= img->bottom(); y++) + { + QRgb rgba = img->constScanLine(x, y); + if (qAlpha(rgba) > 0) + { + int redValue = qRed(rgba); + int greenValue = qGreen(rgba); + int blueValue = qBlue(rgba); + + if(redValue > greenValue + COLORDIFF && redValue > blueValue + COLORDIFF) + { // IF Red line + if (redEnabled) + { + img->scanLine(x, y, redline); + } + else + { + img->scanLine(x, y, transp); + } + } + + else if(greenValue > redValue + COLORDIFF && greenValue > blueValue + COLORDIFF) + { // IF Green line + if (greenEnabled) + { + img->scanLine(x, y, greenline); + } + else + { + img->scanLine(x, y, transp); + } + } + else if(blueValue > redValue + COLORDIFF && blueValue > greenValue + COLORDIFF) + { // IF Blue line + if (blueEnabled) + { + img->scanLine(x, y, blueline); + } + else + { + img->scanLine(x, y, transp); + } + } + } + + } + } + img->modification(); + return img; +} + void BitmapImage::traceLine(BitmapImage* img, bool blackEnabled, bool redEnabled, bool greenEnabled, bool blueEnabled) { Q_ASSERT(img != nullptr); @@ -850,7 +905,6 @@ void BitmapImage::fillSpotAreas(BitmapImage *img) int areaSize = fillWithColor(QPoint(x, y), transp, rosa, img); if (areaSize <= mSpotArea) { // replace rosa with last color - qDebug() << "Fill spot area " << areaSize << " with: " << qRed(previous) << " " << qGreen(previous) << " " << qBlue(previous) << " " << qAlpha(previous); fillWithColor(points.last(), rosa, previous, img); points.removeLast(); } diff --git a/core_lib/src/graphics/bitmap/bitmapimage.h b/core_lib/src/graphics/bitmap/bitmapimage.h index 13c2bc2a3b..9f75e5414e 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.h +++ b/core_lib/src/graphics/bitmap/bitmapimage.h @@ -112,6 +112,7 @@ class BitmapImage : public KeyFrame int getThreshold() { return mThreshold; } int getSpotArea() { return mSpotArea; } BitmapImage* scanToTransparent(BitmapImage* bitmapimage, bool redEnabled, bool greenEnabled, bool blueEnabled); + BitmapImage* prepDrawing(BitmapImage* img, bool redEnabled, bool greenEnabled, bool blueEnabled); void traceLine(BitmapImage* bitmapimage, bool blackEnabled, bool redEnabled, bool greenEnabled, bool blueEnabled); void eraseRedGreenBlueLines(BitmapImage* img); void fillSpotAreas(BitmapImage* img); From db802b4395242c62c3c7b28b5cfe0fd5bb801245 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 29 Jul 2023 22:11:42 +0200 Subject: [PATCH 092/100] Fixed bug, that made first frame untracable --- app/src/bitmapcoloring.cpp | 7 ++++--- core_lib/src/graphics/bitmap/bitmapimage.cpp | 2 ++ core_lib/src/structure/layer.cpp | 20 ++++++++++++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 855e2e00c0..0605c26196 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -20,7 +20,6 @@ GNU General Public License for more details. #include "ui_bitmapcoloringwidget.h" #include "layermanager.h" #include "toolmanager.h" -#include "selectionmanager.h" #include "app_util.h" @@ -523,7 +522,7 @@ void BitmapColoring::prepareAndTraceLines() if (ui->cb3TraceAllKeyframes->isChecked()) { - for (int i = sourceLayer->firstKeyFramePosition(); i <= sourceLayer->getMaxKeyFramePosition(); i++ ) + for (int i = sourceLayer->firstKeyFramePosition(); i <= sourceLayer->getMaxKeyFramePosition(); i++) { if (sourceLayer->keyExists(i)) { @@ -584,6 +583,7 @@ void BitmapColoring::prepareLines() { return; } + LayerManager* lMgr = mEditor->layers(); LayerBitmap* colorLayer = nullptr; bool black; @@ -593,6 +593,7 @@ void BitmapColoring::prepareLines() { colorLayer = mLayerBitmap; } + // Method selector 2 = Coloring on separate layer else { @@ -627,7 +628,7 @@ void BitmapColoring::prepareLines() return; } - mBitmapImage->traceLine(colorLayer->getBitmapImageAtFrame(mEditor->currentFrame()), + mBitmapImage->traceLine(mBitmapImage, black, mRedChecked, mGreenChecked, diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 8c9cfa2713..9d79ac953c 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -880,7 +880,9 @@ void BitmapImage::traceLine(BitmapImage* img, bool blackEnabled, bool redEnabled else { if (blackEnabled && alphaValue > TRANSP_THRESHOLD) + { img->scanLine(x, y, blackline); + } else if (blackEnabled) img->scanLine(x, y, transp); } diff --git a/core_lib/src/structure/layer.cpp b/core_lib/src/structure/layer.cpp index b7fa4ebb55..71a7746d00 100644 --- a/core_lib/src/structure/layer.cpp +++ b/core_lib/src/structure/layer.cpp @@ -389,9 +389,25 @@ void Layer::copyFrame(Layer *fromLayer, Layer *toLayer, int frame) mObject->updateActiveFrames(frame); KeyFrame* keyframe = fromLayer->getKeyFrameAt(frame); KeyFrame* dupKey = keyframe->clone(); - if (toLayer->keyExists(frame)) + if (toLayer->keyExists(frame) && toLayer->keyFrameCount() == 1) + { + int i = toLayer->firstKeyFramePosition(); + if (i == frame) + { + toLayer->addKeyFrame(frame + 1, dupKey); + toLayer->removeKeyFrame(frame); + toLayer->moveKeyFrame(frame + 1, -1); + } else + { + toLayer->addKeyFrame(frame, dupKey); + toLayer->removeKeyFrame(i); + } + } + else + { toLayer->removeKeyFrame(frame); - toLayer->addKeyFrame(frame, dupKey); + toLayer->addKeyFrame(frame, dupKey); + } toLayer->setModified(frame, true); toLayer->getKeyFrameAt(frame)->modification(); } From e0325c03ad52433edd84e89537754a5d9c634c1b Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 12 Aug 2023 10:56:09 +0200 Subject: [PATCH 093/100] Made comments more precise --- app/src/actioncommands.cpp | 2 ++ app/src/bitmapcoloring.cpp | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/actioncommands.cpp b/app/src/actioncommands.cpp index 1b8102e6a7..b3c38988bf 100644 --- a/app/src/actioncommands.cpp +++ b/app/src/actioncommands.cpp @@ -851,6 +851,8 @@ Status ActionCommands::deleteCurrentLayer() LayerManager* layerMgr = mEditor->layers(); QString strLayerName = layerMgr->currentLayer()->name(); + qDebug() << "current layer index: " << mEditor->layers()->currentLayerIndex(); + qDebug() << "count: " << mEditor->layers()->count(); if (!layerMgr->canDeleteLayer(mEditor->currentLayerIndex())) { return Status::CANCELED; } diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 0605c26196..99f8a64930 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -488,10 +488,9 @@ void BitmapColoring::blendLines() } /* - * If drawings are made in Pencil2D, we need to: - * - Preserve the originals by... - * - ...making a copy of the originals, and... - * - ...making a color layer + * If drawings are made in Pencil2D, we need to preserve the originals by: + * - ...making a copy of the original layer, named 'name'_L (L for Line art) + * - ...making a new coloring layer named 'name'_C (C for Coloring) * (unless copy and color layer already exists) */ void BitmapColoring::prepareAndTraceLines() From c0ca138db713736500dc11c10c44d4db83be74ed Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 12 Aug 2023 14:34:32 +0200 Subject: [PATCH 094/100] Fixed bug when deleting layer --- core_lib/src/managers/layermanager.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/core_lib/src/managers/layermanager.cpp b/core_lib/src/managers/layermanager.cpp index 031aa43646..aebd51a1e4 100644 --- a/core_lib/src/managers/layermanager.cpp +++ b/core_lib/src/managers/layermanager.cpp @@ -323,18 +323,6 @@ Status LayerManager::deleteLayer(int index) if (camLayers.size() == 1) return Status::ERROR_NEED_AT_LEAST_ONE_CAMERA_LAYER; } - - // resets layer flag, if color layer is deleted - if (layer->getIsColorLayer()) - { - QString s = layer->name(); - s.chop(2); - Layer* artLayer = findLayerByName(s); - if (artLayer != nullptr) - artLayer->setHasColorLayer(false); - } - - object()->deleteLayer(layer); Q_ASSERT(object()->getLayerCount() >= 2); // current layer is the last layer && we are deleting it @@ -353,6 +341,16 @@ Status LayerManager::deleteLayer(int index) emit layerDeleted(index); emit layerCountChanged(count()); + // resets layer flag, if color layer is deleted + if (layer->getIsColorLayer()) + { + QString s = layer->name(); + s.chop(2); + Layer* artLayer = findLayerByName(s); + if (artLayer != nullptr) + artLayer->setHasColorLayer(false); + } + return Status::OK; } From 76338a60b668c26f66ab35dbc8f4757f65becea6 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 12 Aug 2023 14:39:03 +0200 Subject: [PATCH 095/100] Refactor code in deletelayer again --- core_lib/src/managers/layermanager.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core_lib/src/managers/layermanager.cpp b/core_lib/src/managers/layermanager.cpp index aebd51a1e4..10af16304a 100644 --- a/core_lib/src/managers/layermanager.cpp +++ b/core_lib/src/managers/layermanager.cpp @@ -325,6 +325,16 @@ Status LayerManager::deleteLayer(int index) } Q_ASSERT(object()->getLayerCount() >= 2); + // resets layer flag, if color layer is deleted + if (layer->getIsColorLayer()) + { + QString s = layer->name(); + s.chop(2); + Layer* artLayer = findLayerByName(s); + if (artLayer != nullptr) + artLayer->setHasColorLayer(false); + } + // current layer is the last layer && we are deleting it if (index == object()->getLayerCount() - 1 && index == currentLayerIndex()) @@ -341,16 +351,6 @@ Status LayerManager::deleteLayer(int index) emit layerDeleted(index); emit layerCountChanged(count()); - // resets layer flag, if color layer is deleted - if (layer->getIsColorLayer()) - { - QString s = layer->name(); - s.chop(2); - Layer* artLayer = findLayerByName(s); - if (artLayer != nullptr) - artLayer->setHasColorLayer(false); - } - return Status::OK; } From a5a69246f36ac085253719047820bef62ef23567 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 12 Aug 2023 15:50:00 +0200 Subject: [PATCH 096/100] Cleaned up code --- app/src/actioncommands.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/actioncommands.cpp b/app/src/actioncommands.cpp index b3c38988bf..1b8102e6a7 100644 --- a/app/src/actioncommands.cpp +++ b/app/src/actioncommands.cpp @@ -851,8 +851,6 @@ Status ActionCommands::deleteCurrentLayer() LayerManager* layerMgr = mEditor->layers(); QString strLayerName = layerMgr->currentLayer()->name(); - qDebug() << "current layer index: " << mEditor->layers()->currentLayerIndex(); - qDebug() << "count: " << mEditor->layers()->count(); if (!layerMgr->canDeleteLayer(mEditor->currentLayerIndex())) { return Status::CANCELED; } From 5427d989d14447a6bc8c1438c1ce5f868b5437b3 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 13 Aug 2023 12:40:33 +0200 Subject: [PATCH 097/100] Added info-popup for advanced coloring. --- app/src/bitmapcoloring.cpp | 34 ++++++++++++++++++-- app/src/bitmapcoloring.h | 1 + app/ui/bitmapcoloringwidget.ui | 28 ++++++++++++++-- core_lib/src/graphics/bitmap/bitmapimage.cpp | 2 +- 4 files changed, 59 insertions(+), 6 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 99f8a64930..8104ea1295 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -19,7 +19,6 @@ GNU General Public License for more details. #include "bitmapcoloring.h" #include "ui_bitmapcoloringwidget.h" #include "layermanager.h" -#include "toolmanager.h" #include "app_util.h" @@ -48,6 +47,7 @@ BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : connect(ui->cb3TraceAllKeyframes, &QCheckBox::stateChanged, this, &BitmapColoring::checkAllKeyframesBoxes); connect(ui->btnResetTrace, &QPushButton::clicked, this, &BitmapColoring::resetColoringDock); connect(ui->cbMethodSelector, QOverload::of(&QComboBox::currentIndexChanged), this, &BitmapColoring::enableTabs); + connect(ui->btnInfo, &QPushButton::clicked, this, &BitmapColoring::infoBox); // Prepare connect(ui->tabWidget, &QTabWidget::tabBarClicked, this, &BitmapColoring::tabWidgetClicked); @@ -197,6 +197,34 @@ void BitmapColoring::resetColoringDock() ui->cb3TraceAllKeyframes->setChecked(false); } +void BitmapColoring::infoBox() +{ + QMessageBox::information(this, tr("Basics in Advanced Coloring") + ,tr("Advanced coloring is developed for users that use color-separation to achieve a shade-effect.\n" + "It is assumed that the animation is done with black/gray pencil,\n" + "and you can use red, blue and/or green for the color-separation.\n\n" + "In this example, we have a active layer called 'Bird'.\n" + "The Advanced coloring creates two new layers, called 'Bird_L' and 'Bird_C'.\n" + "'Bird_L' is a copy of the Line-art layer, and 'Bird_C' is the Coloring layer.\n" + "STEP 1: Trace:\n" + "Make sure that you are on the layer 'Bird'!\n" + "Check the relevant boxes for color-separation.\n" + "Check the 'all drawings' box, if it is all drawings on layer. It most times is.\n" + "Press 'Trace'\n" + "STEP 2: Thin:\n" + "Make sure that you are on the layer 'Bird_C'!\n" + "Here the traced lines are thinned to 1 pixel thickness.\n" + "To avoid 'holes' in your thinned line, you can run the 'Fill small areas' first.\n" + "Your original layer 'Bird' is un-altered through the process, and should be made hidden.\n" + "Press 'Thin'\n" + "STEP 3: Colorize:\n" + "Choose the Bucket-tool. Reference 'current layer', and method 'Replace'\n" + "NB! Uncheck 'Color tolerance' and 'Expand fill'!\n" + "STEP 4: Blend:\n" + "Press 'Blend and Finish', and the thinned lines will dissappear,\n" + "and be replaced with blending af neighboring colors. You're done!\n\n")); +} + void BitmapColoring::enableTabs(int index) { Q_UNUSED(index) @@ -506,13 +534,13 @@ void BitmapColoring::prepareAndTraceLines() if (!lMgr->findLayerByName(orgName + "_L")) { - artLayer = lMgr->createBitmapLayer(orgName + "_L"); colorLayer = lMgr->createBitmapLayer(orgName + "_C"); + artLayer = lMgr->createBitmapLayer(orgName + "_L"); } else { - artLayer = static_cast(lMgr->findLayerByName(orgName + "_L")); colorLayer = static_cast(lMgr->findLayerByName(orgName + "_C")); + artLayer = static_cast(lMgr->findLayerByName(orgName + "_L")); } Q_ASSERT(artLayer && colorLayer); diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 4323d496be..71dbfa7350 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -36,6 +36,7 @@ public slots: void checkAllKeyframesBoxes(); void tabWidgetClicked(int index); void resetColoringDock(); + void infoBox(); void enableTabs(int index); // 1: Trace void updateTraceBoxes(); diff --git a/app/ui/bitmapcoloringwidget.ui b/app/ui/bitmapcoloringwidget.ui index e2600797d6..abe9e598d0 100644 --- a/app/ui/bitmapcoloringwidget.ui +++ b/app/ui/bitmapcoloringwidget.ui @@ -7,7 +7,7 @@ 0 0 282 - 403 + 485 @@ -47,6 +47,30 @@ + + + + + + Info + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -283,7 +307,7 @@ 20 - 49 + 19 diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 9d79ac953c..7e70189c62 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -918,7 +918,7 @@ void BitmapImage::fillSpotAreas(BitmapImage *img) // fill areas size 'area' or less with appropriate color QVector points; points.clear(); - QRgb active = blackline; + QRgb active; QRgb previous = blackline; for (int x = img->left() + 1; x < img->right(); x++) { From 6eaa9b96504759278877a11f1995d6bd7d762887 Mon Sep 17 00:00:00 2001 From: Jakob Gahde Date: Sun, 8 Oct 2023 22:02:15 +0200 Subject: [PATCH 098/100] Clean up --- app/data/app.qrc | 3 --- app/data/icons/black.png | Bin 154 -> 0 bytes app/data/icons/select.png | Bin 508 -> 0 bytes app/data/icons/select_ok.png | Bin 542 -> 0 bytes app/src/addtransparencytopaperdialog.cpp | 12 ++++------ app/src/addtransparencytopaperdialog.h | 9 +++----- app/src/bitmapcoloring.cpp | 17 ++++---------- app/src/bitmapcoloring.h | 23 +++++++------------ app/src/mainwindow2.cpp | 15 +++++------- app/src/mainwindow2.h | 4 +--- app/src/timelinecells.cpp | 1 - core_lib/src/graphics/bitmap/bitmapimage.cpp | 5 ---- core_lib/src/graphics/bitmap/bitmapimage.h | 4 ---- core_lib/src/interface/editor.cpp | 7 +----- core_lib/src/interface/editor.h | 5 ---- core_lib/src/managers/layermanager.cpp | 1 - core_lib/src/managers/layermanager.h | 3 --- core_lib/src/structure/layer.h | 1 - core_lib/src/structure/layerbitmap.cpp | 4 +--- core_lib/src/structure/layerbitmap.h | 1 - 20 files changed, 28 insertions(+), 87 deletions(-) delete mode 100644 app/data/icons/black.png delete mode 100644 app/data/icons/select.png delete mode 100644 app/data/icons/select_ok.png diff --git a/app/data/app.qrc b/app/data/app.qrc index 4973808cc5..b7573e0e07 100644 --- a/app/data/app.qrc +++ b/app/data/app.qrc @@ -54,12 +54,9 @@ icons/new/svg/smudge_detailed.svg icons/new/svg/trash_detailed.svg icons/new/checkerboard_smaller.png - icons/select.png icons/blue.png icons/green.png icons/red.png - icons/black.png - icons/select_ok.png icons/overlayCenter.png icons/overlayGoldenRatio.png icons/overlaySafe.png diff --git a/app/data/icons/black.png b/app/data/icons/black.png deleted file mode 100644 index 942f74e5b5481983e8df35dfd7f8b5c021e8c092..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 154 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|oCO|{#S9GG!XV7ZFl&wkP>{XE z)7O>#F*6gVrADi7K1fJ5GbEzKIX^cyHLnE7WngeFN=+-3|LrLz?wibHaQT082}JKjMxJ4?c29-=Ywb_CME_k zF)^%x2oOL_(b3WWU%Yt1@cQ*@xFF1SHa0c}4h{}5jSBz-5EICsAb(**4^#|9Bg=pM z_>tlL`}YhoGBRMN0|XEg%rD4ZfoT9a9fZ*h24R>!fB<4zvt|uS6v7mNG$OkKJ%(Tg z00a;VvY+Apg4&A9Yl4D;3~%1N0ZRe|5R<2;=YLqVp*s_sA?SR700M^rvSyeIVBSD> z5sdxi%NGVNE-rAO0R#{W$N*4GVDkdjXoJeZ!VMsR7;S89{)3V-$RJSW012w8slhW0 yEHeSq30RJsoBKb=LJ$VZGXewMFT@zOlQc?UwCD9D)eQ&-g}&L6h$FcRhiG{qN=s(VzH1UdY<8GwUQ75`2S`NT{J0TJQ)=ZARCA?;V+-__2C!-4&N zPp{XD04BjWO))teV|e}TZ6mUXAR;wHvtF+oCA?T&MiIdn!>g~?5#a9gZ#l0}5|9`p zyWI|JEpL9jf6|usH@5=N>2v_7s)}y6`^aE48pTw$b3peux01ed&ZZXd-ZvWMR3w!z z?de=q743HW*ooeILI{nfdH8ZC{~Mkpmbl4aFo@1My!RAEApre;zaE%0Ol4Un7BPfC g2m$Au$aBZ}FKcb #include #include @@ -19,13 +20,13 @@ AddTransparencyToPaperDialog::AddTransparencyToPaperDialog(QDialog *parent) : ui->mainLayout->setStretchFactor(ui->optionsLayout, 1); ui->mainLayout->setStretchFactor(ui->previewLayout, 20); - connect(this, &QDialog::finished, this, &AddTransparencyToPaperDialog::closeClicked); + connect(this, &QDialog::finished, this, &AddTransparencyToPaperDialog::closeDialog); connect(ui->sb_treshold, static_cast(&QSpinBox::valueChanged), this, &AddTransparencyToPaperDialog::SpinboxChanged); connect(ui->sliderThreshold, &QSlider::valueChanged, this, &AddTransparencyToPaperDialog::SliderChanged); connect(ui->cb_Red, &QCheckBox::stateChanged, this, &AddTransparencyToPaperDialog::updateDrawing); connect(ui->cb_Green, &QCheckBox::stateChanged, this, &AddTransparencyToPaperDialog::updateDrawing); connect(ui->cb_Blue, &QCheckBox::stateChanged, this, &AddTransparencyToPaperDialog::updateDrawing); - connect(ui->btnCancel, &QPushButton::clicked, this, &AddTransparencyToPaperDialog::closeClicked); + connect(ui->btnCancel, &QPushButton::clicked, this, &AddTransparencyToPaperDialog::closeDialog); connect(ui->btnApply, &QPushButton::clicked, this, &AddTransparencyToPaperDialog::traceScannedDrawings); connect(ui->testTransparencyCheckbox, &QCheckBox::stateChanged, this, &AddTransparencyToPaperDialog::checkerStateChanged); connect(ui->zoomSlider, &QSlider::valueChanged, this, &AddTransparencyToPaperDialog::zoomChanged); @@ -245,10 +246,5 @@ void AddTransparencyToPaperDialog::traceScannedDrawings() mEditor->setAutoSaveCounter(count); } if (ui->rbAllKeyframes->isChecked()) - closeClicked(); -} - -void AddTransparencyToPaperDialog::closeClicked() -{ - emit closeDialog(); + emit closeDialog(); } diff --git a/app/src/addtransparencytopaperdialog.h b/app/src/addtransparencytopaperdialog.h index 8f3b7866f7..459ab2cfd5 100644 --- a/app/src/addtransparencytopaperdialog.h +++ b/app/src/addtransparencytopaperdialog.h @@ -2,13 +2,12 @@ #define ADDTRANSPARENCYTOPAPERDIALOG_H #include -#include #include -#include #include "bitmapimage.h" class Editor; +class QGraphicsPixmapItem; namespace Ui { class AddTransparencyToPaperDialog; @@ -35,17 +34,15 @@ class AddTransparencyToPaperDialog : public QDialog private slots: void SpinboxChanged(int value); void SliderChanged(int value); - void loadDrawing(int frame); + void traceScannedDrawings(); void updateDrawing(); void layerChanged(int index); void checkerStateChanged(bool state); void zoomChanged(int zoomLevel); private: - void updatePreview(); - void traceScannedDrawings(); - void closeClicked(); + void loadDrawing(int frame); int mZoomLevel = 1; diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index 3bd154c02f..be53172813 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -18,7 +18,10 @@ GNU General Public License for more details. #include #include "bitmapcoloring.h" #include "ui_bitmapcoloringwidget.h" +#include "editor.h" +#include "layerbitmap.h" #include "layermanager.h" +#include "scribblearea.h" #include "app_util.h" @@ -111,7 +114,7 @@ void BitmapColoring::updateUI() mScribblearea->updateFrame(); } -void BitmapColoring::visibilityChanged(bool visibility) +void BitmapColoring::onVisibilityChanged(bool visibility) { if (visibility) updateUI(); @@ -245,11 +248,6 @@ void BitmapColoring::updateTraceBoxes() } } -void BitmapColoring::setThreshold(int threshold) -{ - mBitmapImage->setThreshold(threshold); -} - void BitmapColoring::traceLines() { if (mLayerBitmap == nullptr || mLayerBitmap->type() != Layer::BITMAP) { return; } @@ -664,13 +662,6 @@ void BitmapColoring::prepareLines() void BitmapColoring::trace() { - if (mSelectAreas) - { - mEditor->copy(); - mLayerBitmap->removeKeyFrame(mEditor->currentFrame()); - mLayerBitmap->addNewKeyFrameAt(mEditor->currentFrame()); - mEditor->paste(); - } mBitmapImage = mLayerBitmap->getBitmapImageAtFrame(mEditor->currentFrame()); if (mBitmapImage == nullptr) { diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 71dbfa7350..32c21525db 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -2,13 +2,11 @@ #define BITMAPCOLORING_H #include "basedockwidget.h" -#include "editor.h" -#include "layerbitmap.h" -#include "bitmapimage.h" -#include -#include "scribblearea.h" -class Layer; +class BitmapImage; +class Editor; +class LayerBitmap; +class ScribbleArea; namespace Ui { @@ -25,11 +23,9 @@ class BitmapColoring : public BaseDockWidget void initUI() override; void updateUI() override; - void visibilityChanged(bool visibility); + void onVisibilityChanged(bool visibility); -signals: - -public slots: +private slots: void checkRedBoxes(); void checkGreenBoxes(); void checkBlueBoxes(); @@ -40,7 +36,7 @@ public slots: void enableTabs(int index); // 1: Trace void updateTraceBoxes(); - void setThreshold(int threshold); + void prepareAndTraceLines(); void traceLines(); // 2: Thin void updateFillSpotsButton(); @@ -52,8 +48,7 @@ public slots: void updateBlendBoxes(); void blendLines(); -protected: - void prepareAndTraceLines(); +private: void prepareLines(); void trace(); void thin(); @@ -61,13 +56,11 @@ public slots: void nonValidBitmap(int frame); void updateTraceButtons(); -private: Ui::BitmapColoringWidget* ui = nullptr; Editor* mEditor = nullptr; ScribbleArea* mScribblearea = nullptr; LayerBitmap* mLayerBitmap = nullptr; BitmapImage* mBitmapImage = nullptr; - bool mSelectAreas = false; int mAnimLayer = 0; // Animation layer index int mColLayer = 0; // Coloring layer index bool mRedChecked = false; diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index add51fc68a..560b6edb65 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -67,6 +67,7 @@ GNU General Public License for more details. #include "bitmapcoloring.h" #include "onionskinwidget.h" #include "pegbaralignmentdialog.h" +#include "addtransparencytopaperdialog.h" #include "repositionframesdialog.h" //#include "preview.h" @@ -175,12 +176,6 @@ void MainWindow2::createDockWidgets() mBitmapColoring = new BitmapColoring(mEditor, this); mBitmapColoring->setObjectName("BitmapColoring"); - /* - mTimeline2 = new Timeline2; - mTimeline2->setObjectName( "Timeline2" ); - mDockWidgets.append( mTimeline2 ); - */ - mDockWidgets << mTimeLine << mColorBox @@ -211,7 +206,6 @@ void MainWindow2::createDockWidgets() addDockWidget(Qt::RightDockWidgetArea, mColorInspector); addDockWidget(Qt::RightDockWidgetArea, mColorPalette); addDockWidget(Qt::RightDockWidgetArea, mBitmapColoring); - mBitmapColoring->hide(); addDockWidget(Qt::LeftDockWidgetArea, mToolBox); addDockWidget(Qt::LeftDockWidgetArea, mToolOptions); addDockWidget(Qt::LeftDockWidgetArea, mOnionSkinWidget); @@ -238,7 +232,10 @@ void MainWindow2::createDockWidgets() for (BaseDockWidget* w : mDockWidgets) { w->setFloating(false); - w->show(); + if (w != mBitmapColoring) + { + w->show(); + } w->updateUI(); } } @@ -1555,7 +1552,7 @@ void MainWindow2::makeConnections(Editor* pEditor, TimeLine* pTimeline) connect(pEditor->layers(), &LayerManager::currentLayerChanged, this, &MainWindow2::updateLayerMenu); connect(pEditor->layers(), &LayerManager::currentLayerChanged, mToolOptions, &ToolOptionWidget::updateUI); connect(pEditor->layers(), &LayerManager::currentLayerChanged, mBitmapColoring, &BitmapColoring::updateUI); - connect(mBitmapColoring, &QDockWidget::visibilityChanged, mBitmapColoring, &BitmapColoring::visibilityChanged); + connect(mBitmapColoring, &QDockWidget::visibilityChanged, mBitmapColoring, &BitmapColoring::onVisibilityChanged); } void MainWindow2::makeConnections(Editor*, OnionSkinWidget*) diff --git a/app/src/mainwindow2.h b/app/src/mainwindow2.h index ea2edc562d..64f8444f3d 100644 --- a/app/src/mainwindow2.h +++ b/app/src/mainwindow2.h @@ -19,8 +19,6 @@ GNU General Public License for more details. #define MAINWINDOW2_H #include -#include "pegbaralignmentdialog.h" -#include "addtransparencytopaperdialog.h" template class QList; class QActionGroup; @@ -31,7 +29,6 @@ class ScribbleArea; class BaseDockWidget; class ColorPaletteWidget; class BitmapColoring; -class DisplayOptionWidget; class OnionSkinWidget; class ToolOptionWidget; class TimeLine; @@ -46,6 +43,7 @@ class ImportImageSeqDialog; class BackupElement; class LayerOpacityDialog; class PegBarAlignmentDialog; +class AddTransparencyToPaperDialog; class RepositionFramesDialog; class StatusBar; enum class SETTING; diff --git a/app/src/timelinecells.cpp b/app/src/timelinecells.cpp index 3a05144146..a25805aab3 100644 --- a/app/src/timelinecells.cpp +++ b/app/src/timelinecells.cpp @@ -20,7 +20,6 @@ GNU General Public License for more details. #include #include #include -#include #include #include #include diff --git a/core_lib/src/graphics/bitmap/bitmapimage.cpp b/core_lib/src/graphics/bitmap/bitmapimage.cpp index 813dc4c225..f49f1b4015 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.cpp +++ b/core_lib/src/graphics/bitmap/bitmapimage.cpp @@ -728,11 +728,6 @@ void BitmapImage::drawPath(QPainterPath path, QPen pen, QBrush brush, modification(); } -void BitmapImage::setBounds(QRect rect) -{ - updateBounds(rect); -} - BitmapImage* BitmapImage::scanToTransparent(BitmapImage *img, bool redEnabled, bool greenEnabled, bool blueEnabled) { Q_ASSERT(img != nullptr); diff --git a/core_lib/src/graphics/bitmap/bitmapimage.h b/core_lib/src/graphics/bitmap/bitmapimage.h index 1da333abe5..7c96191f2a 100644 --- a/core_lib/src/graphics/bitmap/bitmapimage.h +++ b/core_lib/src/graphics/bitmap/bitmapimage.h @@ -112,11 +112,8 @@ class BitmapImage : public KeyFrame QRect& bounds() { autoCrop(); return mBounds; } - void setBounds(QRect rect); // coloring methods - int getThreshold() { return mThreshold; } - int getSpotArea() { return mSpotArea; } BitmapImage* scanToTransparent(BitmapImage* bitmapimage, bool redEnabled, bool greenEnabled, bool blueEnabled); BitmapImage* prepDrawing(BitmapImage* img, bool redEnabled, bool greenEnabled, bool blueEnabled); void traceLine(BitmapImage* bitmapimage, bool blackEnabled, bool redEnabled, bool greenEnabled, bool blueEnabled); @@ -211,7 +208,6 @@ public slots: const int GRAYSCALEDIFF = 15; // difference in grasycale values to decide color const int TRANSP_THRESHOLD = 60;// threshold when tracing black for two layer coloring - const int RED_FACTOR = 20; qreal mOpacity = 1.0; }; diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 77af1886e5..6bf6c2d051 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -1087,11 +1087,6 @@ void Editor::selectAll() const select()->setSelection(rect, false); } -void Editor::notifyCurrentFrameUpdated() -{ - emit currentFrameUpdated(); -} - void Editor::deselectAll() const { select()->resetSelectionProperties(); @@ -1145,7 +1140,7 @@ void Editor::scrubTo(int frame) emit updateTimeLineCached(); // needs to update the timeline to update onion skin positions } mObject->updateActiveFrames(frame); - Q_EMIT scrubbedTo(frame); + emit scrubbedTo(frame); } void Editor::scrubForward() diff --git a/core_lib/src/interface/editor.h b/core_lib/src/interface/editor.h index 2c954ed81e..48b2d8cde6 100644 --- a/core_lib/src/interface/editor.h +++ b/core_lib/src/interface/editor.h @@ -154,8 +154,6 @@ class Editor : public QObject void objectLoaded(); void fpsChanged(int fps); - void changeThinLinesButton(bool); - void currentFrameChanged(int n); void scrubbedTo(int frame); void needSave(); @@ -193,8 +191,6 @@ class Editor : public QObject KeyFrame* addNewKey(); void removeKey(); - void notifyCurrentFrameUpdated(); - void notifyAnimationLengthChanged(); void switchVisibilityOfLayer(int layerNumber); void swapLayers(int i, int j); bool canSwapLayers(int layerIndexLeft, int layerIndexRight) const; @@ -240,7 +236,6 @@ class Editor : public QObject void resetAutoSaveCounter(); int getAutoSaveCounter() { return mAutosaveCounter; } void setAutoSaveCounter(int count) { mAutosaveCounter = count; } - bool getIsDoingRepeatColoring() { return mIsDoingRepeatInColoring; } void setIsDoingRepeatColoring(bool b) { mIsDoingRepeatInColoring = b; } diff --git a/core_lib/src/managers/layermanager.cpp b/core_lib/src/managers/layermanager.cpp index 10af16304a..3ddd378ccc 100644 --- a/core_lib/src/managers/layermanager.cpp +++ b/core_lib/src/managers/layermanager.cpp @@ -19,7 +19,6 @@ GNU General Public License for more details. #include "object.h" #include "editor.h" -#include "bitmapimage.h" #include "layersound.h" #include "layerbitmap.h" diff --git a/core_lib/src/managers/layermanager.h b/core_lib/src/managers/layermanager.h index c99ad1da6b..d4cbc8ce7d 100644 --- a/core_lib/src/managers/layermanager.h +++ b/core_lib/src/managers/layermanager.h @@ -65,9 +65,6 @@ class LayerManager : public BaseManager LayerCamera* createCameraLayer(const QString& strLayerName); LayerSound* createSoundLayer(const QString& strLayerName); - // color layer - Status copyLayer(Layer* fromLayer, Layer* toLayer); - // KeyFrame Management int lastFrameAtFrame(int frameIndex); int firstKeyFrameIndex(); diff --git a/core_lib/src/structure/layer.h b/core_lib/src/structure/layer.h index 9e15875428..20c90b2024 100644 --- a/core_lib/src/structure/layer.h +++ b/core_lib/src/structure/layer.h @@ -77,7 +77,6 @@ class Layer : public QObject /** Get selected keyframe positions based on the order they were selected */ QList selectedKeyFramesByLast() const { return mSelectedFrames_byLast; } - virtual Status saveKeyFrameFile(KeyFrame*, QString dataPath) = 0; virtual void loadDomElement(const QDomElement& element, QString dataDirPath, ProgressCallback progressForward) = 0; virtual QDomElement createDomElement(QDomDocument& doc) const = 0; diff --git a/core_lib/src/structure/layerbitmap.cpp b/core_lib/src/structure/layerbitmap.cpp index 2db1f859b0..1194640462 100644 --- a/core_lib/src/structure/layerbitmap.cpp +++ b/core_lib/src/structure/layerbitmap.cpp @@ -19,11 +19,9 @@ GNU General Public License for more details. #include #include #include -#include #include "keyframe.h" #include "bitmapimage.h" -#include -#include + LayerBitmap::LayerBitmap(Object* object) : Layer(object, Layer::BITMAP) { diff --git a/core_lib/src/structure/layerbitmap.h b/core_lib/src/structure/layerbitmap.h index 85461e30d5..4865dd64a2 100644 --- a/core_lib/src/structure/layerbitmap.h +++ b/core_lib/src/structure/layerbitmap.h @@ -27,7 +27,6 @@ class LayerBitmap : public Layer Q_OBJECT public: - LayerBitmap(Object* object); ~LayerBitmap() override; From 88695a1306baba44491bf9359c0e6110ef881d05 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Thu, 15 Feb 2024 11:58:34 +0100 Subject: [PATCH 099/100] Fixed copyFrame, after it has been deleted from layer class --- app/src/bitmapcoloring.cpp | 32 ++++++++++++++++++++++++++++++++ app/src/bitmapcoloring.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index be53172813..d89ef7b7da 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -23,6 +23,7 @@ GNU General Public License for more details. #include "layermanager.h" #include "scribblearea.h" #include "app_util.h" +#include "object.h" BitmapColoring::BitmapColoring(Editor* editor, QWidget *parent) : @@ -745,3 +746,34 @@ void BitmapColoring::updateTraceButtons() ui->btnApplyTrace->setEnabled(true); } } + +void BitmapColoring::copyFrame(LayerBitmap *fromLayer, LayerBitmap *toLayer, int frame) +{ + if (fromLayer->keyExists(frame)) + { + KeyFrame* keyframe = fromLayer->getKeyFrameAt(frame); + KeyFrame* dupKey = keyframe->clone(); + if (toLayer->keyExists(frame) && toLayer->keyFrameCount() == 1) + { + int i = toLayer->firstKeyFramePosition(); + if (i == frame) + { + toLayer->addKeyFrame(frame + 1, dupKey); + toLayer->removeKeyFrame(frame); + toLayer->moveKeyFrame(frame + 1, -1); + } else + { + toLayer->addKeyFrame(frame, dupKey); + toLayer->removeKeyFrame(i); + } + } + else + { + toLayer->removeKeyFrame(frame); + toLayer->addKeyFrame(frame, dupKey); + } + toLayer->setModified(frame, true); + toLayer->getKeyFrameAt(frame)->modification(); + } + +} diff --git a/app/src/bitmapcoloring.h b/app/src/bitmapcoloring.h index 32c21525db..c6f2191b7b 100644 --- a/app/src/bitmapcoloring.h +++ b/app/src/bitmapcoloring.h @@ -3,11 +3,13 @@ #include "basedockwidget.h" +class Object; class BitmapImage; class Editor; class LayerBitmap; class ScribbleArea; + namespace Ui { class BitmapColoringWidget; @@ -55,6 +57,7 @@ private slots: void blend(LayerBitmap* artLayer); void nonValidBitmap(int frame); void updateTraceButtons(); + void copyFrame(LayerBitmap *fromLayer, LayerBitmap *toLayer, int frame); Ui::BitmapColoringWidget* ui = nullptr; Editor* mEditor = nullptr; From be5013afece3aedf657b3c59b4d4146dee68b52c Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Thu, 15 Feb 2024 12:18:29 +0100 Subject: [PATCH 100/100] Finally got copyFrame running. --- app/src/bitmapcoloring.cpp | 10 +++++----- core_lib/src/structure/layer.cpp | 31 ------------------------------- core_lib/src/structure/layer.h | 1 - 3 files changed, 5 insertions(+), 37 deletions(-) diff --git a/app/src/bitmapcoloring.cpp b/app/src/bitmapcoloring.cpp index d89ef7b7da..e064f92dda 100644 --- a/app/src/bitmapcoloring.cpp +++ b/app/src/bitmapcoloring.cpp @@ -554,13 +554,13 @@ void BitmapColoring::prepareAndTraceLines() { mEditor->scrubTo(i); lMgr->setCurrentLayer(sourceLayer); - sourceLayer->copyFrame(sourceLayer, artLayer, i); + copyFrame(sourceLayer, artLayer, i); BitmapImage* image = artLayer->getBitmapImageAtFrame(i); image->prepDrawing(image, mRedChecked, mGreenChecked, mBlueChecked); - artLayer->copyFrame(artLayer, colorLayer, i); + copyFrame(artLayer, colorLayer, i); BitmapImage* colorImage = colorLayer->getBitmapImageAtFrame(i); colorImage->traceLine(colorImage, black, @@ -581,13 +581,13 @@ void BitmapColoring::prepareAndTraceLines() if (sourceLayer->keyExists(i)) { lMgr->setCurrentLayer(sourceLayer); - sourceLayer->copyFrame(sourceLayer, artLayer, i); + copyFrame(sourceLayer, artLayer, i); BitmapImage* image = artLayer->getBitmapImageAtFrame(i); image->prepDrawing(image, mRedChecked, mGreenChecked, mBlueChecked); - artLayer->copyFrame(artLayer, colorLayer, i); + copyFrame(artLayer, colorLayer, i); BitmapImage* colorImage = colorLayer->getBitmapImageAtFrame(i); colorImage->traceLine(colorImage, black, @@ -645,7 +645,7 @@ void BitmapColoring::prepareLines() if (ui->cbMethodSelector->currentIndex() == 2) { - mLayerBitmap->copyFrame(mLayerBitmap, colorLayer, mEditor->currentFrame()); + copyFrame(mLayerBitmap, colorLayer, mEditor->currentFrame()); } mBitmapImage = colorLayer->getBitmapImageAtFrame(mEditor->currentFrame()); if (mBitmapImage == nullptr) diff --git a/core_lib/src/structure/layer.cpp b/core_lib/src/structure/layer.cpp index 71a7746d00..1e5f435538 100644 --- a/core_lib/src/structure/layer.cpp +++ b/core_lib/src/structure/layer.cpp @@ -382,37 +382,6 @@ void Layer::setModified(int position, bool modified) const } } -void Layer::copyFrame(Layer *fromLayer, Layer *toLayer, int frame) -{ - if (fromLayer->keyExists(frame)) - { - mObject->updateActiveFrames(frame); - KeyFrame* keyframe = fromLayer->getKeyFrameAt(frame); - KeyFrame* dupKey = keyframe->clone(); - if (toLayer->keyExists(frame) && toLayer->keyFrameCount() == 1) - { - int i = toLayer->firstKeyFramePosition(); - if (i == frame) - { - toLayer->addKeyFrame(frame + 1, dupKey); - toLayer->removeKeyFrame(frame); - toLayer->moveKeyFrame(frame + 1, -1); - } else - { - toLayer->addKeyFrame(frame, dupKey); - toLayer->removeKeyFrame(i); - } - } - else - { - toLayer->removeKeyFrame(frame); - toLayer->addKeyFrame(frame, dupKey); - } - toLayer->setModified(frame, true); - toLayer->getKeyFrameAt(frame)->modification(); - } -} - bool Layer::isFrameSelected(int position) const { KeyFrame* keyFrame = getKeyFrameWhichCovers(position); diff --git a/core_lib/src/structure/layer.h b/core_lib/src/structure/layer.h index 20c90b2024..3dbce2eed4 100644 --- a/core_lib/src/structure/layer.h +++ b/core_lib/src/structure/layer.h @@ -115,7 +115,6 @@ class Layer : public QObject void foreachKeyFrame(std::function) const; - void copyFrame(Layer *fromLayer, Layer *toLayer, int frame); void setModified(int position, bool isModified) const; // Handle selection