diff --git a/toonz/sources/tnztools/bluredbrush.cpp b/toonz/sources/tnztools/bluredbrush.cpp index fdc01a0..9530079 100644 --- a/toonz/sources/tnztools/bluredbrush.cpp +++ b/toonz/sources/tnztools/bluredbrush.cpp @@ -27,7 +27,8 @@ QImage rasterToQImage(const TRasterP &ras, bool premultiplied = false) { //---------------------------------------------------------------------------------- // drawOrderMode : 0=OverAll, 1=UnderAll, 2=PaletteOrder void putOnRasterCM(const TRasterCM32P &out, const TRaster32P &in, int styleId, - int drawOrderMode, const QSet &aboveStyleIds) { + int drawOrderMode, bool lockAlpha, + const QSet &aboveStyleIds) { if (!out.getPointer() || !in.getPointer()) return; assert(out->getSize() == in->getSize()); int x, y; @@ -43,6 +44,12 @@ void putOnRasterCM(const TRasterCM32P &out, const TRaster32P &in, int styleId, TPixel32 *inPix = &in->pixels(y)[x]; if (inPix->m == 0) continue; TPixelCM32 *outPix = &out->pixels(y)[x]; + if (lockAlpha && !outPix->isPureInk() && outPix->getPaint() == 0 && + outPix->getTone() == 255) { + *outPix = TPixelCM32(outPix->getInk(), outPix->getPaint(), + outPix->getTone()); + continue; + } bool sameStyleId = styleId == outPix->getInk(); // line with the same style : multiply tones // line with different style : pick darker tone @@ -66,6 +73,12 @@ void putOnRasterCM(const TRasterCM32P &out, const TRaster32P &in, int styleId, TPixel32 *inPix = &in->pixels(y)[x]; if (inPix->m == 0) continue; TPixelCM32 *outPix = &out->pixels(y)[x]; + if (lockAlpha && !outPix->isPureInk() && outPix->getPaint() == 0 && + outPix->getTone() == 255) { + *outPix = TPixelCM32(outPix->getInk(), outPix->getPaint(), + outPix->getTone()); + continue; + } bool sameStyleId = styleId == outPix->getInk(); // line with the same style : multiply tones // line with different style : pick darker tone @@ -83,6 +96,12 @@ void putOnRasterCM(const TRasterCM32P &out, const TRaster32P &in, int styleId, TPixel32 *inPix = &in->pixels(y)[x]; if (inPix->m == 0) continue; TPixelCM32 *outPix = &out->pixels(y)[x]; + if (lockAlpha && !outPix->isPureInk() && outPix->getPaint() == 0 && + outPix->getTone() == 255) { + *outPix = TPixelCM32(outPix->getInk(), outPix->getPaint(), + outPix->getTone()); + continue; + } bool sameStyleId = styleId == outPix->getInk(); // line with the same style : multiply tones // line with different style : pick darker tone @@ -365,7 +384,7 @@ void BluredBrush::eraseDrawing(const TRasterP ras, const TRasterP rasBackup, void BluredBrush::updateDrawing(const TRasterCM32P rasCM, const TRasterCM32P rasBackupCM, const TRect &bbox, int styleId, - int drawOrderMode) const { + int drawOrderMode, bool lockAlpha) const { if (!rasCM) return; TRect rasRect = rasCM->getBounds(); @@ -374,7 +393,7 @@ void BluredBrush::updateDrawing(const TRasterCM32P rasCM, rasCM->copy(rasBackupCM->extract(targetRect), targetRect.getP00()); putOnRasterCM(rasCM->extract(targetRect), m_ras->extract(targetRect), styleId, - drawOrderMode, m_aboveStyleIds); + drawOrderMode, lockAlpha, m_aboveStyleIds); } //---------------------------------------------------------------------------------- diff --git a/toonz/sources/tnztools/bluredbrush.h b/toonz/sources/tnztools/bluredbrush.h index e1468a4..3f7a32c 100644 --- a/toonz/sources/tnztools/bluredbrush.h +++ b/toonz/sources/tnztools/bluredbrush.h @@ -40,7 +40,8 @@ public: TRect getBoundFromPoints(const std::vector &points) const; // colormapped void updateDrawing(const TRasterCM32P rasCM, const TRasterCM32P rasBackupCM, - const TRect &bbox, int styleId, int drawOrderMode) const; + const TRect &bbox, int styleId, int drawOrderMode, + bool lockAlpha) const; void eraseDrawing(const TRasterCM32P rasCM, const TRasterCM32P rasBackupCM, const TRect &bbox, bool selective, int selectedStyleId, const std::wstring &mode) const; diff --git a/toonz/sources/tnztools/geometrictool.cpp b/toonz/sources/tnztools/geometrictool.cpp index a99b324..f878ee0 100644 --- a/toonz/sources/tnztools/geometrictool.cpp +++ b/toonz/sources/tnztools/geometrictool.cpp @@ -181,7 +181,7 @@ static TRect drawBluredBrush(const TToonzImageP &ti, TStroke *stroke, int thick, TRect chunkBox = brush.getBoundFromPoints(points); brush.addArc(points[0], points[1], points[2], 1, 1); brush.updateDrawing(ti->getRaster(), backupRas, chunkBox, styleId, - selective); + selective, false); } delete s; diff --git a/toonz/sources/tnztools/toonzrasterbrushtool.cpp b/toonz/sources/tnztools/toonzrasterbrushtool.cpp index b985c74..08d0621 100644 --- a/toonz/sources/tnztools/toonzrasterbrushtool.cpp +++ b/toonz/sources/tnztools/toonzrasterbrushtool.cpp @@ -488,19 +488,22 @@ class RasterBluredBrushUndo final : public TRasterUndo { DrawOrder m_drawOrder; int m_maxThick; double m_hardness; + bool m_modifierLockAlpha; public: RasterBluredBrushUndo(TTileSetCM32 *tileSet, const std::vector &points, int styleId, - DrawOrder drawOrder, TXshSimpleLevel *level, - const TFrameId &frameId, int maxThick, double hardness, - bool isFrameCreated, bool isLevelCreated) + DrawOrder drawOrder, bool lockAlpha, + TXshSimpleLevel *level, const TFrameId &frameId, + int maxThick, double hardness, bool isFrameCreated, + bool isLevelCreated) : TRasterUndo(tileSet, level, frameId, isFrameCreated, isLevelCreated, 0) , m_points(points) , m_styleId(styleId) , m_drawOrder(drawOrder) , m_maxThick(maxThick) - , m_hardness(hardness) {} + , m_hardness(hardness) + , m_modifierLockAlpha(lockAlpha) {} void redo() const override { if (m_points.size() == 0) return; @@ -523,7 +526,8 @@ public: points.push_back(m_points[0]); TRect bbox = brush.getBoundFromPoints(points); brush.addPoint(m_points[0], 1); - brush.updateDrawing(ras, ras, bbox, m_styleId, (int)m_drawOrder); + brush.updateDrawing(ras, ras, bbox, m_styleId, (int)m_drawOrder, + m_modifierLockAlpha); if (m_points.size() > 1) { points.clear(); points.push_back(m_points[0]); @@ -531,7 +535,8 @@ public: bbox = brush.getBoundFromPoints(points); brush.addArc(m_points[0], (m_points[1] + m_points[0]) * 0.5, m_points[1], 1, 1); - brush.updateDrawing(ras, backupRas, bbox, m_styleId, (int)m_drawOrder); + brush.updateDrawing(ras, backupRas, bbox, m_styleId, (int)m_drawOrder, + m_modifierLockAlpha); int i; for (i = 1; i + 2 < (int)m_points.size(); i = i + 2) { points.clear(); @@ -540,7 +545,8 @@ public: points.push_back(m_points[i + 2]); bbox = brush.getBoundFromPoints(points); brush.addArc(m_points[i], m_points[i + 1], m_points[i + 2], 1, 1); - brush.updateDrawing(ras, backupRas, bbox, m_styleId, (int)m_drawOrder); + brush.updateDrawing(ras, backupRas, bbox, m_styleId, (int)m_drawOrder, + m_modifierLockAlpha); } } ToolUtils::updateSaveBox(); @@ -1379,7 +1385,8 @@ void ToonzRasterBrushTool::leftButtonDown(const TPointD &pos, m_tileSaver->save(m_strokeRect); m_bluredBrush->addPoint(point, 1); m_bluredBrush->updateDrawing(ri->getRaster(), m_backupRas, m_strokeRect, - m_styleId, drawOrder); + m_styleId, drawOrder, + m_modifierLockAlpha.getValue()); m_lastRect = m_strokeRect; std::vector pts; @@ -1519,7 +1526,8 @@ void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos, invalidateRect += ToolUtils::getBounds(points, maxThickness) - rasCenter; m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox, - m_styleId, m_drawOrder.getIndex()); + m_styleId, m_drawOrder.getIndex(), + m_modifierLockAlpha.getValue()); m_strokeRect += bbox; } } @@ -1719,7 +1727,8 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, ToolUtils::getBounds(points, maxThickness) - rasCenter; m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox, - m_styleId, m_drawOrder.getIndex()); + m_styleId, m_drawOrder.getIndex(), + m_modifierLockAlpha.getValue()); m_strokeRect += bbox; } TThickPoint point = pts.back(); @@ -1734,7 +1743,8 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, m_tileSaver->save(bbox); m_bluredBrush->addArc(points[0], points[1], points[2], 1, 1); m_bluredBrush->updateDrawing(ti->getRaster(), m_backupRas, bbox, - m_styleId, m_drawOrder.getIndex()); + m_styleId, m_drawOrder.getIndex(), + m_modifierLockAlpha.getValue()); invalidateRect += ToolUtils::getBounds(points, maxThickness) - rasCenter; @@ -1750,8 +1760,9 @@ void ToonzRasterBrushTool::finishRasterBrush(const TPointD &pos, if (m_tileSet->getTileCount() > 0) { TUndoManager::manager()->add(new RasterBluredBrushUndo( m_tileSet, m_points, m_styleId, (DrawOrder)m_drawOrder.getIndex(), - simLevel.getPointer(), frameId, m_rasThickness.getValue().second, - m_hardness.getValue() * 0.01, m_isFrameCreated, m_isLevelCreated)); + m_modifierLockAlpha.getValue(), simLevel.getPointer(), frameId, + m_rasThickness.getValue().second, m_hardness.getValue() * 0.01, + m_isFrameCreated, m_isLevelCreated)); } } delete m_tileSaver;