Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

refactor: extract adjustFillDepth

Abel You1cf161547ae4
diff --git a/toonz/sources/toonzlib/fill.cpp b/toonz/sources/toonzlib/fill.cpp
index 05b6f2378..01b521ca6 100644
--- a/toonz/sources/toonzlib/fill.cpp
+++ b/toonz/sources/toonzlib/fill.cpp
@@ -12,6 +12,37 @@
//-----------------------------------------------------------------------------
namespace { // Utility Function
+//-----------------------------------------------------------------------------
+
+inline int threshTone(const TPixelCM32 &pix, int fillDepth) {
+ if (fillDepth == TPixelCM32::getMaxTone())
+ return pix.getTone();
+ else
+ return ((pix.getTone()) > fillDepth) ? TPixelCM32::getMaxTone()
+ : pix.getTone();
+}
+
+inline int adjustFillDepth(const int &fillDepth) {
+ assert(fillDepth >= 0 && fillDepth < 16);
+
+ switch (TPixelCM32::getMaxTone()) {
+ case 15:
+ return 15 - fillDepth;
+ case 255:
+ return ((15 - fillDepth) << 4) | (15 - fillDepth);
+ default:
+ assert(false);
+ return -1;
+ }
+}
+
+inline int threshMatte(int matte, int fillDepth) {
+ if (fillDepth == 255)
+ return matte;
+ else
+ return (matte < fillDepth) ? 255 : matte;
+}
+
inline TPoint nearestInkNotDiagonal(const TRasterCM32P &r, const TPoint &p) {
TPixelCM32 *buf = (TPixelCM32 *)r->pixels(p.y) + p.x;
@@ -368,22 +399,6 @@ public:
//-----------------------------------------------------------------------------
-inline int threshTone(const TPixelCM32 &pix, int fillDepth) {
- if (fillDepth == TPixelCM32::getMaxTone())
- return pix.getTone();
- else
- return ((pix.getTone()) > fillDepth) ? TPixelCM32::getMaxTone()
- : pix.getTone();
-}
-
-//-----------------------------------------------------------------------------
-
-inline int threshMatte(int matte, int fillDepth) {
- if (fillDepth == 255)
- return matte;
- else
- return (matte < fillDepth) ? 255 : matte;
-}
//-----------------------------------------------------------------------------
@@ -571,18 +586,8 @@ bool fill(const TRasterCM32P &r, const FillParameters &params,
TRop::putRefImage(r, Ref);
}
- assert(fillDepth >= 0 && fillDepth < 16);
-
- switch (TPixelCM32::getMaxTone()) {
- case 15:
- fillDepth = (15 - fillDepth);
- break;
- case 255:
- fillDepth = ((15 - fillDepth) << 4) | (15 - fillDepth);
- break;
- default:
- assert(false);
- }
+ fillDepth = adjustFillDepth(fillDepth);
+
/*--Look at the colors in the four corners and update the saveBox if any of
* the colors change. --*/
TPixelCM32 borderIndex[4];