summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsubhransu sekhar mohanty <smohantty@subhransus-MacBook-Air.local>2018-07-07 13:26:21 +0900
committersubhransu sekhar mohanty <smohantty@subhransus-MacBook-Air.local>2018-07-07 16:35:43 +0900
commitfdb6fd794e72e614ef427aa8bcbfab48da04ae04 (patch)
tree66252b4373b8965ae27625fa70fcec93cd3fde93
parent719d8d26716bad5667d32ea25d9192d8a98587ee (diff)
lottie: added intersected , * and ~ operator overload api in sgrle.
-rw-r--r--include/sgrle.h10
-rw-r--r--src/painting/vpainter.cpp2
-rw-r--r--src/util/sgrle.cpp87
3 files changed, 96 insertions, 3 deletions
diff --git a/include/sgrle.h b/include/sgrle.h
index be12729..32682c0 100644
--- a/include/sgrle.h
+++ b/include/sgrle.h
@@ -34,6 +34,9 @@ public:
34 SGRle &intersect(const SGRect &r); 34 SGRle &intersect(const SGRect &r);
35 int size() const; 35 int size() const;
36 const SGRle::Span* data() const; 36 const SGRle::Span* data() const;
37 SGRle operator~() const;
38 friend SGRle operator*(const SGRle &, float alpha);
39 inline friend SGRle operator*(float alpha, const SGRle &);
37 friend SGDebug& operator<<(SGDebug& os, const SGRle& object); 40 friend SGDebug& operator<<(SGDebug& os, const SGRle& object);
38private: 41private:
39 SGRle copy() const; 42 SGRle copy() const;
@@ -41,8 +44,15 @@ private:
41 void cleanUp(SGRleData *x); 44 void cleanUp(SGRleData *x);
42 SGRleData *d; 45 SGRleData *d;
43}; 46};
47
44inline void SGRle::translate(int x, int y) 48inline void SGRle::translate(int x, int y)
45{ 49{
46 translate(SGPoint(x,y)); 50 translate(SGPoint(x,y));
47} 51}
52
53inline SGRle operator*(float alpha, const SGRle &rle)
54{
55 return (rle * alpha);
56}
57
48#endif // SGRLE_H 58#endif // SGRLE_H
diff --git a/src/painting/vpainter.cpp b/src/painting/vpainter.cpp
index 03078f3..23d01cb 100644
--- a/src/painting/vpainter.cpp
+++ b/src/painting/vpainter.cpp
@@ -13,7 +13,7 @@ public:
13void VPainterImpl::drawRle(const SGPoint &pos, const SGRle &rle) 13void VPainterImpl::drawRle(const SGPoint &pos, const SGRle &rle)
14{ 14{
15 if (rle.isEmpty()) return; 15 if (rle.isEmpty()) return;
16 mSpanData.updateSpanFunc(); 16 //mSpanData.updateSpanFunc();
17 17
18 if (!mSpanData.mUnclippedBlendFunc) return; 18 if (!mSpanData.mUnclippedBlendFunc) return;
19 19
diff --git a/src/util/sgrle.cpp b/src/util/sgrle.cpp
index 7e26286..20d64b5 100644
--- a/src/util/sgrle.cpp
+++ b/src/util/sgrle.cpp
@@ -18,7 +18,7 @@ struct SGRleHelper
18#define SGMAX(a,b) ((a) > (b) ? (a) : (b)) 18#define SGMAX(a,b) ((a) > (b) ? (a) : (b))
19 19
20static inline int 20static inline int
21_div_255(int x) { return (x + (x>>8) + 0x80) >> 8; } 21divBy255(int x) { return (x + (x>>8) + 0x80) >> 8; }
22 22
23/* 23/*
24 * This function will clip a rle list with another rle object 24 * This function will clip a rle list with another rle object
@@ -86,7 +86,7 @@ rleIntersectWithRle(SGRleHelper *tmp_clip,
86 out->x = SGMAX(sx1, cx1); 86 out->x = SGMAX(sx1, cx1);
87 out->len = ( SGMIN(sx2, cx2) - out->x); 87 out->len = ( SGMIN(sx2, cx2) - out->x);
88 out->y = spans->y; 88 out->y = spans->y;
89 out->coverage = _div_255(spans->coverage * clipSpans->coverage); 89 out->coverage = divBy255(spans->coverage * clipSpans->coverage);
90 ++out; 90 ++out;
91 --available; 91 --available;
92 } 92 }
@@ -189,7 +189,10 @@ public:
189 void updateBbox(); 189 void updateBbox();
190 bool operator ==(const SGRleImpl &) const; 190 bool operator ==(const SGRleImpl &) const;
191 void intersected(const SGRect &r, SGRleImpl &result); 191 void intersected(const SGRect &r, SGRleImpl &result);
192 void intersected(const SGRleImpl &clip, SGRleImpl &result);
192 friend SGDebug& operator<<(SGDebug& os, const SGRleImpl& object); 193 friend SGDebug& operator<<(SGDebug& os, const SGRleImpl& object);
194 void invert();
195 void alphaMul(int alpha);
193public: 196public:
194 SGRect m_bbox; 197 SGRect m_bbox;
195 std::vector<SGRle::Span> m_spans;// array of Spanlines. 198 std::vector<SGRle::Span> m_spans;// array of Spanlines.
@@ -215,6 +218,22 @@ SGDebug& operator<<(SGDebug& os, const SGRleImpl& o)
215 return os; 218 return os;
216} 219}
217 220
221void SGRleImpl::invert()
222{
223 for (auto &i : m_spans) {
224 i.coverage = 255 - i.coverage;
225 }
226}
227
228void SGRleImpl::alphaMul(int alpha)
229{
230 alpha &= 0xff;
231
232 for (auto &i : m_spans) {
233 i.coverage = divBy255(i.coverage * alpha);
234 }
235}
236
218void SGRleImpl::intersected(const SGRect &r, SGRleImpl &result) 237void SGRleImpl::intersected(const SGRect &r, SGRleImpl &result)
219{ 238{
220 SGRect clip = r.translated(-m_offset.x(), -m_offset.y()); 239 SGRect clip = r.translated(-m_offset.x(), -m_offset.y());
@@ -243,6 +262,36 @@ void SGRleImpl::intersected(const SGRect &r, SGRleImpl &result)
243 result.updateBbox(); 262 result.updateBbox();
244} 263}
245 264
265void SGRleImpl::intersected(const SGRleImpl &clip, SGRleImpl &result)
266{
267 SGRleHelper tresult, tmp_obj, tmp_clip;
268 std::array<SGRle::Span,256> array;
269
270 //setup the tresult object
271 tresult.size = array.size();
272 tresult.alloc = array.size();
273 tresult.spans = array.data();
274
275 // setup tmp object
276 tmp_obj.size = m_spans.size();
277 tmp_obj.spans = m_spans.data();
278
279 //setup tmp clip object
280 tmp_clip.size = clip.m_spans.size();
281 tmp_clip.spans = const_cast<SGRle::Span *>(clip.m_spans.data());
282
283 // run till all the spans are processed
284 while (tmp_obj.size)
285 {
286 rleIntersectWithRle(&tmp_clip, -clip.m_offset.x(), -clip.m_offset.y(), &tmp_obj, &tresult);
287 if (tresult.size) {
288 copyArrayToVector(tresult.spans, tresult.size, result.m_spans);
289 }
290 tresult.size = 0;
291 }
292 result.updateBbox();
293}
294
246 295
247SGRleImpl &SGRleImpl::operator=(const SGRleImpl &other) 296SGRleImpl &SGRleImpl::operator=(const SGRleImpl &other)
248{ 297{
@@ -425,6 +474,29 @@ SGRle SGRle::intersected(const SGRect &r) const
425 return result; 474 return result;
426} 475}
427 476
477SGRle SGRle::intersected(const SGRle &other) const
478{
479 if (isEmpty() || other.isEmpty())
480 return SGRle();
481 // check if the bounding rect are not intersecting
482 SGRle result;
483 result.detach();
484 d->impl.intersected(other.d->impl, result.d->impl);
485 return result;
486}
487
488SGRle SGRle::operator~() const
489{
490 if (isEmpty()) return SGRle();
491
492 SGRle result = *this;
493 result.detach();
494 result.d->impl.invert();
495 return result;
496}
497
498
499
428void SGRle::intersected(const SGRect &r, VRleSpanCb cb, void *userData) 500void SGRle::intersected(const SGRect &r, VRleSpanCb cb, void *userData)
429{ 501{
430 //TODO Implement 502 //TODO Implement
@@ -442,6 +514,17 @@ SGRle &SGRle::intersect(const SGRect &r)
442 return *this = result; 514 return *this = result;
443} 515}
444 516
517SGRle operator*(const SGRle &obj, float alpha)
518{
519 if (obj.isEmpty()) return obj;
520
521 SGRle result = obj;
522 result.detach();
523 result.d->impl.alphaMul(alpha);
524 return result;
525}
526
527
445int SGRle::size() const 528int SGRle::size() const
446{ 529{
447 if (isEmpty()) return 0; 530 if (isEmpty()) return 0;