lottie/render: added drawBitmap api to painter class. 67/196767/2
authorsubhransu mohanty <sub.mohanty@samsung.com>
Fri, 4 Jan 2019 06:23:56 +0000 (15:23 +0900)
committersubhransu mohanty <sub.mohanty@samsung.com>
Thu, 10 Jan 2019 07:34:10 +0000 (16:34 +0900)
Change-Id: I07fc5f90c9988e02182f69672eeef9608aa51a2a

src/vector/vpainter.cpp
src/vector/vpainter.h

index e8f54b2..39b19f6 100644 (file)
@@ -25,7 +25,8 @@ class VPainterImpl {
 public:
     void drawRle(const VPoint &pos, const VRle &rle);
     void drawRle(const VRle &rle, const VRle &clip);
-
+    void setCompositionMode(VPainter::CompositionMode mode) { mSpanData.mCompositionMode = mode;}
+    void  drawBitmapUntransform(const VRect &target, const VBitmap &bitmap, const VRect &source);
 public:
     VRasterBuffer mBuffer;
     VSpanData     mSpanData;
@@ -55,6 +56,54 @@ void VPainterImpl::drawRle(const VRle &rle, const VRle &clip)
                   &mSpanData);
 }
 
+static void fillRect(const VRect &r, VSpanData *data)
+{
+    int x1, x2, y1, y2;
+
+    x1 = std::max(r.x(), 0);
+    x2 = std::min(r.x() + r.width(), data->mRasterBuffer->width());
+    y1 = std::max(r.y(), 0);
+    y2 = std::min(r.y() + r.height(), data->mRasterBuffer->height());
+
+    if (x2 <= x1 || y2 <= y1)
+        return;
+
+    const int nspans = 256;
+    VRle::Span spans[nspans];
+
+    int y = y1;
+    while (y < y2) {
+        int n = std::min(nspans, y2 - y);
+        int i = 0;
+        while (i < n) {
+            spans[i].x = x1;
+            spans[i].len = x2 - x1;
+            spans[i].y = y + i;
+            spans[i].coverage = 255;
+            ++i;
+        }
+
+        data->mUnclippedBlendFunc(n, spans, data);
+        y += n;
+    }
+}
+
+void  VPainterImpl::drawBitmapUntransform(const VRect &target,
+                                          const VBitmap &bitmap,
+                                          const VRect &source)
+{
+    mSpanData.initTexture(&bitmap, 255, VBitmapData::Plain, source);
+    if (!mSpanData.mUnclippedBlendFunc)
+        return;
+    mSpanData.dx = -target.x();
+    mSpanData.dy = -target.y();
+
+    VRect rr = source.translated(target.x(), target.y());
+
+    fillRect(rr, &mSpanData);
+}
+
+
 
 VPainter::~VPainter()
 {
@@ -86,6 +135,11 @@ void VPainter::setBrush(const VBrush &brush)
     mImpl->mSpanData.setup(brush);
 }
 
+void  VPainter::setCompositionMode(CompositionMode mode)
+{
+    mImpl->setCompositionMode(mode);
+}
+
 void VPainter::drawRle(const VPoint &pos, const VRle &rle)
 {
     mImpl->drawRle(pos, rle);
@@ -102,4 +156,38 @@ VRect VPainter::clipBoundingRect() const
     return mImpl->mSpanData.mSystemClip;
 }
 
+void  VPainter::drawBitmap(const VPoint &point, const VBitmap &bitmap, const VRect &source)
+{
+    if (!bitmap.valid()) return;
+
+    drawBitmap(VRect(point.x(), point.y(), bitmap.width(), bitmap.height()),
+               bitmap, source);
+}
+
+void  VPainter::drawBitmap(const VRect &target, const VBitmap &bitmap, const VRect &source)
+{
+    if (!bitmap.valid()) return;
+
+    if (target.size() == source.size()) {
+        mImpl->drawBitmapUntransform(target, bitmap, source);
+    } else {
+        // @TODO scaling
+    }
+}
+
+void  VPainter::drawBitmap(const VPoint &point, const VBitmap &bitmap)
+{
+    if (!bitmap.valid()) return;
+
+    drawBitmap(VRect(point.x(), point.y(), bitmap.width(), bitmap.height()),
+               bitmap, VRect(0, 0, bitmap.width(), bitmap.height()));
+}
+
+void  VPainter::drawBitmap(const VRect &rect, const VBitmap &bitmap)
+{
+    if (!bitmap.valid()) return;
+
+    drawBitmap(rect, bitmap, VRect(0, 0, bitmap.width(), bitmap.height()));
+}
+
 V_END_NAMESPACE
index d4fbe9f..389c94d 100644 (file)
@@ -29,17 +29,27 @@ class VBitmap;
 class VPainterImpl;
 class VPainter {
 public:
-    enum CompositionMode { CompModeSrc, CompModeSrcOver };
+    enum CompositionMode {
+        CompModeSrc,
+        CompModeSrcOver,
+        CompModeDestIn,
+        CompModeDestOut
+    };
     ~VPainter();
     VPainter();
     VPainter(VBitmap *buffer);
     bool  begin(VBitmap *buffer);
     void  end();
     void  setBrush(const VBrush &brush);
+    void  setCompositionMode(CompositionMode mode);
     void  drawRle(const VPoint &pos, const VRle &rle);
     void  drawRle(const VRle &rle, const VRle &clip);
     VRect clipBoundingRect() const;
 
+    void  drawBitmap(const VPoint &point, const VBitmap &bitmap, const VRect &source);
+    void  drawBitmap(const VRect &target, const VBitmap &bitmap, const VRect &source);
+    void  drawBitmap(const VPoint &point, const VBitmap &bitmap);
+    void  drawBitmap(const VRect &rect, const VBitmap &bitmap);
 private:
     VPainterImpl *mImpl;
 };