vector: added reset() api to VBitmap
authorsubhransu mohanty <sub.mohanty@samsung.com>
Fri, 27 Sep 2019 06:59:44 +0000 (15:59 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Sun, 29 Sep 2019 21:50:13 +0000 (06:50 +0900)
src/vector/vbitmap.cpp
src/vector/vbitmap.h

index 5a3bdf5..8ee9ae0 100644 (file)
@@ -37,6 +37,18 @@ void VBitmap::Impl::reset(size_t width, size_t height, VBitmap::Format format)
     mOwnData = std::make_unique<uchar[]>(mStride * mHeight);
 }
 
+void VBitmap::Impl::reset(uchar *data, size_t width, size_t height, size_t bytesPerLine,
+                          VBitmap::Format format)
+{
+    mRoData = data;
+    mWidth = uint(width);
+    mHeight = uint(height);
+    mStride = uint(bytesPerLine);
+    mFormat = format;
+    mDepth = depth(format);
+    mOwnData = nullptr;
+}
+
 uchar VBitmap::Impl::depth(VBitmap::Format format)
 {
     uchar depth = 1;
@@ -106,6 +118,16 @@ VBitmap::VBitmap(uchar *data, size_t width, size_t height, size_t bytesPerLine,
     mImpl = rc_ptr<Impl>(data, width, height, bytesPerLine, format);
 }
 
+void VBitmap::reset(uchar *data, size_t w, size_t h, size_t bytesPerLine,
+                    VBitmap::Format format)
+{
+    if (mImpl) {
+        mImpl->reset(data, w, h, bytesPerLine, format);
+    } else {
+        mImpl = rc_ptr<Impl>(data, w, h, bytesPerLine, format);
+    }
+}
+
 void VBitmap::reset(size_t w, size_t h, VBitmap::Format format)
 {
     if (mImpl) {
index fad6583..d460d43 100644 (file)
@@ -36,7 +36,7 @@ public:
     VBitmap() = default;
     VBitmap(size_t w, size_t h, VBitmap::Format format);
     VBitmap(uchar *data, size_t w, size_t h, size_t bytesPerLine, VBitmap::Format format);
-
+    void reset(uchar *data, size_t w, size_t h, size_t stride, VBitmap::Format format);
     void reset(size_t w, size_t h, VBitmap::Format format=Format::ARGB32_Premultiplied);
     size_t          stride() const;
     size_t          width() const;
@@ -65,8 +65,9 @@ private:
             reset(width, height, format);
         }
         explicit Impl(uchar *data, size_t w, size_t h, size_t bytesPerLine, VBitmap::Format format)
-            : mRoData(data), mWidth(uint(w)), mHeight(uint(h)), mStride(uint(bytesPerLine)),
-              mDepth(depth(format)), mFormat(format){}
+        {
+            reset(data, w, h, bytesPerLine, format);
+        }
         VRect   rect() const { return VRect(0, 0, mWidth, mHeight);}
         VSize   size() const { return VSize(mWidth, mHeight); }
         size_t  stride() const { return mStride; }
@@ -74,6 +75,7 @@ private:
         size_t  height() const { return mHeight; }
         uchar * data() { return mRoData ? mRoData : mOwnData.get(); }
         VBitmap::Format format() const { return mFormat; }
+        void reset(uchar *, size_t, size_t, size_t, VBitmap::Format);
         void reset(size_t, size_t, VBitmap::Format);
         static uchar depth(VBitmap::Format format);
         void fill(uint);