vector/vrle: added free function for + and & operator
authorSubhransu Mohanty <sub.mohanty@samsung.com>
Fri, 14 Aug 2020 07:54:35 +0000 (16:54 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Mon, 17 Aug 2020 22:22:02 +0000 (07:22 +0900)
- removed unused functions.

src/lottie/lottieitem.cpp
src/vector/vrle.cpp
src/vector/vrle.h

index eb5e950..ec7586f 100644 (file)
@@ -8,8 +8,8 @@
  * copies of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
 
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
 
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
@@ -287,8 +287,12 @@ VRle renderer::LayerMask::maskRle(const VRect &clipRect)
 
     VRle rle;
     for (auto &e : mMasks) {
-        auto cur = e.rle();
-        if (e.inverted()) cur = VRle::toRle(clipRect) - cur;
+        const auto cur = [&]() {
+            if (e.inverted())
+                return clipRect - e.rle();
+            else
+                return e.rle();
+        }();
 
         switch (e.maskMode()) {
         case model::Mask::Mode::Add: {
@@ -296,13 +300,17 @@ VRle renderer::LayerMask::maskRle(const VRect &clipRect)
             break;
         }
         case model::Mask::Mode::Substarct: {
-            if (rle.empty() && !clipRect.empty()) rle = VRle::toRle(clipRect);
-            rle = rle - cur;
+            if (rle.empty() && !clipRect.empty())
+                rle = clipRect - cur;
+            else
+                rle = rle - cur;
             break;
         }
         case model::Mask::Mode::Intersect: {
-            if (rle.empty() && !clipRect.empty()) rle = VRle::toRle(clipRect);
-            rle = rle & cur;
+            if (rle.empty() && !clipRect.empty())
+                rle = clipRect & cur;
+            else
+                rle = rle & cur;
             break;
         }
         case model::Mask::Mode::Difference: {
index 08502eb..328b6c8 100644 (file)
@@ -8,7 +8,8 @@
  * copies of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
 
- * The above copyright notice and this permission notice shall be included in all
+ * The above copyright notice and this permission notice shall be included in
+ all
  * copies or substantial portions of the Software.
 
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
@@ -120,7 +121,7 @@ void VRle::VRleData::addRect(const VRect &rect)
         span.coverage = 255;
         mSpans.push_back(span);
     }
-    updateBbox();
+    mBbox = rect;
 }
 
 void VRle::VRleData::updateBbox() const
@@ -146,13 +147,6 @@ void VRle::VRleData::updateBbox() const
     }
 }
 
-void VRle::VRleData::invert()
-{
-    for (auto &i : mSpans) {
-        i.coverage = 255 - i.coverage;
-    }
-}
-
 void VRle::VRleData::operator*=(uchar alpha)
 {
     for (auto &i : mSpans) {
@@ -717,15 +711,6 @@ static void rleSubstractWithRle(VRleHelper *a, VRleHelper *b,
     result->size = result->alloc - available;
 }
 
-VRle VRle::toRle(const VRect &rect)
-{
-    if (rect.empty()) return VRle();
-
-    VRle result;
-    result.d.write().addRect(rect);
-    return result;
-}
-
 /*
  * this api makes use of thread_local temporary
  * buffer to avoid creating intermediate temporary rle buffer
@@ -748,4 +733,30 @@ void VRle::operator&=(const VRle &o)
     d.write() = Scratch_Object;
 }
 
+VRle operator-(const VRect &rect, const VRle &o)
+{
+    if (rect.empty()) return {};
+
+    Scratch_Object.reset();
+    Scratch_Object.addRect(rect);
+
+    VRle result;
+    result.d.write().opSubstract(Scratch_Object, o.d.read());
+
+    return result;
+}
+
+VRle operator&(const VRect &rect, const VRle &o)
+{
+    if (rect.empty() || o.empty()) return {};
+
+    Scratch_Object.reset();
+    Scratch_Object.addRect(rect);
+
+    VRle result;
+    result.d.write().opIntersect(Scratch_Object, o.d.read());
+
+    return result;
+}
+
 V_END_NAMESPACE
index eb9d79b..d25ef8d 100644 (file)
@@ -8,8 +8,8 @@
  * copies of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
 
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
 
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
@@ -39,16 +39,15 @@ public:
         ushort len{0};
         uchar  coverage{0};
     };
-    using VRleSpanCb =  void (*)(size_t count, const VRle::Span *spans,
-                                 void *userData);
+    using VRleSpanCb = void (*)(size_t count, const VRle::Span *spans,
+                                void *userData);
     bool  empty() const;
     VRect boundingRect() const;
-    void setBoundingRect(const VRect &bbox);
+    void  setBoundingRect(const VRect &bbox);
     void  addSpan(const VRle::Span *span, size_t count);
 
     void reset();
     void translate(const VPoint &p);
-    void invert();
 
     void operator*=(uchar alpha);
 
@@ -61,42 +60,43 @@ public:
     VRle operator+(const VRle &o) const;
     VRle operator^(const VRle &o) const;
 
-    static VRle toRle(const VRect &rect);
+    friend VRle operator-(const VRect &rect, const VRle &o);
+    friend VRle operator&(const VRect &rect, const VRle &o);
 
-    bool unique() const {return d.unique();}
-    size_t refCount() const { return d.refCount();}
-    void clone(const VRle &o);
+    bool   unique() const { return d.unique(); }
+    size_t refCount() const { return d.refCount(); }
+    void   clone(const VRle &o);
 
 public:
     struct VRleData {
-        enum class OpCode {
-            Add,
-            Xor
-        };
+        enum class OpCode { Add, Xor };
         bool  empty() const { return mSpans.empty(); }
         void  addSpan(const VRle::Span *span, size_t count);
         void  updateBbox() const;
         VRect bbox() const;
-        void setBbox(const VRect &bbox) const;
+        void  setBbox(const VRect &bbox) const;
         void  reset();
         void  translate(const VPoint &p);
         void  operator*=(uchar alpha);
-        void  invert();
         void  opIntersect(const VRect &, VRle::VRleSpanCb, void *) const;
-        void  opGeneric(const VRle::VRleData &, const VRle::VRleData &, OpCode code);
+        void  opGeneric(const VRle::VRleData &, const VRle::VRleData &,
+                        OpCode code);
         void  opSubstract(const VRle::VRleData &, const VRle::VRleData &);
         void  opIntersect(const VRle::VRleData &, const VRle::VRleData &);
         void  addRect(const VRect &rect);
         void  clone(const VRle::VRleData &);
+
         std::vector<VRle::Span> mSpans;
         VPoint                  mOffset;
         mutable VRect           mBbox;
         mutable bool            mBboxDirty = true;
     };
+
 private:
     friend void opIntersectHelper(const VRle::VRleData &obj1,
                                   const VRle::VRleData &obj2,
                                   VRle::VRleSpanCb cb, void *userData);
+
     vcow_ptr<VRleData> d;
 };
 
@@ -115,16 +115,11 @@ inline VRect VRle::boundingRect() const
     return d->bbox();
 }
 
-inline void VRle::setBoundingRect(const VRect & bbox)
+inline void VRle::setBoundingRect(const VRect &bbox)
 {
     d->setBbox(bbox);
 }
 
-inline void VRle::invert()
-{
-    d.write().invert();
-}
-
 inline void VRle::operator*=(uchar alpha)
 {
     d.write() *= alpha;