mOwnData(true),
mRoData(false)
{
+ reset(width, height, format);
+ }
+
+ void reset(uint width, uint height, VBitmap::Format format)
+ {
+ if (mOwnData && mData) delete(mData);
+
mDepth = depth(format);
uint stride = ((width * mDepth + 31) >> 5) << 2; // bytes per scanline (must be multiple of 4)
mStride = stride;
mBytes = mStride * mHeight;
mData = reinterpret_cast<uchar *>(::operator new(mBytes));
-
- if (!mData) {
- // handle malloc failure
- ;
- }
}
Impl(uchar *data, uint w, uint h, uint bytesPerLine, VBitmap::Format format):
mImpl = std::make_shared<Impl>(data, width, height, bytesPerLine, format);
}
+void VBitmap::reset(uint w, uint h, VBitmap::Format format)
+{
+ if (mImpl) {
+ if (w == mImpl->width() &&
+ h == mImpl->height() &&
+ format == mImpl->format()) {
+ return;
+ }
+ mImpl->reset(w, h, format);
+ } else {
+ mImpl = std::make_shared<Impl>(w, h, format);
+ }
+}
+
uint VBitmap::stride() const
{
return mImpl ? mImpl->stride() : 0;
VBitmap(uint w, uint h, VBitmap::Format format);
VBitmap(uchar *data, uint w, uint h, uint bytesPerLine, VBitmap::Format format);
+ void reset(uint w, uint h, VBitmap::Format format=Format::ARGB32_Premultiplied);
uint stride() const;
uint width() const;
uint height() const;