From: subhransu mohanty Date: Fri, 12 Jul 2019 01:20:44 +0000 (+0900) Subject: lottie: Refcator internal api and remove warnings. X-Git-Tag: submit/tizen/20190719.015332~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7d7fe6f91b9040eed0568d8280ff0be91b34c503;p=platform%2Fcore%2Fuifw%2Flottie-player.git lottie: Refcator internal api and remove warnings. --- diff --git a/inc/rlottiecommon.h b/inc/rlottiecommon.h index bd905d5..8355de1 100644 --- a/inc/rlottiecommon.h +++ b/inc/rlottiecommon.h @@ -122,7 +122,7 @@ typedef struct LOTMask { size_t elmCount; } mPath; LOTMaskType mMode; - int mAlpha; + unsigned char mAlpha; }LOTMask; typedef enum @@ -154,10 +154,10 @@ typedef struct LOTNode { struct { unsigned char enable; - int width; + float width; LOTCapStyle cap; LOTJoinStyle join; - int meterLimit; + float meterLimit; float *dashArray; int dashArraySize; } mStroke; @@ -217,7 +217,7 @@ typedef struct LOTLayerNode { LOTMatteType mMatte; int mVisible; - int mAlpha; + unsigned char mAlpha; const char *name; } LOTLayerNode; diff --git a/src/lottie/lottieitem.cpp b/src/lottie/lottieitem.cpp index a522566..163dd2e 100644 --- a/src/lottie/lottieitem.cpp +++ b/src/lottie/lottieitem.cpp @@ -206,7 +206,7 @@ VRle LOTMaskItem::rle() if (mRasterRequest) { mRasterRequest = false; if (!vCompare(mCombinedAlpha, 1.0f)) - mRasterizer.rle() *= (mCombinedAlpha * 255); + mRasterizer.rle() *= uchar(mCombinedAlpha * 255); if (mData->mInv) mRasterizer.rle().invert(); } return mRasterizer.rle(); @@ -231,7 +231,7 @@ void LOTLayerItem::buildLayerNode() mLayerCNode->mClipPath.elmCount = 0; mLayerCNode->name = name().c_str(); } - if (complexContent()) mLayerCNode->mAlpha = combinedAlpha() * 255.f; + if (complexContent()) mLayerCNode->mAlpha = uchar(combinedAlpha() * 255.f); mLayerCNode->mVisible = visible(); // update matte if (hasMatte()) { @@ -261,13 +261,13 @@ void LOTLayerItem::buildLayerNode() LOTMask * cNode = &mMasksCNode[i++]; const std::vector &elm = mask.mFinalPath.elements(); const std::vector & pts = mask.mFinalPath.points(); - const float *ptPtr = reinterpret_cast(pts.data()); - const char * elmPtr = reinterpret_cast(elm.data()); + auto ptPtr = reinterpret_cast(pts.data()); + auto elmPtr = reinterpret_cast(elm.data()); cNode->mPath.ptPtr = ptPtr; cNode->mPath.ptCount = pts.size(); cNode->mPath.elmPtr = elmPtr; cNode->mPath.elmCount = elm.size(); - cNode->mAlpha = mask.mCombinedAlpha * 255.0f; + cNode->mAlpha = uchar(mask.mCombinedAlpha * 255.0f); switch (mask.maskMode()) { case LOTMaskData::Mode::Add: cNode->mMode = MaskAdd; @@ -501,11 +501,8 @@ VMatrix LOTLayerItem::matrix(int frameNo) const bool LOTLayerItem::visible() const { - if (frameNo() >= mLayerData->inFrame() && - frameNo() < mLayerData->outFrame()) - return true; - else - return false; + return (frameNo() >= mLayerData->inFrame() && + frameNo() < mLayerData->outFrame()); } LOTCompLayerItem::LOTCompLayerItem(LOTLayerData *layerModel) @@ -513,9 +510,9 @@ LOTCompLayerItem::LOTCompLayerItem(LOTLayerData *layerModel) { // 1. create layer item for (auto &i : mLayerData->mChildren) { - LOTLayerData *layerModel = static_cast(i.get()); - auto layerItem = LOTCompItem::createLayerItem(layerModel); - if (layerItem) mLayers.push_back(std::move(layerItem)); + auto model = static_cast(i.get()); + auto item = LOTCompItem::createLayerItem(model); + if (item) mLayers.push_back(std::move(item)); } // 2. update parent layer @@ -547,8 +544,8 @@ void LOTCompLayerItem::buildLayerNode() if (mClipper) { const std::vector &elm = mClipper->mPath.elements(); const std::vector & pts = mClipper->mPath.points(); - const float *ptPtr = reinterpret_cast(pts.data()); - const char * elmPtr = reinterpret_cast(elm.data()); + auto ptPtr = reinterpret_cast(pts.data()); + auto elmPtr = reinterpret_cast(elm.data()); layerNode()->mClipPath.ptPtr = ptPtr; layerNode()->mClipPath.elmPtr = elmPtr; layerNode()->mClipPath.ptCount = 2 * pts.size(); @@ -584,7 +581,7 @@ void LOTCompLayerItem::render(VPainter *painter, const VRle &inheritMask, srcPainter.begin(&srcBitmap); renderHelper(&srcPainter, inheritMask, matteRle); srcPainter.end(); - painter->drawBitmap(VPoint(), srcBitmap, combinedAlpha() * 255.0f); + painter->drawBitmap(VPoint(), srcBitmap, uchar(combinedAlpha() * 255.0f)); } else { renderHelper(painter, inheritMask, matteRle); } @@ -767,7 +764,7 @@ void LOTSolidLayerItem::buildLayerNode() mCNodeList.clear(); for (auto &i : mDrawableList) { - LOTDrawable *lotDrawable = static_cast(i); + auto lotDrawable = static_cast(i); lotDrawable->sync(); mCNodeList.push_back(lotDrawable->mCNode.get()); } @@ -826,15 +823,15 @@ void LOTImageLayerItem::buildLayerNode() mCNodeList.clear(); for (auto &i : mDrawableList) { - LOTDrawable *lotDrawable = static_cast(i); + auto lotDrawable = static_cast(i); lotDrawable->sync(); lotDrawable->mCNode->mImageInfo.data = lotDrawable->mBrush.mTexture.data(); lotDrawable->mCNode->mImageInfo.width = - lotDrawable->mBrush.mTexture.width(); + int(lotDrawable->mBrush.mTexture.width()); lotDrawable->mCNode->mImageInfo.height = - lotDrawable->mBrush.mTexture.height(); + int(lotDrawable->mBrush.mTexture.height()); lotDrawable->mCNode->mImageInfo.mMatrix.m11 = combinedMatrix().m_11(); lotDrawable->mCNode->mImageInfo.mMatrix.m12 = combinedMatrix().m_12(); @@ -947,7 +944,7 @@ void LOTShapeLayerItem::buildLayerNode() mCNodeList.clear(); for (auto &i : mDrawableList) { - LOTDrawable *lotDrawable = static_cast(i); + auto lotDrawable = static_cast(i); lotDrawable->sync(); mCNodeList.push_back(lotDrawable->mCNode.get()); } @@ -1613,7 +1610,7 @@ static void updateGStops(LOTNode *n, const VGradient *grad) LOTGradientStop *ptr = n->mGradient.stopPtr; for (const auto &i : grad->mStops) { ptr->pos = i.first; - ptr->a = i.second.alpha() * grad->alpha(); + ptr->a = uchar(i.second.alpha() * grad->alpha()); ptr->r = i.second.red(); ptr->g = i.second.green(); ptr->b = i.second.blue(); diff --git a/src/lottie/lottiemodel.cpp b/src/lottie/lottiemodel.cpp index 759f396..87c27e2 100644 --- a/src/lottie/lottiemodel.cpp +++ b/src/lottie/lottiemodel.cpp @@ -198,16 +198,16 @@ int LOTGStrokeData::getDashInfo(int frameNo, float *array) const void LOTGradient::populate(VGradientStops &stops, int frameNo) { LottieGradient gradData = mGradient.value(frameNo); - int size = int(gradData.mGradient.size()); + auto size = gradData.mGradient.size(); float * ptr = gradData.mGradient.data(); int colorPoints = mColorPoints; if (colorPoints == -1) { // for legacy bodymovin (ref: lottie-android) - colorPoints = size / 4; + colorPoints = int(size / 4); } - int opacityArraySize = size - colorPoints * 4; + auto opacityArraySize = size - colorPoints * 4; float *opacityPtr = ptr + (colorPoints * 4); stops.clear(); - int j = 0; + size_t j = 0; for (int i = 0; i < colorPoints; i++) { float colorStop = ptr[0]; LottieColor color = LottieColor(ptr[1], ptr[2], ptr[3]); diff --git a/src/vector/vbitmap.cpp b/src/vector/vbitmap.cpp index db5506b..a1cd662 100644 --- a/src/vector/vbitmap.cpp +++ b/src/vector/vbitmap.cpp @@ -28,8 +28,7 @@ struct VBitmap::Impl { uint mWidth{0}; uint mHeight{0}; uint mStride{0}; - uint mBytes{0}; - uint mDepth{0}; + uchar mDepth{0}; VBitmap::Format mFormat{VBitmap::Format::Invalid}; bool mOwnData; bool mRoData; @@ -40,49 +39,54 @@ struct VBitmap::Impl { Impl& operator=(Impl&&) = delete; Impl& operator=(Impl&) = delete; - explicit Impl(uint width, uint height, VBitmap::Format format) + VRect rect() const + { + return VRect(0, 0, mWidth, mHeight); + } + + VSize size() const + { + return VSize(mWidth, mHeight); + } + + explicit Impl(size_t width, size_t height, VBitmap::Format format) : mOwnData(true), mRoData(false) { reset(width, height, format); } - void reset(uint width, uint height, VBitmap::Format format) + void reset(size_t width, size_t height, VBitmap::Format format) { - if (mOwnData && mData) delete (mData); + if (mOwnData && mData) delete[] mData; + + mWidth = uint(width); + mHeight = uint(height); + mFormat = format; mDepth = depth(format); - uint stride = ((width * mDepth + 31) >> 5) + mStride = ((mWidth * mDepth + 31) >> 5) << 2; // bytes per scanline (must be multiple of 4) - - mWidth = width; - mHeight = height; - mFormat = format; - mStride = stride; - mBytes = mStride * mHeight; - mData = new uchar[mBytes]; + mData = new uchar[mStride * mHeight]; } - explicit Impl(uchar *data, uint w, uint h, uint bytesPerLine, VBitmap::Format format) - : mData(data), mWidth(w), mHeight(h), mStride(bytesPerLine), - mDepth(depth(format)), mFormat(format), mOwnData(false), mRoData(false) - { - mBytes = mStride * mHeight; - } + explicit Impl(uchar *data, size_t w, size_t h, size_t bytesPerLine, VBitmap::Format format) + : mData(data), mWidth(uint(w)), mHeight(uint(h)), mStride(uint(bytesPerLine)), + mDepth(depth(format)), mFormat(format), mOwnData(false), mRoData(false){} ~Impl() { if (mOwnData && mData) delete[] mData; } - uint stride() const { return mStride; } - uint width() const { return mWidth; } - uint height() const { return mHeight; } + size_t stride() const { return mStride; } + size_t width() const { return mWidth; } + size_t height() const { return mHeight; } VBitmap::Format format() const { return mFormat; } uchar * data() { return mData; } - static uint depth(VBitmap::Format format) + static uchar depth(VBitmap::Format format) { - uint depth = 1; + uchar depth = 1; switch (format) { case VBitmap::Format::Alpha8: depth = 8; @@ -132,14 +136,14 @@ struct VBitmap::Impl { } }; -VBitmap::VBitmap(uint width, uint height, VBitmap::Format format) +VBitmap::VBitmap(size_t width, size_t height, VBitmap::Format format) { if (width <= 0 || height <= 0 || format == Format::Invalid) return; mImpl = std::make_shared(width, height, format); } -VBitmap::VBitmap(uchar *data, uint width, uint height, uint bytesPerLine, +VBitmap::VBitmap(uchar *data, size_t width, size_t height, size_t bytesPerLine, VBitmap::Format format) { if (!data || width <= 0 || height <= 0 || bytesPerLine <= 0 || @@ -149,7 +153,7 @@ VBitmap::VBitmap(uchar *data, uint width, uint height, uint bytesPerLine, mImpl = std::make_shared(data, width, height, bytesPerLine, format); } -void VBitmap::reset(uint w, uint h, VBitmap::Format format) +void VBitmap::reset(size_t w, size_t h, VBitmap::Format format) { if (mImpl) { if (w == mImpl->width() && h == mImpl->height() && @@ -162,22 +166,22 @@ void VBitmap::reset(uint w, uint h, VBitmap::Format format) } } -uint VBitmap::stride() const +size_t VBitmap::stride() const { return mImpl ? mImpl->stride() : 0; } -uint VBitmap::width() const +size_t VBitmap::width() const { return mImpl ? mImpl->width() : 0; } -uint VBitmap::height() const +size_t VBitmap::height() const { return mImpl ? mImpl->height() : 0; } -uint VBitmap::depth() const +size_t VBitmap::depth() const { return mImpl ? mImpl->mDepth : 0; } @@ -192,6 +196,16 @@ uchar *VBitmap::data() const return mImpl ? mImpl->data() : nullptr; } +VRect VBitmap::rect() const +{ + return mImpl ? mImpl->rect() : VRect(); +} + +VSize VBitmap::size() const +{ + return mImpl ? mImpl->size() : VSize(); +} + bool VBitmap::valid() const { return (mImpl != nullptr); diff --git a/src/vector/vbitmap.h b/src/vector/vbitmap.h index a21c680..4de0dcd 100644 --- a/src/vector/vbitmap.h +++ b/src/vector/vbitmap.h @@ -34,19 +34,20 @@ public: }; VBitmap() = default; - 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; - uint depth() const; + 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(size_t w, size_t h, VBitmap::Format format=Format::ARGB32_Premultiplied); + size_t stride() const; + size_t width() const; + size_t height() const; + size_t depth() const; VBitmap::Format format() const; bool valid() const; uchar * data(); uchar * data() const; - + VRect rect() const; + VSize size() const; void fill(uint pixel); void updateLuma(); private: diff --git a/src/vector/vcompositionfunctions.cpp b/src/vector/vcompositionfunctions.cpp index 52ac0db..78fe921 100644 --- a/src/vector/vcompositionfunctions.cpp +++ b/src/vector/vcompositionfunctions.cpp @@ -124,7 +124,7 @@ void comp_func_SourceOver(uint32_t *dest, const uint32_t *src, int length, * dest = source' + dest ( 1- source'a) */ for (int i = 0; i < length; ++i) { - uint s = BYTE_MUL(src[i], const_alpha); + s = BYTE_MUL(src[i], const_alpha); sia = vAlpha(~s); dest[i] = s + BYTE_MUL(dest[i], sia); } diff --git a/src/vector/vdrawhelper.cpp b/src/vector/vdrawhelper.cpp index e137a35..9db17b2 100644 --- a/src/vector/vdrawhelper.cpp +++ b/src/vector/vdrawhelper.cpp @@ -76,7 +76,7 @@ public: VCacheData info; const VGradientStops &stops = gradient.mStops; for (uint i = 0; i < stops.size() && i <= 2; i++) - hash_val += (stops[i].second.premulARGB() * gradient.alpha()); + hash_val += VCacheKey(stops[i].second.premulARGB() * gradient.alpha()); { std::lock_guard guard(mMutex); @@ -209,7 +209,7 @@ VBitmap::Format VRasterBuffer::prepare(VBitmap *image) void VSpanData::init(VRasterBuffer *image) { mRasterBuffer = image; - setDrawRegion(VRect(0, 0, image->width(), image->height())); + setDrawRegion(VRect(0, 0, int(image->width()), int(image->height()))); mType = VSpanData::Type::None; mBlendFunc = nullptr; mUnclippedBlendFunc = nullptr; @@ -349,9 +349,9 @@ void fetch_linear_gradient(uint32_t *buffer, const Operator *op, float rw = data->m23 * (y + float(0.5)) + data->m13 * (x + float(0.5)) + data->m33; while (buffer < end) { - float x = rx / rw; - float y = ry / rw; - t = (op->linear.dx * x + op->linear.dy * y) + op->linear.off; + float xt = rx / rw; + float yt = ry / rw; + t = (op->linear.dx * xt + op->linear.dy * yt) + op->linear.off; *buffer = gradientPixel(gradient, t); rx += data->m11; @@ -717,8 +717,8 @@ static void blend_untransformed_argb(size_t count, const VRle::Span *spans, const int image_width = data->mBitmap.width; const int image_height = data->mBitmap.height; - int xoff = data->dx; - int yoff = data->dy; + int xoff = int(data->dx); + int yoff = int(data->dy); while (count--) { int x = spans->x; @@ -789,7 +789,7 @@ void VSpanData::setup(const VBrush &brush, VPainter::CompositionMode /*mode*/, mType = VSpanData::Type::Texture; initTexture( &brush.mTexture, 255, VBitmapData::Plain, - VRect(0, 0, brush.mTexture.width(), brush.mTexture.height())); + brush.mTexture.rect()); setupMatrix(brush.mMatrix); break; } @@ -826,8 +826,8 @@ void VSpanData::initTexture(const VBitmap *bitmap, int alpha, mType = VSpanData::Type::Texture; mBitmap.imageData = bitmap->data(); - mBitmap.width = bitmap->width(); - mBitmap.height = bitmap->height(); + mBitmap.width = int(bitmap->width()); + mBitmap.height = int(bitmap->height()); mBitmap.bytesPerLine = bitmap->stride(); mBitmap.format = bitmap->format(); mBitmap.x1 = sourceRect.x(); diff --git a/src/vector/vdrawhelper.h b/src/vector/vdrawhelper.h index 9c1b567..5c9a6db 100644 --- a/src/vector/vdrawhelper.h +++ b/src/vector/vdrawhelper.h @@ -83,22 +83,22 @@ public: inline uchar *scanLine(int y) { assert(y >= 0); - assert(y < mHeight); + assert(size_t(y) < mHeight); return mBuffer + y * mBytesPerLine; } - int width() const { return mWidth; } - int height() const { return mHeight; } - int bytesPerLine() const { return mBytesPerLine; } - int bytesPerPixel() const { return mBytesPerPixel; } + size_t width() const { return mWidth; } + size_t height() const { return mHeight; } + size_t bytesPerLine() const { return mBytesPerLine; } + size_t bytesPerPixel() const { return mBytesPerPixel; } VBitmap::Format mFormat{VBitmap::Format::ARGB32_Premultiplied}; private: - int mWidth{0}; - int mHeight{0}; - int mBytesPerLine{0}; - int mBytesPerPixel{0}; - uchar *mBuffer{nullptr}; + size_t mWidth{0}; + size_t mHeight{0}; + size_t mBytesPerLine{0}; + size_t mBytesPerPixel{0}; + uchar *mBuffer{nullptr}; }; struct VGradientData { diff --git a/src/vector/vimageloader.cpp b/src/vector/vimageloader.cpp index a75ca86..03c269a 100644 --- a/src/vector/vimageloader.cpp +++ b/src/vector/vimageloader.cpp @@ -224,5 +224,5 @@ VBitmap VImageLoader::load(const char *fileName) VBitmap VImageLoader::load(const char *data, size_t len) { - return mImpl->load(data, len); + return mImpl->load(data, int(len)); } diff --git a/src/vector/vpainter.cpp b/src/vector/vpainter.cpp index cdcaa11..af0da6e 100644 --- a/src/vector/vpainter.cpp +++ b/src/vector/vpainter.cpp @@ -61,12 +61,10 @@ void VPainterImpl::drawRle(const VRle &rle, const VRle &clip) 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->mDrawableSize.width()); - y1 = std::max(r.y(), 0); - y2 = std::min(r.y() + r.height(), data->mDrawableSize.height()); + auto x1 = std::max(r.x(), 0); + auto x2 = std::min(r.x() + r.width(), data->mDrawableSize.width()); + auto y1 = std::max(r.y(), 0); + auto y2 = std::min(r.y() + r.height(), data->mDrawableSize.height()); if (x2 <= x1 || y2 <= y1) return; @@ -78,9 +76,9 @@ static void fillRect(const VRect &r, VSpanData *data) 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].x = short(x1); + spans[i].len = ushort(x2 - x1); + spans[i].y = short(y + i); spans[i].coverage = 255; ++i; } @@ -97,8 +95,8 @@ void VPainterImpl::drawBitmapUntransform(const VRect & target, { mSpanData.initTexture(&bitmap, const_alpha, VBitmapData::Plain, source); if (!mSpanData.mUnclippedBlendFunc) return; - mSpanData.dx = -target.x(); - mSpanData.dy = -target.y(); + mSpanData.dx = float(-target.x()); + mSpanData.dy = float(-target.y()); VRect rr = source.translated(target.x(), target.y()); @@ -165,7 +163,7 @@ void VPainter::drawBitmap(const VPoint &point, const VBitmap &bitmap, { if (!bitmap.valid()) return; - drawBitmap(VRect(point.x(), point.y(), bitmap.width(), bitmap.height()), + drawBitmap(VRect(point, bitmap.size()), bitmap, source, const_alpha); } @@ -189,8 +187,8 @@ 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()), + drawBitmap(VRect(point, bitmap.size()), + bitmap, bitmap.rect(), const_alpha); } @@ -199,7 +197,7 @@ void VPainter::drawBitmap(const VRect &rect, const VBitmap &bitmap, { if (!bitmap.valid()) return; - drawBitmap(rect, bitmap, VRect(0, 0, bitmap.width(), bitmap.height()), + drawBitmap(rect, bitmap, bitmap.rect(), const_alpha); } diff --git a/src/vector/vrect.h b/src/vector/vrect.h index 9638859..c1401cd 100644 --- a/src/vector/vrect.h +++ b/src/vector/vrect.h @@ -28,6 +28,7 @@ class VRect { public: VRect() = default; VRect(int x, int y, int w, int h):x1(x),y1(y),x2(x+w),y2(y+h){} + explicit VRect(VPoint pt, VSize sz):VRect(pt.x(), pt.y(), sz.width(), sz.height()){} explicit VRect(const VRectF &r); V_CONSTEXPR bool empty() const {return x1 >= x2 || y1 >= y2;} V_CONSTEXPR int left() const {return x1;} @@ -115,9 +116,13 @@ inline bool VRect::contains(const VRect &r, bool proper) const class VRectF { public: VRectF() = default; - VRectF(float x, float y, float w, float h):x1(x),y1(y),x2(x+w),y2(y+h){} - explicit VRectF(const VRect &r):x1(float(r.left())),y1(float(r.top())), - x2(float(r.right())),y2(float(r.bottom())){} + + explicit VRectF(float x, float y, float w, float h):x1(x),y1(y),x2(x+w),y2(y+h){} + + explicit VRectF(int x, int y, int w, int h):x1(float(x)),y1(float(y)), + x2(float(x+w)),y2(float(y+h)){} + + explicit VRectF(const VRect &r):VRectF(r.x(), r.y(), r.width(), r.height()){} V_CONSTEXPR bool empty() const {return x1 >= x2 || y1 >= y2;} V_CONSTEXPR float left() const {return x1;}